Python code for multiple SDI-12 sensors

As you probably know, the SDI-12 sensor logger code in Python can only log one sensor at a time. It is not a hardware limitation. I wrote the logger code as an example of how to do logging with the SDI-12 adapters and Python. To make sure people don’t have the wrong ideas that you can ONLY get one sensor logged, I have been working on the logger code for the past couple of days and have increased the number of sensors from one to any number you need. The improvement is backward compatible with the configuration file for Raspberry Pi logging, in case you wonder. All that is changed to the user interface is the prompt:

Original prompt:

‘SDI-12 sensor address: (0-9, A-Z, a-z)’

New prompt:

‘Enter all SDI-12 sensor addresses, such as 1234:’


So if you have 4 sensors you want to log together, then just enter all their addresses in a string, such as 1234 and hit enter. All sensor inputs will be saved to log file and sent to sparkfun’s data server. The only limitation on the code now is the sparkfun data server stream. The server stream is set up to only take 6 values so the logger code will send the first 6 values from all sensors to the server. If you wish to lift this limitation, you should create your own stream and set up as many values per data point as you need, and modify the logger code (see the magic number 6?).

Below are some sample data logs:

2/3/2017  12:15:25 AM 1 1.11 26 z 5.09419 5.09381 0.24388 5.09419
2/3/2017  12:15:56 AM 1 1.11 26 z 5.09325 5.0925 0.24388 5.09306
2/3/2017  12:16:28 AM 1 1.11 26 z 5.09363 5.094 0.24375 5.09438
2/3/2017  12:17:02 AM 1 1.11 26 z 5.09194 5.09269 0.24375 5.09306

As you can see, the data are separated by sensor address. The address z is the analog-to-digital converter’s address for SDI-12 + Analog adapter. As you can see, my computer outputs 5.09V instead of the nominal 5V on its USB port.

Here is a link to the new logger code. Give it a try and let me know how you like it.

SDI-12 USB adapter manual updated

I have just finished an update to the SDI-12 USB adapter documentation.


  1. I added a document to the manual: Sensor connection guide. It lists a number of SDI-12 and other sensor wiring information from various manufacturers. Find it in the SDI-12 USB adapter page under documentation.
  2. All sections are now numbered now for easy reference.
  3. Two new sensors have been tested by customers to work perfectly with the adapter: Campbell Scientific CS650 and CS655 soil sensors.
  4. I added an appendix to explain how to use external power for your SDI-12 sensors, in case they don’t work with the 5V power supplied by the SDI-12 USB adapter. A wiring diagram is included.
  5. I added an appendix to explain how to easily connect a Decagon SDI-12 sensor with a stereo plug with a picture.

SDI-12 USD adapter with external power SDI-12 USD adapter with stereo adapter

Soil data logger telemetry

I have finally found time to build a simple website for my soil data logger with telemetry. The system works as the following:

  1. The data logger consists of a raspberry pi and my SDI-12 USB adapter with a Decagon 5TM soil sensor
  2. The data logger runs the open-source datalogger code I wrote in Python to first get parameters from the user (COM port, SDI-12 address, delay etc.), and then collect data, save to a local .CSV file, and then send the same data to sparkfun’s phant server.
  3. I constructed a web interface to plot the data using Google Charts and download .CSV version from sparkfun’s phant server.

Here is a screen shot:

soil logger webpage

I’ve uploaded the webpage to a server with a link below. The sensor is apparently NOT buried in soil so I can easily take the setup and set it up in different places to test its stability.

Link to the website: Link

Update SDI-12 USB adapter firmware

I have just released an update to the SDI-12 USB adapter. This update makes the adapter recover from errors in communication so it won’t hang your data logging process in case a sensor is broken while you are logging.

To make the firmware update easy, I wrote a Python script to use avrdude.exe to load the firmware to the adapter. You will run the script just like the data logging script or config script:

  1. Install Python 3.5 with Pyserial 3.0 (instruction in the manual).
  2. Unzip the content of the firmware update package in a folder.
  3. Check the properties of avrdude.exe to make sure that it is not blocked from running.
  4. Run the script in Python environment IDLE.
  5. Select the adapter’s serial port from a list.
  6. Pick the firmware file, usually SDI_12_translator_v1_x.hex (must be stored in the same folder as the script), then wait for it to complete, which takes less than 30 seconds.

Here is the output from Python:


sdi-12 USB adapter firmware update

I had the adapter on COM4.

Once updated, try connect to it using a terminal program and send zI! (zee-EYE!) and you will see the response has version 1.2 in it.

(Updated) This script now works on Windows, Mac OSX, GNU/Linux (64-bit) and Raspberry Pi.

SDI-12 USB adapter

After some delay, the SDI-12 USB adapter is finally here:

2015-10-03 16.16.57

This adapter is extremely easy to use. Just connect it to your PC and SDI-12 sensor. Then you can use any serial monitor or terminal emulator program to talk with your sensor. Just open the serial port at 9600 Baud rate. You can start by sending device identification command such as ?!. You will see a response from your sensor, which is the one-character address of your sensor. If you have not set its address, it is most likely to be zero (0). Then you can use 0I! to find out the manufacture and model of your sensor, before getting measurements from it. Getting measurement is easy as pie. First send 0M!, then wait for response. Then send 0D0! to fetch the measurements.

For PC users, I even wrote a data logger script that can automatically log data using the popular Tera Term program. You can choose sensor address, total number of data points, delay between points, and time zone when logging, then the program will keep logging data. The following is a screen grab of Tera Term. The sensor is a Decagon 5TM soil temperature and moisture sensor. The address is one (1) and the returned values are relative dielectric permittivity and then temperature in Celsius.

Data logger

Once you get data logging going, you can import the .CSV file into your Excel and plot it. You can choose a proper refresh rate so your data and plot are up to date when you look at them.


I’m still ordering more circuit boards but should be able to sell these on my store starting now. There is even a quantity discount if you need 10 or more.

Inmojo store sales page

%d bloggers like this: