Adafruits Raspberry Pi Lesson 4 Gpio Setup
Adafruits Raspberry Pi Lesson 4 Gpio Setup
GPIO
Setup
Created by Simon Monk
https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup
Overview 3
Adafruit Pi Code 5
Configuring I2C 6
• Installing Kernel Support (with Raspi-Config)
• Testing I2C
Configuring SPI 10
• Installing Kernel Support (with Raspi-Config)
The GPIO connector actually has a number of different types of connection on them.
There are:
• True GPIO (General Purpose Input Output) pins that you can use to turn LEDs on
and off etc.
• I2C interface pins that allow you to connect hardware modules with just two
control pins
• SPI interface with SPI devices, a similar concept to I2C but a different standard
In this tutorial, you are not actually building anything, but you will learn how to
configure your Raspberry Pi and install useful libraries ready to start attaching some
external electronics to it.
As well as supplying power (GND, 3.3V and 5V) all the GPIO pins can be used as
either digital inputs or outputs. The pins labelled SCL and SDA can be used for I2C.
The pins labelled MOSI, MISO and SCKL can be used to connect to high speed SPI
devices.
All the pins have 3.3V logic levels and are not 5V-safe so the output levels are 0-3.3V
and the inputs should not be higher than 3.3V. If you want to connect a 5V output to a
Pi input, use a level shifter ()
This uses a ribbon cable to connect the GPIO connector to solderless breadboard,
where you can add your own components.
Adafruit Pi Code
To make life easy for those wishing to experiment with attaching electronics to their
Pi, Adafruit have produced an extensive and extremely useful collection of code. This
includes simple CircuitPython Libraries () for a large number of modules, including
displays, sensors, actuators and more.
To fetch this code, you need to use some software called 'git'. .
Configuring I2C
I2C is a very commonly used standard designed to allow one chip to talk to another.
So, since the Raspberry Pi can talk I2C we can connect it to a variety of I2C capable
chips and modules.
Go to Interfacing Options
Enable!
sudo reboot
sudo i2cdetect -y 1
This shows that two I2C addresses are in use – 0x40 and 0x70.
These values will be different for you depending on what is currently attached to the
I2C pins of your Raspberry Pi
Note that if you are using one of the very first Raspberry Pis (a 256MB Raspberry Pi
Model B) then you will need to change the command to:
sudo i2cdetect -y 0
The Raspberry Pi designers swapped over I2C ports between board releases. Just
remember: 512M Pi's use i2c port 1, 256M ones use i2c port 0!
When you are finished in raspi-config reboot for the i2c modules to automatically load
into the kernel.
Go to Interfacing Options
Go to Interfacing Options
That's it!
Next time you log in you can check that you can see the devices with
ls -l /dev/spidev*
you should see two 'devices' one for each SPI bus
• http://learn.adafruit.com/raspberry-pi-e-mail-notifier-using-leds ()
• http://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi ()
• http://learn.adafruit.com/matrix-7-segment-led-backpack-with-the-raspberry-pi ()
• https://learn.adafruit.com/adafruits-raspberry-pi-lesson-12-sensing-movement/
overview ()
• https://learn.adafruit.com/adafruits-raspberry-pi-lesson-13-power-control/
hardware ()