Every TRIME TDR sensor has a communication protocol which enables various settings to be made by using digital communication. However, learning a new communication protocol format can be time consuming. In this post, I will show how perform the communication between a TRIME-PICO 32 and a Raspberry Pi.
We will require a SM-USB, a USB-cable, a TRIME-PICO 32, a power adapter (With Output +12V 2A), and a Raspberry Pi. In this post, I will be using a Raspberry Pi 3B+, though it is proven to work with Raspberry Pi Version 2 and 4.
Note that the TRIME-PICO 32 is connected to the SM-USB on the RS-485 connector. Also, if your TRIME sensor only has the IMP-Bus connector, you can connect to the other IMP-Bus connector, where it will work equally well.
Identify the COM-Port / the ttyUSB port
Navigate to the dev folder
Then, check which new ttyUSBx appears by listing the assets
In my case, the ttyUSB0 appears when the USB-cable is connected to the Raspberry Pi.
Getting the serial number of the TRIME sensors
There are two ways to get the serial number of the TRIME sensor. First method is to find a small tag along the TRIME sensor cable.
A second approach is to launch the TrimeTool software that scans the serial number directly from the sensor.
Using the IMPLIB2 Python library
To perform the communication between the TRIME-PICO 32 with the Raspberry Pi, it is best to start the development in a virtual environment.
Then, you must activate the virtual environment, a (testenv) label will be shown on your command line.
If you want to deactivate the virtual environment later, you can use the command. Please not not deactivate the virtual environment for this tutorial.
Before we start running a python test script, we need to know the COM-Port connection and the serial number of the TRIME sensors. In my case, I have /dev/ttyUSB0 as my port, and 43169 as the serial number.
Now, we need to install the IMPLIB2 python library.
pip install implib2
Run this script and you should be able to receive the measurement data.
import implib2 from datetime import datetime import time serno = 43169 bus = implib2.Bus("/dev/ttyUSB0") if bus.sync(): print("Bus connection active!") else: print("Bus connection lost, please check the connection!") now = datetime.now() ts = time.time() year = now.year month = now.month day = now.day hour = now.hour min = now.minute sec = now.second mod0 = implib2.Module(bus, serno) mod0.start_measure() while mod0.measure_running(): time.sleep(0.5) TT = mod0.get_measurement('TransitTime') PTT = mod0.get_measurement('PseudoTransitTime') MOIST = mod0.get_measurement('Moist') TDR = mod0.get_measurement('TDRValue') EC = mod0.get_measurement('Info1') MTEMP = mod0.get_measurement('MeasTemp') print("Writing: %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s; %s\n" % ( serno, ts, year, month, day, hour, min, sec, TT, PTT, MOIST, TDR, EC, MTEMP))