Raspberry I2C Setup

From FlightGear wiki
Jump to navigation Jump to search

I2C Buses Activation

You need to activate I2C buses with the Raspberry Configuration Tool.

pi@raspberrypi:~ $ sudo raspi-config

┌────────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├────────┐
│                                                                               │
│ 1 Change User Password Change password for the default user (pi)              │
│ 2 Hostname             Set the visible name for this Pi on a network          │
│ 3 Boot Options         Configure options for start-up                         │
│ 4 Localisation Options Set up language and regional settings to your location │
│ 5 Interfacing Options  Configure connections to peripherals                   │
│ 6 Overclock            Configure overclocking for your Pi                     │
│ 7 Advanced Options     Configure advanced settings                            │
│ 8 Update               Update this tool to the latest version                 │
│ 9 About raspi-config   Information about this configuration tool              │
│                                                                               │
│                                                                               │
│                                                                               │
│         <Select>                                                  <Finish>    │
│                                                                               │
└───────────────────────────────────────────────────────────────────────────────┘

Select Option 5 Interfacing Options.

┌────────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├───────┐
│                                                                              │
│  P1 Camera      Enable/Disable connection to the Raspberry Pi Camera         │
│  P2 SSH         Enable/Disable command line access to your Pi using SSH      │
│  P3 VNC         Enable/Disable graphical access to your Pi using RealVNC     │
│  P4 SPI         Enable/Disable automatic loading of SPI kernel module        │
│  P5 I2C         Enable/Disable automatic loading of I2C kernel module        │
│  P6 Serial      Enable/Disable shell and kernel messages of serial connection│
│  P7 1-Wire      Enable/Disable one-wire interface                            │
│  P8 Remote GPIO Enable/Disable remote access to GPIO pins                    │
│                                                                              │
│                                                                              │
│                                                                              │
│                                                                              │
│         <Select>                                                  <Back>     │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

Select P5 I2C

┌──────────────────────────────────────────────────────────┐
│                                                          │
│ Would you like the ARM I2C interface to be enabled?      │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│               <Yes>                  <No>                │
│                                                          │
└──────────────────────────────────────────────────────────┘

Answer yes

┌──────────────────────────────────────────────────────────┐
│                                                          │
│ The ARM I2C interface is enabled                         │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                                                          │
│                          <Ok>                            │
│                                                          │
└──────────────────────────────────────────────────────────┘
┌────────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├─────────────┐
│                                                                                    │
│  P1 Camera      Enable/Disable connection to the Raspberry Pi Camera               │
│  P2 SSH         Enable/Disable remote command line access to your Pi using SSH     │
│  P3 VNC         Enable/Disable graphical remote access to your Pi using RealVNC    │
│  P4 SPI         Enable/Disable automatic loading of SPI kernel module              │
│  P5 I2C         Enable/Disable automatic loading of I2C kernel module              │
│  P6 Serial      Enable/Disable shell and kernel messages on the serial connection  │
│  P7 1-Wire      Enable/Disable one-wire interface                                  │
│  P8 Remote GPIO Enable/Disable remote access to GPIO pins                          │
│                                                                                    │
│                                                                                    │
│                                                                                    │
│                                                                                    │
│         <Select>                                                  <Back>           │
│                                                                                    │
└────────────────────────────────────────────────────────────────────────────────────┘

Now to return to the main menu, select Back

┌────────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├─────────────┐
│                                                                                    │
│ 1 Change User Password Change password for the default user (pi)                   │
│ 2 Hostname             Set the visible name for this Pi on a network               │
│ 3 Boot Options         Configure options for start-up                              │
│ 4 Localisation Options Set up language and regional settings to match your location│
│ 5 Interfacing Options  Configure connections to peripherals                        │
│ 6 Overclock            Configure overclocking for your Pi                          │
│ 7 Advanced Options     Configure advanced settings                                 │
│ 8 Update               Update this tool to the latest version                      │
│ 9 About raspi-config   Information about this configuration tool                   │
│                                                                                    │
│                                                                                    │
│                                                                                    │
│         <Select>                                                  <Finish>         │
│                                                                                    │
└────────────────────────────────────────────────────────────────────────────────────┘

Then the Finish button to end the configuration session.

Now the I2C buses are activated on the Raspberry.

I2C buses control

The I2C utilities can be checked with the 'i2cdetect' command. This command scans the I2C bus passed as a parameter and displays the addresses of the discovered elements

fgint@raspberrypi:~ $ 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: -- -- -- -- -- -- -- --
fgint@raspberrypi:~ $

If you have message as like :

fgint@raspberrypi:~ $ i2cdetect -y 1
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory
fgint@raspberrypi:~ $

This probably mean, that you didn't activate I2C support on your Raspberry.

If the i2cdetect command can not be found, you can install it the following way:

fgint@raspberrypi:~ $ sudo apt-get install i2c-tools

Example

On our Radio Panel project, we have 3 devices used : 2 MCP23017 and 1 HT16K33

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

The bus checked is number 1. The I2C buses 0 is not available, it is revered for the connection of the PI cameras. In the example above, 3 devices were discovered.