Using the Lots of Pots Board for Raspberry Pi
Here’s how to use the Lots of Pots Board for the Raspberry Pi. The daughterboard (or shield; what are we calling Raspberry Pi add ons these days?) sits on top of the Raspberry Pi and breaks out the various GPIO pins in a useful and labeled manner. It also has an 8 channel MCP3008 analog to digital converter on board, which is hooked up to the hardware SPI pins on the GPIO header. This tutorial will describe the features of the board and cover how to read analog inputs from the ADC.
Using the Analog Inputs
Note that these instructions assume that you are running a stock Raspbian distribution. Some steps may not apply in other distributions; for example SPI is already enabled in Adafruit’s Occidentalis distro.
In Raspbian, hardware SPI and I2C are disabled by default. To enable it, edit the file:
sudo nano /etc/modprobe.d/raspi-blacklist.conf
This is a configuration file for modprobe, which is the program that loads kernel modules. The blacklist is a list of modules to skip loading on startup. Comment out the line:
#blacklist spi-bcm2708 blacklist i2c-bcm2708
Now call modprobe to load the kernel module that supports SPI (you can load the i2c module as well, since that header is pulled out on the LOP Board as well):
sudo modprobe spi-bcm2708 sudo modprobe i2c-bcm2708
Spidev is a set of Python bindings that allow you to access the SPI port using the spidev kernel driver. The easiest way to install spidev is to use the Pip package manager, which you really should have if you haven’t installed it already. To install Pip, use the following commands (it’s always a good idea to update your package list to minimize problems):
sudo apt-get update sudo apt-get install python-setuptools sudo apt-get install python-pip python-dev
And then install the spidev module:
sudo pip install spidev
That’s all there is to it. Here’s a sample test program that will read all 8 channels from the ADC on the LOP Board:
#!/usr/bin/python # Lots of Pots Board Analog to Digital Converter test # Modern Device # www.moderndevice.com import spidev # import the spidev module import time # import time for the sleep function spi = spidev.SpiDev() # create a new spidev object spi.open(0, 0) # open bus 0, chip enable 0 def readadc(channel): if channel > 7 or channel < 0: return -1 # spi.xfer2 sends three bytes and returns three bytes: # byte 1: the start bit (always 0x01) # byte 2: configure bits, see MCP3008 datasheet table 5-2 # byte 3: don't care r = spi.xfer2([1, 8 + channel << 4, 0]) # Three bytes are returned; the data (0-1023) is in the # lower 3 bits of byte 2, and byte 3 (datasheet figure 6-1) v = ((r & 3) << 8) + r return v; while True: for i in range(8): value = readadc(i) print "%4d" % value, time.sleep(0.2) print;
Now execute the program as superuser; you need root privileges to access the GPIO pins, which kind of makes sense if you think about it:
sudo python testADC.py
I originally created this board to serve as an interface for some work I've been doing with Pure Data. With a couple of friends (Shawn Greenlee and Elliot Clapp), we've made some iOS apps using Pure Data and libPd. The apps are all based on fictional historical synthesizers; we thought it would be fun to make actual hardware versions of them as well. The Lots of Pots Board will make it easy to replicate the DROM synthesizer; more on that to come.