Getting Distance From Raspberry Pi

Hello Everyone,
I am starting a project using DWM1001 and Raspberry Pi 3 Model B.For that I need to calculate the distance between Tag and Anchors(four). I don’t know where to start, I only need distance so that I can use my own algorithm (Least Sq) to calculate Position. Help me, from where I can write Code to get distance only on my PC using the connection from Raspberry.
Any Help is deeply accepted.

Hi Prashant,

try to look for some info first on this forum. There are a couple of posts related to this topic, e.g.:


1 Like

The lec command detailed in the API Guide returns distances from each anchor.

You can modify my Python script linked by @leapslabs above to fetch distance from each anchor instead of calculated position of the tag easily.

The (x,y,z) coordinates of the anchor can be obtained by:


The distance from that anchor will be:


Where AN0, AN1, AN2, AN3 are the four ranging anchors

1 Like

Any clue where ‘lec’ command is described in what manual?
It looks like every anchor has 5 numbers after it…
and the 1st one is Device ID then 3 distances - one along each axes… and what’s the number after that?
like 6.44 and 6.50 in the 2nd anchor?
EDIT: guessing - is it a LOS (3D) distance to Tag?

@securigy2 It is in the API guide. All documentation for the DWM1001 is located here:

You are correct for the first 4 numbers. The fifth number for each anchor is measured distance to the tag.

The les command is more clear to read but difficult to parse since it is not comma separated, but has the same info.

hi there,
if you can write a “hello world”- program in C, it’s quite easy to follow the instructions for a c-api, and put the 4 distances in the IoT-message of each tag. then you have the information anywhere in the network using the mqtt-broker-function of the raspi.
or you flash the precompiled “dwm-range-iot”- example (the sourcecode is buggy) to your devices, send them “0x0f” as an iot-message, and get 1000(0) distances back.

With regards to ‘les’ command - from API Guide (page 99)

1151[5.00,8.00,2.25]=6.48 0CA8[0.00,8.00,2.25]=6.51 111C[5.00,0.00,2.25]=3.18 1150[0.00,0.00,2.25]=3.16 le_us=2576 est[2.57,1.98,1.68,100]

What is le_us-2576 and what is ‘est’? Is the latter Tag ID?

Hi securigy,

le_us corresponds to the location engine runtime to calculate the position. So i nthat case it took 2576 us to calculate the position.

est[2.57,1.98,1.68,100] is the position estimate of the tag. 100 is the quality factor, so in your situation the location engine assess the estimate quality as very high. (Probably perfect line of sight and very good anchors coordinates)

To get the tag ID you can use the “si” command.


@leapslabs @Yves_Bernard @horst
Can I use raspberry pi 3 model B+ instead for raspberry pi model B,as I bought the former one.
I need distance from tags on my laptop.

Hi Jack, yes you can use raspberry pi 3 B+. I using it with PANS R2 and It works.

Please note that using the raspberry pi 3b+ is not recommend as there may be issues when the ethernet is used. The recommended host is the raspberry pi 3b (in this case, ethernet can be used safely)


what is PAN R2?
please explain

It is the updated firmware. See this post for more info:

hey brianh,
I have set up DWM1001, I updated it with lastest PANS R2.
Also, I am able to access the UART shell and able to perform some command like si,utpg.
It is giving correct output(as described in Gateway Quick Dec pdf). But I am not able to get the output of commands like les,lec,lep.
I have connected DWM1001 with USB, and I have powered 1 anchor also, It should give a distance, but I don’t know why it is not showing anything,
Please help me what I am missing.
My overall task is to get distance from all anchors and a tag, using raspberry pi,I also want to know how to connect raspberry pi to PC(I am not familiar with it), how to download host_api file onto it, and finally where to write above code(u gave), and how to execute it.

Thanks a lot in advance, Please guide me.

Hi jackman,

Have you initialized the anchor already? I believe the anchor has to be initialized with a position and added to a network along with the tag for them to communicate with each other. This is easily done in the DRTLS Manager Android app.

The Python code here can be run on the Raspberry Pi or your PC with the tag connected through USB like you are doing. Just save to a file and run with python3

You can see this documentation on how to use serial with Python:

1 Like

hey Brianh,
As directed by you to initialize the anchors, I tried them by powering all anchors and a tag, and starting DRTLS app. But the thing that shocks me is, the anchor and tag are not showing on the app. But I have done RTLS before using the same anchors and tag,before connecting to RAS pi and PC.I don’t what’s wrong with them(have they gone to sleep mode).
Till now I have done the following things:
1-I updated each anchor with latest PANS R2.
2-I configured each anchor , initiator and tag (as desired in quick dev document) using commands like nis,nmi,nma.
3-I am able to access UART shell ,but les lec not working.
4-Now, anchors and tag not showing up in the android app.

Also I want to know how and where to download host_api package on raspberry pi(i am not much familiar with pi)

Another doubt of mine is I can’t access sudo privileges on my windows PC. Have you any idea how to start using sudo commands.

Thanks a lot in advance,please help me.

Hello Brianh,
@brianh @Yves_Bernard @horst @leapslabs
Reflashing the PANS R2 fixed that problem, now I am able to get rum les command on DWM1001 connected to PC using PC.
Now,I want to get distance data using Raspberry Pi, can anyone help me in this,I know thta Raspberry Pi can be connected to DWM1001 through header pins.I want to know the further steps.raspberry pi is connected to PC through Ethernet.The code provided above seems good,but I dont know where to run it.How will I get distance from all anchor.

I want that DWM1001 connected to raspi should act as listener mode.

Anyone ,please get me to the result.

hello @ibrahim
have you worked on a similar project (getting distance from all anchors using raspberry pi),if yes,please guide me how you proceeded

Hi Jackman,

Glad to hear you got the les command working. If it is already working on your PC it is simple to get the info on the Pi. I used Python3 with pySerial. If you are not familiar with Python you can do a quick “Hello World” tutorial to get the hang of it.

You just have to save my code as and run from the terminal using command


I use the lec command rather than les since it is easier to parse comma separated values, they contain the same info.

As I mentioned before, since you don’t need the SQL part, just delete all lines containing mysql, mydb, sql, val, or mycursor.

Here is the pySerial documentation for reference:

hello @brianh brianh,
Thanks for sharing.
how should I connect Raspi wih DWM1001 ,with header pins or with USB.
And should the python coding to be done on raspi window(tell me if I am wrong).
Can you share me the complete code,it will be better for a noob like me.
Thanks a lot again