User Guide
Table Of Contents
176
You can use several properties of the SpiDev class to change
how the SPI methods work. This is useful when you are using SPI
devices that do not follow the usual process.
7.8 I2C Communication
I2C (pronounced eye-too-see) is another serial communications
protocol, but it uses fewer wires. The master device controls I2C
communications, and you connect all slave devices to the same
wires. Each slave device has a unique number (called an
“address”) and it only responds to messages that it receives
which specify this address. This means that you cannot use two
slave devices that have the same address.
The two I2C lines are called SDA and SCL. You need to use a
pull-up resistor on these lines. The value of the resistors is not
very important, but around 10 KΩ is generally suitable.
I2C can be convenient on the Pi because you only have to
convert the logic level of the SDA wire to interface with 5 V
devices (regardless of how many 5 V slave devices you actually
connect to those lines).
Any GPIO pins can be used for I2C, if you want to write all of the
code. But it is a more complicated protocol to implement from
scratch. To use prebuilt I2C libraries and modules, the two I2C
wires are pin 3 and pin 5 of the GPIO header.
Property Description
cshigh When True, a high signal is used to tell the slave
device that it should listen and respond. When
False, a low signal is used. False is the default.
max_speed_hz Not all SPI devices can run as fast as the Pi.
Decrease the value of this property to slow the SPI
transmissions down.
mode Sets the clock polarity and phase. Can be 0–2.