Skip to Content

← All functionalities

Bioreactor controlM-DuinoModbus TCPModbus RTURS485Communication

Modbus TCP to RTU gateway for a bioreactor plant

A Modbus TCP to RTU gateway lets a SCADA talk to a whole plant through one IP address while the PLC handles the serial bus behind it. This example, taken from a real bioreactor control deployment, turns an M-Duino into a Modbus TCP slave on port 502 and a Modbus RTU master on RS485, driving six slaves: two chillers, two variable frequency drives and two flow meters. The trick is keeping the TCP side responsive while the RTU side polls without ever blocking the loop.

One IP in front, six RS485 slaves behind

The SCADA sees a single Modbus TCP device on port 502 with coils, holding registers and input registers. Behind it, the M-Duino is the RTU master on a 9600 8N1 RS485 bus shared by six slaves. The gateway maps each TCP register to the right slave and function, so the control room never needs to know there is a serial bus at all.

Non-blocking round-robin polling

Calling update() keeps the TCP image alive on every loop pass. A 200 ms timer advances a round-robin pointer across the six slaves, doing one RTU transaction per step. With a short master timeout, a silent or slow slave delays only its own slot instead of freezing the whole gateway, so the SCADA always gets a fresh answer.

Setpoints down, measurements up

Holding registers carry setpoints and run commands the SCADA writes; input registers carry temperature, pH, accumulated litres and real RPM the gateway reads back. Two 16-bit registers are combined into 32-bit values for flow totals and motor speed, so a 250 rpm reading survives the trip from RS485 to Ethernet intact.

A snippet from the implementation

Straight from the example as deployed on the M-Duino — copy it freely:

void setup() {
  Serial.begin(115200);

  // RTU master at 9600 8N1 (short timeout: we do not want to block the TCP)
  master.begin(9600);
  master.setTimeout(200);

  // TCP slave: publish the three memory blocks
  modbus.addCoils(0, coils, 18);
  modbus.addHoldingRegisters(0, holdingRegs, 10);
  modbus.addInputRegisters(0, inputRegs, 12);
  modbus.begin();             // listen on port 502
}

The full example is a complete program — wiring header, setup and main loop — ready to adapt to your application.

Frequently asked questions

Why use a gateway instead of connecting the SCADA directly to RS485?

Most SCADA and control rooms speak Modbus TCP over Ethernet, while field devices like chillers and drives speak Modbus RTU over RS485. The M-Duino bridges both worlds with one device and one IP address.

How many RTU slaves can share the bus?

This deployment uses six on a single RS485 segment at 9600 baud. The round-robin polling scales to more, but watch the total cycle time so each slave is still refreshed often enough.

Does a slow slave block the others?

No. The master uses a short timeout and the loop polls one slave per 200 ms step, so an unresponsive device only costs its own slot and never freezes the TCP side.

Related functionalities