0

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?

dsolimano
  • 8,870
  • 3
  • 48
  • 63
user3753225
  • 1
  • 1
  • 2
  • Please provide more detail about the RS-232 to SDI-12 interface device you are using. Does it have logic to transmit SDI-12 commands using the precise millisecond timing required by SDI-12, with wakeup breaks and retires as needed? – Mike Jablonski Jul 21 '14 at 22:59
  • typically the rs232 converter will run at 9600 baud on the end that enumerates as a serial port.... incidentally I wrote a library for SDI-12 with the Arduino https://github.com/joranbeasley/SDISerial ... the extra start bit usually is important and sdi will not function properly without it ... so its somewhat non-trivial to fix (so you cant talk directly to the sensor with pyserial typically).... – Joran Beasley Jun 06 '15 at 04:25

0 Answers0