116
edits
Changes
Added prototyping script
To quickly see what the sensor transmits on the UART ports, we can use a raspberry pi and a python script. See [https://electrosome.com/uart-raspberry-pi-python/ Using UART on Raspberry PI]
The wiring is simply the TX UART pin connected with the RX pin of the sensor and the TX of the sensor connected through a voltage divider (5K1, 10K) to the RX UART pin of the raspberry.
[[File:Raspberry-pi-2-gpio-pinout.png|thumb|GPIO Pinout]]
The following python script then does all the work easily. A test output can be '''1.26m 25.1°'''.
<syntaxhighlight lang="python" line>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import serial
import binascii
from struct import *
ser = serial.Serial("/dev/ttyAMA0")
ser.baudrate = 9600
ser.write("\0")
output = ser.read(6)
header, distance, temp, checksum = unpack(">cHhc", output)
#print(binascii.hexlify(output))
print("%.2fm, %.1f°" % (distance/1000.0, temp/10.0))
ser.close()
</syntaxhighlight>
= Datasheet =