Product Review: Charlieplexed SparkFun 8×7 LED Array

abccharlieplexedledsanimatedI recently picked up the new SparkFun LED Array – 8×7 to try out some hardcore charlieplexing, and so far it’s been working great.

Quoting Wikipedia, charlieplexing is

“…a technique for driving a multiplexed display in which relatively few I/O pins on a microcontroller are used to drive an array of LEDs. The method uses the tri-state logic capabilities of microcontrollers in order to gain efficiency over traditional multiplexing.”

Charlieplexing itself is a simple idea and can be an extremely efficient way of making an LED grid. However, laying out the wiring of a charlieplexed grid, whether on a breadboard or a PCB, can be complicated and require a bit of thinking. It’s easy to layout a grid with 12 or 20 LEDs, but once you start trying to make grids with 30 or more LEDs, it gets a little crazy.

I love SparkFun’s 8×7 LED Array because it eliminates the need to go through the long process of designing and wiring together the grid. Plus it’s in a neat compact module that can be easily embedded. Out of the box, all I had to do was solder on headers and plug it directly into the digital pins on my Arduino. I didn’t need to wire any external resistors, as they’re already built into the board.100_5200

SparkFun has made an Arduino library for controlling the array that allows you to easily write text and draw shapes and do other interesting things on the grid. However, I wanted to use my array with my Raspberry Pi’s GPIO for the purpose of making an archaic internet-connected game system. I’ve written a single-file class in Python 3 for controlling the array with the Raspberry Pi’s GPIO, called pythonic-charlie, and you can find it here (my first legit GitHub repo! Woot woot!). It’s still under development, and still has bugs that need smoothing, but it allows you to display a list of coordinates, test the grid to verify that it’s wired properly, and display a neat little screensaver. I’m currently working on something that will display text. example-wiring

If you ever wanted to learn how to charlieplex LEDs, SparkFun’s 8×7 LED Array is a really great place to start.



Drum Set with Raspberry Pi – Part 1

This is my prelimnary sketch of the drum kit. It's seriously sloppy.
This is my prelimnary sketch of the drum kit! It’s kind of sloppy.

I like music. I like tapping on things with either my fingers or random objects to get a rhythm stuck in my head out in the world. Since my incessant tapping seems to annoy everyone around me, I’ve decided to make my own fake drum set with the Raspberry Pi! I’ll be able to bang on it as much as I want, and maybe it’ll sound more musical than finger-tapping!

I was inspired to make a drum set after seeing some old large cans after my mom had cleaned up the basement a bit, and I figured they could double as drums. I also figured that I could rig my Pi to play audio whenever each ‘drum’ is hit.

I’ve already made a breadboard prototype with all the components, and I have written software in Python 3 that will likely drive the finished project. Since the software is mostly done, now I’m mainly concerned with building the physical project.

This is the prototype breadboard circuit for the drum set. Each button and LED corresponds with a drum.
This is the prototype breadboard circuit for the drum set. Each button and LED corresponds with a drum.

Here’s some details and components about my drum set:

  • Raspberry Pi: Since this project doesn’t require much processing power and I need at least 20 GPIO, I’m most likely going to use my B+ unless I can obtain a Pi Zero soon.
  • Four RGB LEDs: These will be placed inside each drum and will be constantly lit when the kit is in use, and will change color every time the drum is hit. The RGBs hog up the GPIO pins (12 total) and I could just use two single color LEDs in each drum to reduce the total GPIO pins used down to an amount where I could use the Model B Raspberry Pi as opposed to the B+.
  • The “Drums”: AKA the peanut canisters, will be lined up in a row and wired to four digital inputs.
