Python code for multiple SDI-12 sensors
February 3, 2017 Leave a comment
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.