Yes, you run the Python code from the Raspberry Pi.
Here is the code, modified to remove the SQL parts and to fetch the distance from the first anchor
#DWM Serial Parser by Brian H. | Updated 3/6/19
import serial
import time
import datetime
DWM=serial.Serial(port="/dev/ttyACM0", baudrate=115200)
print("Connected to " +DWM.name)
DWM.write("\r\r".encode())
time.sleep(1)
DWM.write("lec\r".encode())
time.sleep(1)
while True:
try:
line=DWM.readline()
if(line):
if len(line)>=80:
parse=line.decode().split(",")
pos_AN0=(parse[parse.index("AN0")+2],parse[parse.index("AN0")+3],parse[parse.index("AN0")+4])
dist_AN0=parse[parse.index("AN0")+5]
print(datetime.datetime.now().strftime("%H:%M:%S"),pos_AN0,":",dist_AN0)
else:
print("Distance not calculated: ",line.decode())
except Exception as ex:
print(ex)
break
DWM.write("\r".encode())
DWM.close()
hello @brianh
I did the same,I powered my raspi,connected a tag to raspi with usb,but no power coming to tag(DWM1001)device,it’s led not blinking no power it it, Am I missing something.
sorry,if I am annoying you, please let me know where I a wrong.
Also If I am connecting DWM1001 with header pins and running the above code I am getting following output:
Traceback (most recent call last):
File “/home/pi/DWM.py”, line 7, in
DWM=serial.Serial(port="/dev/ttyACM0", baudrate=115200)
File “/usr/lib/python2.7/dist-packages/serial/serialutil.py”, line 236, in init
self.open()
File “/usr/lib/python2.7/dist-packages/serial/serialposix.py”, line 268, in open
raise SerialException(msg.errno, “could not open port {}: {}”.format(self._port, msg))
SerialException: [Errno 2] could not open port /dev/ttyACM0: [Errno 2] No such file or directory: ‘/dev/ttyACM0’
hey @brianh
I changed to Python 3,but the output is as same.Does it depend on the version installed on my laptop(python2.7 is installed on my laptop) .
I don’t know what to do,help me.
Also, you are missing the “pos_AN0=…” line from my code above. Not sure if you meant to do that but it will cause an error in the print statement later on.
#DWM Serial Parser by Brian H. | Updated 3/6/19
import serial
import time
import datetime
DWM=serial.Serial(port="/dev/serial0", baudrate=115200)
print("Connected to " +DWM.name)
DWM.write("\r\r".encode())
time.sleep(1)
DWM.write("lec\r".encode())
time.sleep(1)
while True:
try:
line=DWM.readline()
if(line):
parse=line.decode().split(",")
if parse[0]=="DIST":
pos_AN0=(parse[parse.index("AN0")+2],parse[parse.index("AN0")+3],parse[parse.index("AN0")+4])
dist_AN0=parse[parse.index("AN0")+5]
print(datetime.datetime.now().strftime("%H:%M:%S"),pos_AN0,":",dist_AN0)
else:
print("Distance not calculated: ",line.decode())
except Exception as ex:
print(ex)
break
DWM.write("\r".encode())
DWM.close()
@brianh
thanks a lot, I don’t know how to thank you, you are a hero.
One thing more I want to ask you can we modify dist_AN0 with some algoritm(least sq) to get position with that(tel me if I am wrong)?
Also can you share me the document where you have code the above program,I too want to discover more,it is not given on DECAWAVE.
I can’t comment on the least squares method, I only used the position already calculated by the RTLS. (Why don’t you use this since it’s already available?) I am sure it is possible though, just do more research. Here is an article about trilateration in Python that you can get started with: https://www.alanzucconi.com/2017/03/13/positioning-and-trilateration/
The method I showed you uses the UART (serial) interface.
@jackman That is a fairly involved project and I don’t think this forum is the appropriate place to ask for help with that. I would recommend checking out the Raspberry Pi Forums.