Raspberry Pi I2C

Controlling I2C on the Raspberry Pi is quite straightforward.

Most of our example code is written in Python, which can easily be edited and run through Thonny.

The Raspberry Pi I2C pins include a fixed 1.8K pull-up resistor to 3V3. (NB: This means these GPIO pins are not suitable for use as general purpose IO where a pull-up is not required).

First we can easily check what is connected to the I2C bus, using the below command in Terminal.

Initially we may need to run a simple command to install the tools.

sudo apt-get install i2c-tools

The Raspberry Pi versions includes two BUS ports, which are denoted as I2C0 or I2C1.  We will only be using I2C1.

This one line command then lists any connected I2C peripherals.  The 1 at the end is the BUS.

sudo i2cdetect -y 1

Using Thonny, you can then write a simple Python script to access I2C.  This uses the smbus library.

import RPi.GPIO as GPIO


#Set FMS6501A I2C Address to either 0x43 or 0x03
i2cbus = smbus.SMBus(1)

Please feel free to share our product love through the below