# Retrieving sonar data through pymavlink

**URL:** <https://discuss.bluerobotics.com/t/retrieving-sonar-data-through-pymavlink/14137>\
**Category:** Ping Sonar Devices\
**Created:** [April 18, 2023, 2:14pm UTC](https://discuss.bluerobotics.com/t/retrieving-sonar-data-through-pymavlink/14137 "2023-04-18T14:14:36Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [April 21, 2023, 8:25am UTC](https://discuss.bluerobotics.com/t/retrieving-sonar-data-through-pymavlink/14137/2 "2023-04-21T08:25:51Z")

</div>

Hi @Alstrup,

> [@Alstrup](#):
>
> … we have the blue robotics sonar [Ping Sonar Echosounder for Underwater Distance Measurement](https://bluerobotics.com/store/sensors-sonars-cameras/sonar/ping-sonar-r2-rp/) and we have connected it using the I2C port …

Our Ping Sonar does not communicate using I2C, so this won’t work. You’ll need to either connect it using one of the serial ports, or connect it to the Raspberry Pi using a serial to USB adaptor (like our [BLUART](https://bluerobotics.com/store/comm-control-power/tether-interface/bluart-r1-rp/)).

> [@Alstrup](#):
>
> We are trying to retrieve sonar data through pymavlink

Which data are you after?

- If you only want the distance estimates (and don’t care about changing settings or using Ping Viewer) then you should be able to use a direct serial connection [with some appropriate parameters set in the firmware](https://discuss.bluerobotics.com/t/ping-1d-depth-value/12836/2)
  - In this case the distances may be accessible via either `DISTANCE_SENSOR` or `NAMED_VALUE_FLOAT` messages
  - This approach connects the sonar directly to the autopilot firmware, and BlueOS will not know about it

- If you want more direct control over the sonar’s settings and/or want to use Ping Viewer then you’ll need to either [allow it to pass through from the serial port](https://discuss.bluerobotics.com/t/connecting-ping-sonar-via-navigator-serial-port/12585) or connect it via USB
  - This can still allow distance measurements to be provided over MAVLink by turning on the “MAVLink Distances” option on the [Ping Sonar Devices](https://docs.bluerobotics.com/ardusub-zola/software/onboard/BlueOS-1.1/advanced-usage/#ping-sonar-devices) page
    - This requires BlueOS 1.1, which currently only has beta releases available, so updating to it needs [Pirate Mode](https://docs.bluerobotics.com/ardusub-zola/software/onboard/BlueOS-1.0/advanced-usage/#pirate-mode) to be enabled

  - If you want ping profiles or settings access from your code then you’ll need to use our [Ping Python library](https://github.com/bluerobotics/ping-python) to talk to the sonar, rather than using pymavlink

---

_[View the full topic](https://discuss.bluerobotics.com/t/retrieving-sonar-data-through-pymavlink/14137)._
