Bioreactor controlM-DuinoModbus RTUAcquisition
Reading 32-bit flow meter totals with remote reset
Tracking process water in and out of a bioreactor means reading a totalizer that grows past what 16 bits can hold. This example, from a real bioreactor control deployment, shows a Modbus flow meter 32-bit counter read on an M-Duino PLC over RS485, with a remote reset exposed as a Modbus TCP coil. Two flow meters sit at addresses 5 and 6 on the 9600 8N1 bus, and the SCADA zeroes a counter just by flipping a coil.
A 32-bit total across two registers
Accumulated litres live at register 0x100 as two 16-bit registers. The reader fetches both, validates the response, and combines them into a 32-bit total. That total is then split back into two input registers on the TCP side, so the SCADA reconstructs the exact litre count the field device reported.
Remote reset as a coil
The reset command at RTU register 0x200 is surfaced to the SCADA as a coil. When an operator sets the coil, the loop sends the reset to the meter and, once it confirms, clears the coil again. This handshake means a reset happens exactly once per request instead of firing every scan while the coil stays high.
TCP and RTU in one loop
Calling update() services the SCADA while a 500 ms timer polls both meters over RTU. The same pass checks the reset coils first, then refreshes the totals, so a freshly zeroed counter reads back at zero on the very next cycle without any race between the reset and the read.
A snippet from the implementation
Straight from the example as deployed on the M-Duino — copy it freely:
void setup() {
Serial.begin(115200);
master.begin(9600);
master.setTimeout(300);
modbus.addInputRegisters(0, inputRegs, 12);
modbus.addCoils(0, coils, 18);
modbus.begin();
}The full example is a complete program — wiring header, setup and main loop — ready to adapt to your application.
Frequently asked questions
Why store the total across two registers?
A flow totalizer counts well beyond 65535 litres, which overflows a single 16-bit register. Two registers give a 32-bit value with plenty of headroom before it wraps.
How does the SCADA reset a counter?
It sets the reset coil for that meter. The PLC sees the coil, sends the RTU reset command, and clears the coil once the meter confirms, so the reset fires exactly once.
Can both meters be reset independently?
Yes. Each meter has its own coil and RTU address, so the SCADA resets meter 5 or meter 6 without touching the other.