Raspberry Pi data logger for SDI-12 ussing python

2.8k views Asked by At

Ive been working a on a raspberry pi system now for a while. I am still having trouble with a couple of my sensors. I am trying to control a scientific sensor using SDI-12 commands and settings.

First I am using the standard of a baud of 1200, 7 data bits, 1 parity bit (even parity) and one stop bit.

#####
#pySerial python library
import serial

#####
import time

#####
#sonde is the name of the sensor
sonde=serial.Serial('/dev/ttyUSB0')
sonde.parity=serial.PARITY_EVEN
sonde.bytesize=serial.SEVENBITS
sonde.stopbits=serial.STOPBITS_ONE
sonde.baudrate=1200

#####
# Sometimes the devices take a while to respond, this is the standard mentioned 
# in the  devices manual. 
sonde.timeout=30

sonde.break(12000)


#####
# The devices address is 0
sonde.write('0I!')

##### 
# Wait 30 seconds before reading from the sensor
time.sleep(30)

for line in sonde:
    print(line)
    print('\n')

All of this is in accordance to the standard except that SDI-12 uses 1 start bit but pySerial does not have a field for that. Should I be taking that into account in some other way?

The device has a manufacture provided wiring harness that converts the SDI-12 wiring to RS-232. I have been connecting the device to the pi with a standard serial to usb adapter that has functioned with other sensors.

When I run this code on the pi the terminal display characters or symbols that I know are incorrect. My first thought was that there might be a issue where the baud rate is off but I have tried all the widely used baud rates.

Im not really sure what to do next besides try many more settings that are not part of the SDI-12 standard. Using a carriage return ('\r'), new line ('\n') or a combination of the two ('\r\n') has made no difference in the responses.

What should I do so that I can see the proper response from this command and not gibberish?

0

There are 0 answers