Experiment no. 3+

  • E3+.1 Name:


  • Raspberry Pi - I2C extension with ADXL345


  • E3+.2 Overview, purpose.


  • The laboratory experiment aims to explore the possibilities of creating extensions for RPi platforms using the I2C communication protocol. Its main specifications are introduced as well as integration into MEMS sensors (acceleration, compass). The example is centered on the ADXL345 acceleration sensor connected to the Rpi zero 2 W equipped with a library module that can be accessed in an application program. At the end of the lab, detailed information will be available about the interconnection of systems that communicate via the I2C protocol to the Raspberry Pi platforms.



  • E3.3 Resources:

  • Raspberry Pi zero2 W platform, RGB LED extension, optotriac extension, MOSFET transistor extension, relay module.




  • E3.4 Source of example programs:

  • View acceleration sensor data

    Sensor tilt event generator

  • E3+.5 Experiment progress/tracking:
  • The I2C protocol uses a serial data transmission using the SDA and SCL lines. The start/stop sequence is represented in the following figure:



    The data is preceded by the device address, a generic transfer cycle for read operations specific to I2C sensors is represented as follows:



    The ADXL345 acceleration sensor module has the following diagram:

    The I2C interface is activated using the Raspi-config utility and the installation of I2C software modules is performed as follows:

    > sudo apt-get update
    > sudo apt-get install -y python-smbus i2c-tools

    After connecting the ADXL345 sensor to the SDA and SCL lines, its address can be viewed as follows:

    > i2cdetect -y 1

    In the correct situation, the previous command will provide the following information:

    A level of abstraction of the sensor is provided by an appropriate software module which can be installed as follows:

    > pip3 install adafruit-circuitpython-adxl34x

    At this stage, the 2 prototype programs can be analyzed and run that allow to visualize the data delivered by the sensor as well as use them to generate some events by the sensor's movement.
    Solve the problems proposed;

  • E3.6 Proposed problems:

  • 1. Create a program that allows you to view the signals SDA and SCL with an oscilloscope. .
    2. Complete example 2 with LEDs for movement on the Y and Z axes.
    3. Create a Python script that will activate the LED when the Y tilt is 90 degrees
    4. Create a Python script that will allow you to detect hand "shaking";
    5. Create a Python script that will activate an LED when the Z tilt is 45 degrees.



  • E3+.7 The Experiment can be extended for:

  • - Development of Cyber ​​Physical System ;
    - Creation of actuators for Internet of Things ;
    - Development of active modules for APACHE servers ;
    - Control of digital actuators from very long distances;



  • E3+.8 Documentary references:


  • © 2010-2026 - Embedded Advanced Computer