An I2C bus is a widely-used communication system for internal connection between different devices. It is based on the main device working as a master that controls the other devices known as slaves. To send data to a specific slave, it uses the address of its device provided by the manufacturer. In some cases, the provider does not give the address to work, which complicates the I2C communication. In this post, we will see how to know the addresses of the devices that we do not know at first.
Any of our industrial PLC controllers
An I2C device
How to connect it?
If you are using an Arduino automation MDuino Family PLC, no extra connection other than a PC connection is needed to upload the code, since an RTC (Real Time Connection) with I2C communication is included.
If not, you will have to connect to another device using the SCL and SDA communication pins. Also, it is better to connect the same Ground for a proper connection. Both devices must be properly powered, check the device information provided by the manufacturer.
In the picture on the left, you can see an example where an MDunio 21+ is connected to an Arduino Uno using the I2C pins. In the Arduino Uno you can use the A4 (SCL) and A5 (SDA), it might change in other Arduino devices.
We will be programming using Arduino Ide, which is software based on the C language. Industrial Shields provides boards to program the industrial controllers. Basically is not needed to define the pins as inputs or outputs since everything is automatically set up using the boards.
In order to install Industrial Shields boards, the link below explains everything:
After you have set all the board configurations, choose the Board and Model that are used and the Port where de device is connected to the PC in the Tools section of the Arduino Ide. We will use a simple sketch that scans the I2C bus for devices, showing the ones found in the Arduino Serial Monitor on the top right edge of the screen. The code is shown in the section below. Make sure that the Arduino library Wire is previously installed. In our case, we will be detected, as we have said before, the RTC device shown as the 0x68 address. If another device is connected, it should appear in this scan.
byte error, address;
nDevices = 0;
for(address = 1; address < 127; address++ )
error = Wire.endTransmission();
if (error == 0)
Serial.print("I2C device found at address 0x");
else if (error==4)
Serial.print("Unknown error at address 0x");
if (nDevices == 0)
Serial.println("No I2C devices found\n");