Working with the GPIO on Raspberry Pi

October 20, 2012 at 2:15 am Leave a comment

All sorts of goodies arrived in the last few days, so I spent some time tonight going through some online tutorials on how to work with the GPIO pins on the Pi, first directly through the linux virtual file system using shell scripts, and then moving on to python’s RPi.GPIO support. The first bit was done along the lines of Ch.8 in the early release of “Getting Started with the Raspberry Pi” (see “Untethered Pi” post for more on that), and that was a quick way to show how to read and write the GPIO pins. Eventually I got around to wiring up an ADC (MCP3008) following the tutorial provided by Adafruit (who sold me the chip and some other parts, and apparently supplied many of the parts in the Maker Shed Raspberry Pi Starter kit that I bought at Maker Faire, woot!).

The MCP3008 is a 10-bit ADC with 8 inputs and an SPI interface. One of the cool things I liked about the Adafruit tutorial is that they implemented an basic SPI control through the GPIO pins rather than using the on-board SPI interface, so you get to see the raw mechanics of how the clock signals are used to “bit bang” the information off the ADC. I cut out the audio-control aspect of the python code and just set it up to poll the ADC and print the value of the input if it changed by more than 5, since I was doing all this over VNC and thus no audio anyway. Their script polled every half second, but I cranked it up to poll every 0.1ms (10kHz) and the CPU was not totally pegged, so thats pretty neat. Of course, it’s not real-time, so when the OS preempts the process for other business, there can be a non-trivial pause. I’m sure it’s also happening at a low-level for tasks like communication over VNC and such. But it is still immensely satisfying to twist the potentiometer hooked to channel 0 and see the values go scrolling by in the terminal window.

According to FedEX tracking, my stepper drivers and motors arrive tomorrow, so that’s going to be tomorrow’s fun!


Entry filed under: Uncategorized.

Untethered Pi New Pi has arrived, now with moar memory!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

Flickr Photos

%d bloggers like this: