• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Protocols - I2C I/O
  • I2C Setup Guide
  • 5.0.0

I2C I/O Manual I2C I/O Communicating with Arduino compatible microcontrollers

I2C Setup Guide

STMicroelectronics LSM9DS1 accelerometer

This guide demonstrates how to get accelerometer data from a Raspberry Pi Sense HAT. According to the specification, the Raspberry Pi Sense HAT uses STMicroelectronics LSM9DS1 device to provide accelerometer data. Although LSM9DS1AccelerometerGyroscope or SenseHAT recipe can already get the data from the device, this example demonstrates how to get the data using the general purpose models only.

This example assumes that the device is located at: /dev/i2c-1 and leverages the fact that the LSM9DS1 on Raspberry Pi Sense HAT has device address 0x6A.

  1. Create a system.
  2. Add I2CIOServer to the application of the system.
  3. Set Adapter of the I2CIOServer to /dev/i2c-1.

    Note: One can run i2cdetect -l to check if /dev/i2c-1 is available.

  4. Add I2CDevice to the I2CIOServer.
  5. Set Address of the I2CDevice to 0x6A.
  6. Add I2CRegisterWrite to the I2CDevice.
  7. Set Address of the I2CRegisterWrite to 10 (in hexadecimal notation).
  8. Add eight CDPSignalChannels of type bool to the I2CRegisterWrite with the following attributes:

Note: This channel group of 1 byte at address 0x10 corresponds to CTRL_REG1_G of the LSM9DS1 device. It is used to configure Gyroscope output data rate selection at startup (or runtime when changed). This example sets the Gyroscope output data rate to 952 Hz by setting ODR_G0 and ODR_G1 bits to 1.

NameNrValue
BW_G000
BW_G110
Placeholder20
FS_G030
FS_G140
ODR_G051
ODR_G161
ODR_G270
  1. Add I2CRegisterRead to the I2CDevice.
  2. Set Address of the I2CRegisterRead to 28 (in hexadecimal notation).
  3. Add three CDPSignalChannels of type short to the I2CRegisterRead with the following attributes:

Note: This channel group of 6 bytes at address 0x28 corresponds to OUT_X_XL, OUT_Y_XL, OUT_Z_XL of the LSM9DS1 device containing the linear acceleration of X, Y and Z, two bytes each. This channel block will be read out at I2CIOServer fs frequency.

Name
AccelerationX
AccelerationY
AccelerationZ

As the 16-bit values in two’s complement notation do not correspond to any SI magnitude it is useful to scale the values to known SI units. This is achieved by using ScalingOperator to scale the Max positive value 32767 to represent 2g and Min value -32768 to represent -2g.

  1. Add ScalingOperator of type double to each CDPSignalChannel of type short.
  2. Add two ScalingPoints of type double to each ScalingOperator with the following attributes:
InValueOutValue
-32768-2
327672

The values of the CDPSignalChannels of type short should now vary between -2g...2g.

It is possible that more complex devices require more operators to be used in the channels to perform for example output calibration like in the HTS221HumidTemp model.

Note: Some I2C devices may require a custom CDPOperator to be created by the user to perform complex calibration or formatting of output values.

I2C I/O Manual I2C I/O Communicating with Arduino compatible microcontrollers

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2025 CDP Technologies. Privacy and cookie policy.

Return to top