Expansion Shield for RaspberryPi compatible with Arduino. Part 2 - Use the Shield on RaspberryPi


Boris Landoni, open-electronics.org

Part 1 - Schematic

To proceed in subsequent operations, use RaspberryPi in terminal mode, the two SSH and SCP windows open and root login. Connect the RPY connector of the shield to the GPIO RaspberryPi connector and give voltage.

Now we shall activate the I2C and SPI management modules (drivers in the Windows world) or just one of the two, depending on your needs. The I2C and SPI management modules are compiled into the Raspian kernel as external. To make use of one or both of the management modules you need to remove them from the blacklist and then “add” them to the set of modules known to the kernel.

Now open the configuration file that contains the list of blacklisted modules (obscured), with the command:

nano /etc/modprobe.d/raspi-blacklist.conf

Nano ia a minimalist text editor that runs on the terminal. Erase I2C and SPI modules from the blacklist by deleting the lines or, as we preferred, just commenting with a “#.” Press Ctrl-X and then Y to save the file after the changes.

Now we must make sure that the two modules are loaded and become an integral part of the kernel. To do this, we have two possibilities. The first allows us to load the modules on a command basis, and it is valid for the entire time the RaspberryPi stays on. At the next boot the modules need to be reloaded by a given command. The second way allows you to load the modules directly to the operating system boot and make them available immediately to applications after booting, which is essential if the server system runs unattended.

The first option requires the use of the modprobe command. Just use:

modprobe i2c-dev

We can check the success of the driver activation with the command that displays the list of all installed modules lsmod. As in Linux everything (or almost everything) is a file, let’s go in the /dev folder and see the connection files appear for the i2c-0 and i2c-1 devices. To unload the drivers just use:

modprobe -r i2c-dev

If you want the modules to be loaded at boot you need to modify the configuration file /etc/modules, which contains the list of drivers to load at boot time. To edit the file we can use the command:

nano /etc/modules

and add a new line to the configuration file that contains


Press CTRL+X and then Y to save changes to the file and exit.

Now let’s install the i2c-tools package that provides us with functions you can use with command line to verify the operation of the I2C bus:

apt-get install i2c-tools

and add pi user to the i2c group:

adduser pi i2c

Then perform RaspberryPi reboot to activate the new configuration with the command reboot.

After RaspberryPi has rebooted and you have reconnected with Putty or Kitty check whether the I2C bus is visible to the ADC with the command

i2cdetect -y 0 - per RaspberryPi rev.1
i2cdetect -y 1 - per RaspberryPi rev.2

You should get a result that is similar to that shown in figure where the 0x68 address identifies the ADC.

Use this command:

i2cget –y 0 0x68 0x88 w - per RaspberryPi rev.1
i2cget –y 1 0x68 0x88 w - per RaspberryPi rev.2

to read the hexadecimal value of the two bytes returned from channel 1 of the ADC.

The second parameter indicates the I2C bus to be interrogated while the third is the register that contains the address of the device to read (0x68). The fourth is the register which indicates the inpit from which we wish to know the digital readout and the sampling procedure, the last parameter, w, indicates that we want both the bytes of the measure.


You may have to register before you can post comments and get full access to forum.