Introduction

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.

Setup

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

cd /dev

Then, check which new ttyUSBx appears by listing the assets

ls

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 serial number 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.

virtualenv testenv

Then, you must activate the virtual environment, a (testenv) label will be shown on your command line.

source testenv/bin/activate

If you want to deactivate the virtual environment later, you can use the command. Please not not deactivate the virtual environment for this tutorial.

deactivate

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))

2 thoughts to “Communication between a TRIME TDR sensor and a Raspberry Pi

  • Alex

    Long time supporter, and thought I’d drop a comment.

    Your wordpress site is very sleek – hope you don’t mind me asking what theme you’re using?
    (and don’t mind if I steal it? :P)

    I just launched my site –also built in wordpress like yours– but
    the theme slows (!) the site down quite a bit.

    In case you have a minute, you can find it by searching for “royal cbd” on Google (would appreciate any feedback) – it’s still in the works.

    Keep up the good work– and hope you all take care of yourself during the coronavirus scare!

    ~Alex

    Reply
    • Nicholas Jerome

      Hi Alex,

      Thanks for your support. I’m using one of the few default templates by WordPress – TwentySixteen. Also, you have to make further customization to have it as you want. If you have questions, you can ask me, I can surely help you out 🙂

      If you launch your website with WordPress, you have to make sure not to use too many plugins; or you have to check whether those plugins are slowing your website down. Start analyzing using Google Search Console to optimize your website speed.

      Your website is not that slow, maybe you need to optimize the size of your images, and possibly using a lazy loading image plugin. This helps the first download time of your website.

      You too, stay healthy.

      – Nicholas

      Reply

Leave a comment

Your email address will not be published. Required fields are marked *