Pi 3 click shield connects the world largest collection of add-on boards – click boards™ with one of the today’s most popular embedded platforms – Raspberry Pi.
Here you can find library examples written in Python, a powerful language recommended even for the programming newcomers.
With Pi 3 click shield you are adding two mikroBUS™ sockets to your Raspberry Pi 3, which means that you can experiment with hundreds of click boards™ from the MikroElektronika’s range.
The Pi 3 click shield is compatible with Raspberry Pi 3 model B, 2 B, 1 A+ and B+.
System preparation and installation of necessary libraries
Before you begin, you should know how to prepare your Raspberry Pi and how to install the necessary libraries.
That’s why we are giving you step-by-step instructions on how to establish communication with click boards™ on Raspberry Pi via I2C, SPI and UART interfaces.
Python is well known as an effective language that allows programmers to use fewer lines of code than it would be possible in languages such as C or Java. In this article, we are going to show you how easy is the usage of the modules. Let’s start with GPIO module.
GPIO
GPIO module usage is pretty easy to understand and to remember.
To show an example for GPIO pins used on the Raspberry Pi we’ve plugged two click boards™, Relay click and Signal Relay click, into the mikroBUS™ sockets which are a part of the Pi 3 click shield.
I2C
I2C tools are necessary when we want to use I2C peripheral on our Raspberry Pi. You can install it by using the following command:
After that, we must enable loading of i2c-bcm2708 and i2c-dev kernel modules at boot time, by editing the contents of the modules file located in etc sub-folder of your system:
Next, you need to add the following lines at the end of the file:
Now you can perform the basic test for finding available slave addresses by executing one of the two commands:
or
After the test, you should see the output similar to this one
Then you need to add the i2c-bcm2708 to the blacklist via the following command:
add
at the end of the file.
By this time, you would also need a specific Python library which should be installed by the following command:
After this, you should be able to use any of I2C peripherals by importing smbus module to your project.
In order to show an example of the I2C protocol on the Raspberry Pi, we’ve used Weather click and Color click, again via the Pi 3 click shield.
SPI
Even easier than I2C, this peripheral requires only an addition of spi-bcm2708 to the blacklist and installation of the specific Python library.
spidev module imports everything needed for the successful SPI communication with the device. Here, unlike with the “bare metal applications”, the Linux kernel controls CS or CE pin.
To demonstrate an example of the SPI protocol used on the Raspberry Pi, we’ve plugged two 8×8 R click boards.™
UART
This is the easiest setup. You just need to install pySerial module.
Pi 3 click shield and one of the most popular click boards™, LoRa click, helped us in demonstrating the UART protocol used on the Raspberry Pi.
Summary
As you can see, establishing communication with click boards™ on Raspberry Pi via I2C, SPI, and UART interfaces is not a difficult task even if you are a beginner.
We’ve made examples with some the most popular click boards™ such as LoRa click and 8×8 R click. All examples can be found on LibStock and GitHub.