modbus to i2c

Hello Everyone!

I'm new to the Arduino ecosystem, I don't know if this is possible. I'd like to use an Uno with some i2c expanders to control 64 or more i/o and then map them to modbus so that it would be a modbus slave.

I've played with the modbus library and gotten the onboard i/o to work as coils and such but my ability stops there. I don't know enough about programming to combine the 2 technologies on one device.

Any guidance would be greatly appreciated.

As I understand the Modbus protocol, you have to distinguish between coils or discrete inputs (digital I/O pins), and registers (16 bit values). Now it depends on every I2C slave, whether it serves multiple digital I/O pins (port expander...) or numeric sensor/actor values (temperature, servo angle...). With the Modbus restriction to 16 bit (int) values, you may have to map sensor values into just that range.

If you give an example of a concrete sensor or actor, connected to the I2C bus, we can go into details for handling just that device.

Conceptually what you require is not a difficult task. The success will come down to the implementation of the hardware design, in terms of the I/O interfacing and its requirements and then how well the software is constructed.

Which Modbus library are you currently using ? Maybe post your code here so we can get an idea of the current situation so we can better understand and help. Maybe also a short description of the specific needs, for example timing constraints or other interfacing requirements.


Paul - VK7KPA

I got called off to work and haven't been back home to continue this.

My goal is to have 1 arduino as a modbus slave with 4 other arduinos under it using i2c serving up 64 inputs and outputs. 16 i/o per arduino.

That keeps me in the limits of i2c I/O I believe.

The icing on the cake would be that the main slave could have an ethernet shield on it and use modbus tcp

I got this library to work on 1 uno and control it's onboard i/o http://myarduinoprojects.com/modbus.html

I'm just not sure how to make it control the inputs and outputs on the slaves that are using i2c and the wire library.

When I get home this weekend I'll post code of what I've been working with.

Thank you guy for getting back to me!