These are the four cans I found, with a Raspberry Pi to scale.
These are the four cans I found, with a Raspberry Pi to scale.
  • Drumsticks: These will probably be makeshift dowels with a padded metallic tip wired up the shaft of the drumstick and connected to ground. Every time the drumstick touches the top of the drum, the pull-up resistor will connect to ground and therefore read low. That’s the simplest way I can think of to sensor read when the drum is tapped, although the idea of each drumstick being physically wired to the unit is cumbersome. I could use some sort of capacitive sensing, but I’m not sure how to do that digitally or easily with the Pi and I would need to do some research and experimentation. It would also be kind of neat to make the drums sensitive to hand-taps.
  • Speakers: The Pi will be wired to one or two speakers via the audio jack that will play a drum sound effect every time the drum is hit. I have a of couple options with the physical speaker: I can make homemade speakers to embed in the drums, attach an old external speaker, or just leave the Pi’s audio output jack accessible from the outside so that the audio output can be decided at the user’s discretion, whether it be headphones or speakers. However, each option has disadvantages; homemade speakers are cheap, simple, and embed-able, but have an extremely low volume level certainly unsuitable for hard core drumming. Standard external speakers, while nice and loud, are either clunky or require external battery power, which makes them hard to embed. Finally, leaving the audio jack open to the user might reduce the drum set’s portability.
  • Audio: The drum sounds effects themselves are actually .wav sound files played by the software. I decided to use the sample drum effects files used in Sonic Pi since there is a good variety. Because every Pi running Raspbian has Sonic Pi installed, the software will transport across any image of Raspbian, forgoing the need to download any .wav or .mp3 files along the code. I might in the future compile my own set of drum sound effects, but for now Sonic Pi provides plenty of variety.
  • Volume Buttons: The drum kit will have two buttons to control volume up and down.
  • Software: I wrote code in Python 3 using the RasPi.GPIO module.
  • ‘Soundschemes’ and ‘Colorschemes’: Since I’m using RGB LEDs and an audio mixer, there are an infinite amount of colors and sounds that can be produced. I’m adding a button to the drum kit that changes the ‘soundscheme’ or the drum tones that are played. Each soundscheme contains four related drum tones. For now, I just picked random Sonic Pi .wav files to make three mock soundschemes. I also added ‘colorschemes’ where a button can change the LED colors of each drum. This function might be removed in the future.

It might be a few weeks before I finish this. Stay tuned for part 2!

The Python RasPi GPIO Module Remade –

Any maker who uses the Raspberry Pi will almost certainly be familiar with the Python GPIO module (dubbed RPi.GPIO in code), which is used to program the general purpose input output pins  (GPIO) on the Raspberry Pi. Using this module, I’ve implemented my own mini Python module called iopi (for input output pi)  to allow for easier and faster pin control especially from within IDLE. 100_4228Basically, I’ve condensed the standard GPIO functions like GPIO.setup() and GPIO.output() and added additional callable data.  Since I hate having to look up the GPIO pin number of a pin like CE0, MOSI, or TXD when building electronics, I’ve added data to allow to call the pin’s ‘lettered’ name without having to look up its number.

My module iopi is geared to more efficient use of IDLE, and not toward writing permanent programs. The module uses only the broadcom pin numberings (GPIO.BCM) and warnings are set to False by default (GPIO.setwarnings(False)), and you can’t change them. But by not having to type them when you open an IDLE session, you can turn pins on and off much faster.

***Note that this is my first attempt at writing modules of any kind. Right now, the module won’t give an error if you pass the wrong type of argument to a function like setup().  In other words, IDLE won’t throw an error if you try to turn on a pin named ‘hello.’ Also note that currently iopi works only with Python 3.***

This is only version 0.0. I’ll be working on adding more functions and data, as well as polishing up the existing functions. Look at the code here. All the functions are listed.

If you want to install this module on your Raspberry  Pi to try it out,  there’s some steps you’ll have to take.

  1. Get the code from GitHub by clicking here. Using a USB thumb drive, transfer it to your Raspberry Pi.
  2. When Python imports a module (such as time, random, or RPi.GPIO) it searches for the module contents in a few specific places on the file system. In order to be able to import as a module, you have to place your code in one of those specific places so that IDLE will find it when you enter import iopi.
  3. In IDLE, you can find out the locations that Python searches by importing the sys module with import sys, then typing sys.path, which spits out the absolute paths of the places where modules can be found.
  4. Now you need to put the file in one those directories so that it can be used as a module.
  5. Either by opening the File Manager on the desktop or by using the terminal, navigate to the directory /usr/lib/python3/dist-packages. This specific ‘dist-packages’ directory is ideal for placing the iopi module because it’s where all the Raspberry Pi specific modules are located, like (RPi.GPIO, mcpi, and Picamera).
  6. From there, copy the file to that directory either by drag-n-drop or with the mv command in the terminal.
  7. The module should be good to go! To test it, type ‘sudo python3‘ at the terminal and then type ‘import iopi‘ and try some functions.