# Python to access the Ping raw data on Raspberry PI

**URL:** <https://discuss.bluerobotics.com/t/python-to-access-the-ping-raw-data-on-raspberry-pi/4225>\
**Category:** Ping Sonar Devices\
**Created:** [February 5, 2019, 6:47am UTC](https://discuss.bluerobotics.com/t/python-to-access-the-ping-raw-data-on-raspberry-pi/4225 "2019-02-05T06:47:08Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [February 8, 2019, 7:41pm UTC](https://discuss.bluerobotics.com/t/python-to-access-the-ping-raw-data-on-raspberry-pi/4225/13 "2019-02-08T19:41:52Z")

</div>

> It would be really helpful if you could illustrate the extraction of data from ‘profile-data’ variable say to JSON?

It’s as simple as `print(data)`

Here is an example program:

```py
#!/usr/bin/env python

from brping import Ping1D
import argparse

##Parse Command line options
############################

parser = argparse.ArgumentParser(description="Ping python library example.")
parser.add_argument('--device', action="store", required=True, type=str, help="Ping device port.")
parser.add_argument('--baudrate', action="store", type=int, default=115200, help="Ping device baudrate.")
args = parser.parse_args()

#Make a new Ping
myPing = Ping1D(args.device, args.baudrate)
if myPing.initialize() is False:
    print("Failed to initialize Ping!")
    exit(1)

data = myPing.get_profile()
print("dictionary data looks like this:", data)
print("access distance:", data["distance"])

```

And the output:

```sh
$ python ex.py --device=/dev/ttyUSB0 --baudrate=9600
Opening /dev/ttyUSB0 at 9600 bps
('dictionary data looks like this:', {'distance': 13917, 'confidence': 0, 'scan_start': 0, 'profile_data': "\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd\xfd'0\x08\x00\x01\x01\x08\x01\x00\x01\x00\x02\x04\x03\x06\x08\x10\x03\x00\x01\x00\x00\x00\x00\x03\x01\x01\x01\x03\n\x03\x03\x01\x00\x03\x08\x03\x03\x00\x00\x00\x02\x02\x05\x00\x00\x00\x00\x01\x05\x01\x04\x04\x06\x06\x00\x00\x00\x00\x01\x00\x02\x02\x02\x02\x00\x00\x02\x03\x00\x00\x00\x00\x00\x03\x04\x03\x00\x00\x00\x00\x03\x02\x05\x04\x04\x04\x00\x01\x00\x00\x00\x00\x00\x00\x03\x03\x03\x01\x00\x00\x00\x00\x00\x00\x00\x03\x05\x04\x02\x00\x00\x01\x02\x0b\x0c\x04\x07\r+?5.\x16\t\x02\x07\x01\x01\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x00\x00\x04\x02\x03\x05\x00\x00\x01\x01\x00\x00\x03\x02\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00.\xfd8\x00", 'scan_length': 20750, 'gain_index': 6, 'ping_number': 570, 'pulse_duration': 556})
('access distance:', 13917)

```

---

_[View the full topic](https://discuss.bluerobotics.com/t/python-to-access-the-ping-raw-data-on-raspberry-pi/4225)._
