# Ping360 example python code

**URL:** <https://discuss.bluerobotics.com/t/ping360-example-python-code/7457>\
**Category:** Ping Sonar Devices\
**Created:** [May 30, 2020, 12:55pm UTC](https://discuss.bluerobotics.com/t/ping360-example-python-code/7457 "2020-05-30T12:55:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fahrettin](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@fahrettin](https://discuss.bluerobotics.com/u/fahrettin)\
**Post date:** [May 30, 2020, 12:55pm UTC](https://discuss.bluerobotics.com/t/ping360-example-python-code/7457/1 "2020-05-30T12:55:44Z")

</div>

We need simple python code applicable for ping 360. It will return the distance information according to the angle value. Can you help us?

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [May 30, 2020, 1:04pm UTC](https://discuss.bluerobotics.com/t/ping360-example-python-code/7457/2 "2020-05-30T13:04:19Z")

</div>

Hi,

Please take a look in [Ping360 documentation](https://bluerobotics.com/store/sensors-sonars-cameras/sonar/ping360-sonar-r1-rp/), the learn tab can be useful.  
For more information about the protocol, check the [ping-protocol documentation](https://docs.bluerobotics.com/ping-protocol/).

---

<div class="post-metadata">

**Author:** ![luuckiest](https://avatars.discourse-cdn.com/v4/letter/l/cab0a1/32.png) [@luuckiest](https://discuss.bluerobotics.com/u/luuckiest)\
**Post date:** [June 22, 2021, 1:04am UTC](https://discuss.bluerobotics.com/t/ping360-example-python-code/7457/3 "2021-06-22T01:04:14Z")

</div>

I am trying to use the p.intialize from the ping360.py in the brping. But it fails all the time. Is there anything I could do/try?

---

<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:** [June 22, 2021, 4:20am UTC](https://discuss.bluerobotics.com/t/ping360-example-python-code/7457/4 "2021-06-22T04:20:00Z")

</div>

Hi @luuckiest, welcome to the forum 🙂

How are you connecting to your ping360, and how are you trying to run the script? Connecting to a ping360 requires specifying either the serial/USB port it’s connected to, or the UDP port if it’s on an ethernet connection/interface, as specified in the command-line arguments [ping360.py](https://github.com/bluerobotics/ping-python/blob/deployment/brping/ping360.py#L284-L286).

Note also that the [second half of that script](https://github.com/bluerobotics/ping-python/blob/deployment/brping/ping360.py#L314-L337) uses auto-transmit functionality, which isn’t yet available in the public version of the Ping360 firmware, so only the first half is expected to work at this stage (which just loops through individual [`transmitAngle`](https://github.com/bluerobotics/ping-python/blob/deployment/brping/ping360.py#L263-L275) messages).

---

<div class="post-metadata">

**Author:** ![luuckiest](https://avatars.discourse-cdn.com/v4/letter/l/cab0a1/32.png) [@luuckiest](https://discuss.bluerobotics.com/u/luuckiest)\
**Post date:** [June 22, 2021, 1:02pm UTC](https://discuss.bluerobotics.com/t/ping360-example-python-code/7457/5 "2021-06-22T13:02:26Z")

</div>

We have correctly use the routing page to set up the udp port to listen to the signal from the ping360.

I am using “python ping360.py --udp 192.168.2.1:9092” to connect to the device. I am also trying to break it down in the code to try to call the Ping360 class in the code and use its function to try to connect to the device.

We are able to use ping-viewer to read the data and decode\_binary.py to see what is in the binary file. But we are not able to directly log the data out from the ping360.

Please let me know if there is anything I can do to directly log the singal/data out from the ping360 sonar! Thanks in advacne

---

<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:** [June 22, 2021, 11:55pm UTC](https://discuss.bluerobotics.com/t/ping360-example-python-code/7457/6 "2021-06-22T23:55:25Z")

</div>

> [@luuckiest](#):
>
> I am using “python ping360.py --udp 192.168.2.1:9092” to connect to the device

The ping UDP connection should be to the companion IP address, not the top computer’s, so you should be using `192.168.2.2:9092` (which is also specified as the UDP example in the command-line arguments lines I linked you to in `ping360.py`).

> [@luuckiest](#):
>
> Please let me know if there is anything I can do to directly log the singal/data out from the ping360 sonar!

Should definitely be possible with the existing script - I was working with that for a bit last year 🙂
