Skip to content

RPI420MA - 4/20mA sensor hat for Raspberry Pi

4/20mA sensor hat for Raspberry Pi

Find me in the shop

The RPI420MA interface up to seven 4/20mA sensors with a Raspberry Pi.

Data are sent on the serial port of the Raspberry Pi and are easily read from a terminal or with a Python script.


Hardware Connections

  • There are 7 ports for 4–20mA sensors, available as screw terminals marked Positive (+) and Negative (−).
  • The board also includes a port for an external power supply (required to power the sensors).
    This must be a 12V DC power supply unit, available here.

Raspberry Pi Setup

Please follow the guide below to setup the Raspberry Pi.

Howto setup Raspbian for serial read


Firmware Configuration

You can dump the current configuration into a file using:

lcl-rpict-config.py

The configuration file is stored inside /tmp/rpict.conf.

Example configuration:

[main]
format = 3
nodeid = 11
output_rate = 5000
resistor = 100.0
nsamples = 20
subsample = 100
SCALES = 1.0 1.0 1.0 1.0 1.0 1.0 1.0
OFFSETS = 0.0 0.0 0.0 0.0 0.0 0.0 0.0

Parameter description:

  • format – Unused.
  • nodeid – Device identifier (keep default unless required).
  • output_rate – Interval (ms) for sending data via the serial port.
  • resistor – Hardware resistor value (leave as default).
  • nsamples – Number of samples per acquisition burst (default: 100 samples).
  • subsample – Unused.
  • SCALES – Scaling factors for sensor readings (see section below).
  • OFFSETS – Offsets for sensor readings.

To apply changes, write the modified config back to the HAT:

lcl-rpict-config.py -w /tmp/rpict.conf

Reading the Output

Run:

lcl-run

Example output:

11 3.99 0.00 0.00 0.00 0.00 0.00 0.00
11 3.97 0.00 0.00 0.00 0.00 0.00 0.00
11 3.96 0.00 0.00 0.00 0.00 0.00 0.00
11 3.99 0.00 0.00 0.00 0.00 0.00 0.00
  • Each line is printed every 5 seconds (or according to output_rate).
  • In this example, only port S1 has a sensor connected, reading ~4mA (minimum range). All others are disconnected.

Adjusting SCALES and OFFSETS

The configuration file includes two calibration parameters:

  • SCALES – Multiplication factor
  • OFFSETS – Value to add after scaling

Each list entry corresponds to a port (first entry = S1).

  • Default: scale = 1.0, offset = 0.0 → Output in mA (4–20mA).
  • To output physical values (e.g., pressure in bar, depth in meters), adjust these parameters.

There are two methods:

  1. Using manufacturer specifications
  2. Using experimental measurements

1. Using Manufacturer Specifications

If your sensor outputs:

  • Rmin at 4mA
  • Rmax at 20mA

Then:

scale = (Rmax - Rmin) / 16
offset = (5 * Rmin - Rmax) / 4

Example:
Sensor TL-136 (0–2 m range):

Rmin = 0
Rmax = 2
scale = (2 - 0) / 16 = 0.125
offset = (5*0 - 2) / 4 = -0.5

Add these values to the config to display depth in meters instead of current.


2. Using Experimental Measurements

This method is more accurate if you can measure the real physical value (e.g., with a gauge or ruler).

Steps:

  1. Keep scale = 1.0 and offset = 0.0.
  2. Run lcl-run and take at least 3 reference points:
  3. Measure the physical value
  4. Record the corresponding current reading

Example for a 2m TL-136 sensor:

X (mA) Y (m)
3.98 0.0
12.1 1.05
19.5 1.98
  1. Use a linear regression calculator:
  2. X values: currents from RPI420MA
  3. Y values: physical measurements (gauge or ruler)

The calculator returns:

ŷ = 0.12761X - 0.5034

So:

scale = 0.12761
offset = -0.5034