Archimede Documentation

Info

I2C is a popular communications protocol and is used by a lot of sensors and devices. I²C uses only two bidirectional open collector or open drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors.

https://en.wikipedia.org/wiki/I2C

Pinout

 

In Archimede there are tw0 I2C interface, as any other onboard interfaces these interfaces can be powered on and off using GPIO.

InterfaceEnable PINRoadRunner PIN
3V3 Device 0PA8
SDA0PA6
SCL0PA7
3V3 Device 1PA9
SDA1PC20
SCL1PC19

For info about how to power on and off the interface see —LINK A UNA PAGINA DEDICATA—

Use I2C from userspace

i2c-tools

The faster way to do the first experiments with this board is by installing and using the i2c-tools.

i2c-tools is a package that contains a set of I2C tools for Linux such as:

  • a bus probing tool
  • a chip dumper
  • a register-level access helpers
  • an EEPROM decoding scripts

To install i2c-tools on the FOX Board just type:

$ apt-get update
$ apt-get install i2c-tools

List all the enabled devices:

$ i2cdetect -l
i2c-0   i2c     OMAP I2C adapter      I2C adapter
i2c-1   i2c     OMAP I2C adapter      I2C adapter

Scan all addresses on one device:

$ i2cdetect -r 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0 using read byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] Y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- UU -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- UU -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: UU -- -- -- -- -- -- --

Write one byte to a device and an address:

$ i2cset -y 2 0x77 0xf4 0x34

Read one byte from a device and an address:

$ i2cdump -y 2 0x77

 

Example 1: Taking temperature, humidity and air pressure 

Bosch BME280

In this example a BOSCH BME280 sensor has been plugged.

We will use python to read and print temperature, humidity and air pressure from the sensor.

To do this we use the library at https://github.com/kbrownlees/bme280/

We ned to first install the package python-smbus, so:

$ apt-get install python-smbus

Then using pip:

$ pip install bme280

Adafruit have a good run through of setting up their break out version of the bme280 at https://learn.adafruit.com/adafruit-bme280-humidity-barometric-pressure-temperature-sensor-breakout/wiring-and-test

You will need to know the i2c address being used by the bme280, it is usually 0x76 or 0x77. To verify which devices are connected you can use:

$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- 77

Our device is connected at the address 0x77, so we can now read data from the sensor:

$ read_bme280 --i2c-address 0x77

1017.58 hPa
  50.55 %
  19.03 ℃

 

 

 

 

Contact US

For clarification or suggestions to improve the documentation