Sensors – I2C and SPI

The Raspberry Pi has several ‘busses’ (think of them as signal paths!) that can be used to read more complicated sensor signals.

I2C

Pronounced “Eye-squared-see” or “Eye-two-see”, the I2C bus allows you to read from multiple sensors on just two GPIO pins. Each I2C sensor board has a different ‘address’ which means they don’t often conflict. (They do occasionally, so you have to watch out for that!There are many sensors out there, so I won’t describe them all, but a search on eBay (UK/USA) on AliExpress will find you several. You are looking for sensors with pins labelled SDA and SCL. Accessing readings from each sensor can be tricky. However, there are many Python libraries out there for you to use. Just use Google to find them!

The I2C bus is also used for output – some LCD and matrix displays have I2C ‘backpacks’. This reduces the number of wires you need to connect them up.

Analog

One thing the Pi does not have is a way to natively read Analog inputs. Whereas digital signals tend to communicate as either on (1) or off (zero), Analog sources give you a reading over a range. However, to get those ranged readings, you will need something called an analog-to-digital converter. One of the best of these is the MCP3008 which offers 8 pins of analog inputs – perfect for if you have several analog sensors or sources. The nice thing about the MCP3008 is that it is built into GPIO Zero so it’s really simple to get going. Take a look over at RasPi.TV for a good tutorial. The MCP3008 is terrific, but it can be a challenge to wire it up correctly. If you want to do analog easily, without a lot of wiring, take a look at the RasPiO Analog Zero, an add-on board where everything is ‘wired up’ for you.

The MCP3008 uses SPI, which is another ‘bus’ available to you on the Raspberry Pi. There are other analog-to-digital converters that use I2C. Just pick the one that is right for you!