# Echo sounder Python code for rasberry 3

**URL:** <https://discuss.bluerobotics.com/t/echo-sounder-python-code-for-rasberry-3/10201>\
**Category:** Ping Sonar Devices\
**Tags:** ping, sonar\
**Created:** [July 18, 2021, 4:24am UTC](https://discuss.bluerobotics.com/t/echo-sounder-python-code-for-rasberry-3/10201 "2021-07-18T04:24:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MuhammedBeken](https://avatars.discourse-cdn.com/v4/letter/m/a6a055/32.png) [@MuhammedBeken](https://discuss.bluerobotics.com/u/MuhammedBeken)\
**Post date:** [July 18, 2021, 4:24am UTC](https://discuss.bluerobotics.com/t/echo-sounder-python-code-for-rasberry-3/10201/1 "2021-07-18T04:24:08Z")

</div>

I am trying to obtain the echo sounder distance mesurement in python using a rasbery pi connected through ssh to windows 10 , I have followed the github installation guidance . I have also used pip3 to download the package but when I try to execute the program using the following command ( simplePingExample.py --device/dev/ttyUSB0 ) ( I have tried from ttyUSB0 to ttyUSB4)but I keep on getting the following error

Traceback (most recent call last):  
File “/home/pi/.local/bin/simplePingExample.py”, line 4, in   
**import** (‘pkg\_resources’).run\_script(‘bluerobotics-ping==0.1.0’, ‘simplePingExample.py’)  
File “/usr/lib/python3/dist-packages/pkg\_resources/ **init**.py”, line 666, in run\_script  
self.require(requires)[0].run\_script(script\_name, ns)  
File “/usr/lib/python3/dist-packages/pkg\_resources/ **init**.py”, line 1437, in run\_script  
.format(\*\*locals()),  
pkg\_resources.ResolutionError: Script ‘scripts/simplePingExample.py’ not found in metadata at '/home/pi/.l

Could you please guide me through What I am doing wrong ? , I have tried connecting to the echosounder using an arduino , and everything seemed to run smoothly , which is not the case in python

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [July 18, 2021, 11:35pm UTC](https://discuss.bluerobotics.com/t/echo-sounder-python-code-for-rasberry-3/10201/2 "2021-07-18T23:35:04Z")

</div>

Hi @MuhammedBeken,

The end of your error traceback seems to be missing, so it’s not clear what’s actually going wrong.

I just tried this using the Raspberry Pi 3 companion computer in the ROV and it worked for me 🙂

```auto
ssh pi@raspberrypi.local
pi@raspberrypi.local's password:

# install bluerobotics-ping library and dependencies for python 3
pi@raspberrypi:~ $ sudo pip3 install bluerobotics-ping
# stop the companion 'pingproxy' service to allow script connection instead
pi@raspberrypi:~ $ screen -S pingproxy -X quit
# run the simple Ping example on the first Ping1D device detected by companion
pi@raspberrypi:~ $ simplePingExample.py --device $(ls -d /dev/serial/ping/Ping1* | head -1)

```

For just the commands I ran once ssh’d in:

```nohighlight
# install bluerobotics-ping library and dependencies for python 3
sudo pip3 install bluerobotics-ping
# stop the companion 'pingproxy' service to allow script connection instead
screen -S pingproxy -X quit
# run the simple Ping example on the first Ping1D device detected by companion
simplePingExample.py --device $(ls -d /dev/serial/ping/Ping1* | head -1)

```

Note that if you’re not using our companion image you won’t need to quit the ‘pingproxy’ service, but you will need to manually specify the usb port, e.g.

```nohighlight
# install bluerobotics-ping library and dependencies for python3
sudo pip3 install bluerobotics-ping
# run the simple Ping example on USB0 (may need to change device)
simplePingExample.py --device /dev/ttyUSB0

```

---

<div class="post-metadata">

**Author:** ![MokhtarYahia](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/mokhtaryahia/32/8601_2.png) [@MokhtarYahia](https://discuss.bluerobotics.com/u/MokhtarYahia)\
**Post date:** [July 23, 2021, 2:32pm UTC](https://discuss.bluerobotics.com/t/echo-sounder-python-code-for-rasberry-3/10201/3 "2021-07-23T14:32:05Z")

</div>

Thank you Eliot for the reply , but sadly when I tried to run the command that you have shared with me

**_simplePingExample.py --device $(ls -d /dev/serial/ping/Ping1_ | head -1)**

it seemed that there was no “/ping” folder under /serial ( you can check the screenshot )

And when I try to run directly the **simplePingExample.py --device /dev/ttyUSB0** of course trying diffrent USB numbers 0-4 , I get the same error previously

simplePingExample.py --device /dev/ttyUSB0  
Traceback (most recent call last):  
File “/home/pi/.local/bin/simplePingExample.py”, line 4, in   
**import** (‘pkg\_resources’).run\_script(‘bluerobotics-ping==0.1.0’, ‘simplePingExample.py’)  
File “/usr/lib/python3/dist-packages/pkg\_resources/ **init**.py”, line 666, in run\_script  
self.require(requires)[0].run\_script(script\_name, ns)  
File “/usr/lib/python3/dist-packages/pkg\_resources/ **init**.py”, line 1437, in run\_script  
.format(\*\*locals()),  
pkg\_resources.ResolutionError: Script ‘scripts/simplePingExample.py’ not found in metadata at ‘/home/pi/.local/lib/python3.7/site-packages/bluerobotics\_ping-0.1.0.dist-info’

Could you please help me out, As I have mentioned previously, I am just trying to read the distance data using in python , using raspberry Pi 3

 ![image](https://us1.discourse-cdn.com/flex019/uploads/bluerobotics/original/2X/3/3c08b59c62fabd97aeb79ca634b28f5856510f07.png)

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [July 27, 2021, 8:41am UTC](https://discuss.bluerobotics.com/t/echo-sounder-python-code-for-rasberry-3/10201/4 "2021-07-27T08:41:07Z")

</div>

> [@MokhtarYahia](#):
>
> it seemed that there was no “/ping” folder under /serial ( you can check the screenshot )

I mentioned in my comment that

> [@EliotBR](#):
>
> if you’re not using our companion image you won’t need to quit the ‘pingproxy’ service, but you will need to manually specify the usb port

I’m assuming that’s the case here? `/serial/ping/` is something our companion software sets up, so understandably it won’t exist if you’re not using that software.

> [@MokhtarYahia](#):
>
> when I try to run directly the **simplePingExample.py --device /dev/ttyUSB0** of course trying diffrent USB numbers 0-4 , I get the same error previously

If you want you can try to check which USB device it’s been assigned to by running `dmesg | grep usb | grep FTDI`, which searches the kernel startup messages for detection of a connected FTDI device (serial to USB converter).

I’m not sure why you’re getting that issue, and I can’t reproduce it on my Raspberry Pi 3B or my laptop. I’m a bit confused by the error message you’re getting, and also notice that in your screenshot you’re seemingly in a `~/ping-python/examples` directory, which seems like you’ve cloned the code instead of installing it, or that you’ve installed AND cloned it, in which case it may be struggling to find the correct `simplePingExample.py` to use (when the library is installed it’s supposed to make that file available as a script from anywhere, but that may be conflicting with the one in the directory that you’re in.

I’d suggest you try the following:

```shell
# return to the home directory
cd ~
# install the latest version of bluerobotics-ping (0.1.1)
sudo pip3 install --upgrade bluerobotics-ping
# determine which USB to connect to (/dev/ttyUSBx)
dmesg | grep usb | grep FTDI
# run the ping example on that (TODO: set the correct device!)
simplePingExample.py --device /dev/ttyUSB_

```

If that works for you then you likely want to delete your `~/ping-python/` directory 🙂
