Skip to Content

Expanding I/O over I2C with M-Duino or Ardbox

The pump station grows: a second tank, more valves, more sensors, and the PLC runs out of terminals. The next step is expansion, not a second unrelated controller. The M-Duino and Ardbox expose an I2C bus, and that bus is how you add more inputs and outputs while one controller keeps running the logic.

What you will learn

  • Explain the master and slave roles on an I2C bus.
  • Find the devices on the bus with a scan and avoid address clashes.
  • Decide between I2C expansion and a second PLC using Modbus.

One master, many slaves

On an I2C bus, one device is the master and talks to the others, which are slaves. The master starts every conversation, and slaves never talk to each other directly. Your M-Duino is the master and runs the main logic. The slaves can be I/O expander modules, sensors, converters or another Arduino-based board programmed as an I2C slave. They extend what your program can see and drive, they do not run the machine logic.

Each slave has a 7-bit address and every address on the bus must be unique. There is no fixed limit on the number of expansion modules: it depends on the addresses still available and on the electrical capacity of the bus, which is shaped by the cable type, its length and the number of devices. Start with a few modules and test.

Industrial Shields does not provide a dedicated I2C library. You use the standard Arduino Wire library.

Set up the bus on the M-Duino

  1. Connect SDA and SCL of every device to the SDA and SCL terminals of the M-Duino, and share ground.
  2. Check the SCL and SDA switches: these terminals are shared with other functions, and the switches select which one is active. For I2C they must select SCL and SDA, not the inputs. See section 9 of the user guide for your model.
  3. You do not need external pull-up resistors for short runs, since the M-Duino already includes them. For longer cables or higher speeds, add external pull-ups between 1 kΩ and 4.7 kΩ.

Try it: scan the bus

#include <Wire.h>

void setup() {
  Serial.begin(9600);
  Wire.begin();

  for (byte address = 1; address < 127; address++) {
    Wire.beginTransmission(address);
    if (Wire.endTransmission() == 0) {
      Serial.print("Found device at 0x");
      Serial.println(address, HEX);
    }
  }
  Serial.println("Scan finished");
}

void loop() {}

Expected result: the Serial Monitor lists the address of each connected device, then prints Scan finished.

If it fails: if no device appears, check that SDA and SCL are not swapped, that the switches select I2C, that the device has power and a common ground, and that no two devices share an address.

Why expand instead of adding a second PLC

Two independent PLCs need their own link and logic to stay in sync, which is extra complexity for what is really one machine. Expansion keeps one program on one master in control of every input and output, which is simpler to reason about and to debug.

Exercise: plan the I/O before you wire

Fill in a table like this one for your own machine before installation:

DeviceSignalTypeCable length to the I2C master
MasterStart, emergency stop2 inputsin the same panel
MasterPump 1, beacon2 outputsin the same panel
Expansion 1Tank 2 level1 analog inputto measure
Expansion 1Valves 1 to 44 outputsto measure

The last column matters: I2C is a short-range bus, so plan the physical layout accordingly rather than assuming any wiring distance will work.

When expansion is not the right answer

If the extra I/O is physically far from the PLC, across a building rather than in the same panel, a second PLC talking Modbus back to the first is usually a better fit than stretching an I2C bus. Expansion solves running out of terminals in one panel, not spreading I/O across a site.

Go deeper

Next lesson: a first dashboard for the pump station. Take the quiz below first.

Rating
0 0

There are no comments for now.

to be the first to leave a comment.