How to test external I2C communication on Raspberry PLC
Learn how to connect an accelerometer on the external I2C of the Raspberry PLC
21 September, 2021 by
How to test external I2C communication on Raspberry PLC
Boot & Work Corp. S.L., Fernandez Queralt Martinez


I2C stands for Inter-Integrated Circuit. It is a bus interface connection protocol incorporated into devices for serial communication.

As the Raspberry PLCs from Industrial Shields have i2c communication, we are going to test it using an Adafruit accelerometer which works through I2C.


How to

Connect Raspberry PLC to Wi-Fi


Raspberry PLC

Family products


How to

Program Raspberry PLC Interrupt inputs with Python


Basics about

Raspberry Pi PLC Analog Outputs


Touchberry Pi

Family products


How to

Find your perfect industrial PLC



Raspberry PLC >>>

Power Supply >>>

Adafruit MMA8451 accelerometer >>> 

  • Either Ethernet cable or external monitor and keyboard to connect to the Raspberry


In order to connect the Adafruit MMA8451 accelerometer to our Raspberry based PLC, we are going to connect the cables as shown in the picture below:

Odoo • Image and Text

 Adafruit MMA8451 Library

First of all, we are going to download the Adafruit MMA8451 Library >>> in the Raspberry PLC to be able to use the examples for our accelerometer. Run the following command:

git clone

Note: You must have internet connection and git installed in your Raspberry PLC. Also, if you get any error by copying the command from this blog, type the command manually.


Once the library is rightly installed, let's test the accelerometer:

1. In your open source hardware, go to:
~/Adafruit_CircuitPython_MMA8451/examples directory:

cd ~/Adafruit_CircuitPython_MMA8451/examples

2. List files to check that there is the file:


3. Now, make sure that Python3 is installed into the Raspberry PLC:

python3 --version

4. Finally, run the python file and enjoy your app! 


Odoo • Image and Text


If you get "OSError: [Errno 121] Remote I/O error", open the python file:


Add a delay of a second right after this line:
i2c = board.I2C()  # uses board.SCL and board.SDA

By adding time.sleep(1.0)

In order that the code looks like:
import time
import board
import adafruit_mma8451

i2c = board.I2C()  # uses board.SCL and board.SDA

# Initialize MMa8451 module.
sensor = adafruit_mma8451.MMa8451(i2C)

Finally, save and exit. Run again your application to enjoy the accelerometer using I2C communication!

How to test external I2C communication on Raspberry PLC
Boot & Work Corp. S.L., Fernandez Queralt Martinez
21 September, 2021
Share this post

Looking for your ideal PLC?

Take a look at this product comparison with other industrial controllers Arduino-based.

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.

Industrial PLC comparison >>

Do you want more information?

Just fill the form!

Tell me more!