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.



Tic Tac Toe Arcade Game with Raspberry Pi

tic tac toe arcade game circuit layout
Final layout of my tic tac toe game

In the event of the Raspberry Pi’s 4th (1st) birthday, I’ve been working on a tic tac toe arcade game using the Raspberry Pi’s GPIO with Python. Basically, a human player battles against the computer on a 3×3 LED grid. The player uses a pushbutton 4-way keypad with a ‘select’ button to play. I also added a speaker and coded some neat sound FX!

Below is a demo of the game:


parts to tictactoe arcade game raspberry pi
Parts used for the tic tac toe game

The hardware for this project is pretty basic:

  • Raspberry Pi
  • 9x green LEDs
  • 5x pushbuttons
  • Speaker
  • Trim potentiometer
  • 9x 330Ω resistor
  • 5x 10kΩ resistor
  • Adafruit Pi Cobbler with ribbon cable

    wiring diagram
    Wiring schematic for tic tac toe made with Fritzing

LED Grid Diffuser

In order to make the playing experience more pleasant, I designed a 3×3 grid LED light diffuser and 3D printed it so as to make the light from the LEDs less blinding. It also keeps the LEDs lined up nice and covers some of the wires up too!

Computer AI

This was actually my first experience dealing with any computer AI, and I discovered that it is quite fun! I designed it so it has four logical steps:

  1. First, if there’s any move where the computer will win (i.e. the computer already has two in a row), the computer will play that move.
  2. Second, if the player could win on the next turn, the computer will block it.
  3. Third, if the center of the board hasn’t been played, the computer will play the center.
  4. Finally, if none of the options above are applicable, the computer will play a random move not already played.


For the software, click here. It’s written in Python 3 with the RPi.GPIO library, and it’s actually the longest bit of code that I’ve written as of yet. 🙂

Here’s an extra video with more info about the project:

building the tic tac toe game
Building the final prototype for the tic tac toe game
closeup of tic tac toe circuit raspberry pi
Closeup of LED grid and buttons

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!

Project: XL Seven-Segment Display

seven-segment displayseven-segment display









Here’s the perfect amateur maker project: a self-built giant seven-segment display that will awe all those who watch it in action! You only need a Raspberry Pi and a handful of regular LEDs and resistors, plus a breadboard. You can 3D print a case or you can use a paper template printout of the display. This project is versatile, I’ve provided Python 3 code for the Raspberry Pi, but you could use anything like an Arduino Mega or Beaglebone, you’ll just have to write your own software. Why, you ask, couldn’t I just use a standard 3 cm $0.99 seven-segment display? Because you can’t DIY and it’s not half as cool!

BoM (Bill of Materials):

  • 21 red 5mm LEDs
  • 21 330 ohm resistors
  • Raspberry Pi B+ or Pi 2 with peripherals
  • Adafruit Raspberry Pi Cobbler Plus w/ ribbon cable (not required by HIGHLY recommended)
  • Full-Size breadboard
  • 3D printed seven-segment display case with seven segments OR if you don’t have a 3D printer, this paper printout here (I recommend cardstock or similar for opacity and durability) with a standard paper holepunch
  • Assorted wires and jumper wires
  • Small piezo buzzer (completely optional, just if you want countdown sound effects)
The wiring with the 3D printed segments
The wiring with the 3D printed segments in place
seven segment display wiring
The bare-bones wiring display











  1.  The first step is to properly position the LEDs and their power and ground connections. Start by putting the Adafruit T-Cobbler to the far right side of the breadboard, all the in the last set of holes.
  2. Next, we’ll wire each segment one by one. Refer to the diagram below, just starting with the LEDs and their resistors to ground; in the next step we’ll add the jumpers to the pins. The center three segments require  a bit of maneuvering to get the resistors and jumpers into place. Make sure not to clip the resistor leads too short, and it may be helpful to use some needle-nosed pliers to get the resistors in place without ripping up other LEDs.fritzing diagram
  3. Finishing up the LEDs and their resistors to ground, now we can wire each LED to a pin on the Raspberry Pi. You can either copy the wiring shown here, or you can make up your own wiring. If you do your own pin wiring, make sure you keep careful track of which pin is part of which segment, either on paper in some working code variables.
  4. Optional step: If you want to add a small piezo buzzer for countdown sound effects, now’s the time. Connect it to pin 21 and span it directly to the ground rail. Or, if you did your own pin-numbering connect it to any free pin.
  5. Now for a bit of wire management: make sure all your jumper wires are underneath the LEDs so that they don’t get in the way of the segments and casing.
  6. If you have a 3D printer: Print the casing and seven segments from here. Test fit each hole in each segment with an LED to make sure an LED fits. Put a segment over each set of three LEDs, and fit the casing over all the segments. You’ll have to bend the LED leads a bit so it fits, and the first time you put the casing on will be a bit of challenge.
  7. If you don’t have a 3D printer: Print this seven-segment cutout here. Cut it out on the dotted lines and then holepunch each symbol. Now fit the cutout over the LEDs. Note that it’ll be a bit tough to fit it over the LEDs the first time; you’ll likely have to bend the LED leads quite a bit to get it to display side view
  8. The hardware is all finished! At this point the display should be making you giddy with happiness, but it’ll be even better once it’s got some software! Warm up your Raspberry Pi and open up your favorite text editor to write some Python code!
  9. Check out the code here. It’s got lots of comments that explain how the code works. Make sure if you wired your pins differently, you change the variables to reflect your wiring. When you get the code running you’ll be able to display numbers, do a 9-0 countdown, and do some cool animations!
  10. Troubleshooting: if some of your LEDs aren’t working double check they could be burned out. Replace them and if they still don’t work check your connections to the pins. Finally, check your variable assignments; one error can make the whole display act strangely.
  11. Now you’ve got a working XL seven-segment display, with five GPIO pins to spare! Now you can stare at the mesmerizing numbers all day…

The Origins of This Project Plus Future Developments

I was inspired to make this after seeing some 3D printable large seven-segment displays on Thingiverse. Because my Printrbot Play 3D printer has such a small build dimension, I designed my own, slightly smaller display and got to work with my Raspberry Pi. I made the display small enough that you can simply use a breadboard, which makes it different from other large seven-segment displays.

There is plenty of room in the back of the 3D printed case so that you can make a custom PCB if you like (I won’t attempt that now; I still have to develop my terrible soldering skills!), and there’s screw holes so you can also mount it to something. I’m currently working on a charlieplexing solution to reduce the pins used for the display from 21 down to 6. That way I’ll be able to use an Arduino Uno, add another display (another display would add a whole lot of potential), or add more components.

seven-segment display

My Recommended List of Coding Applications and Cloud Software

There’s a large number of different cloud based coding related websites and apps out there that can help make it easier to write, share, and run your code. Here’s a short list of websites and free software that I would recommend!

Codeshare – Codeshare is a cloud based site that allows you to share your code easily through a link. It’s also neat because it will update every time you change the code, so you can share in real-time without hassle. It’s also fun to change the syntactical highlight color scheme. I use Codeshare to share my Python code!

codeshare img

Enthought Canopy – Canopy is a full-fledged Python IDE that is intended for scientific and data analysis programming, that you install on your computer. I found out about it through MIT’s CS and Programming with Python MOOC that I’m currently taking through EdX. My computer has always had a problem with Python’s IDLE and running programs, but Canopy provides a Python IDE that is not dependent on IDLE. The free version is great for an IDLE substitute, especially when IDLE isn’t working.

canopy img

Codecademy – Codecademy is one of the best ways to learn to code! It’s simple and completely cloud-based, so it’s easy to get started. There’s quite a few languages to pick from, plus it’s good if you need a brush-up on a specific language.

codecademy image – is cloud based terminal editor that allows you to use the shells for a ton of different languages, from Python and Ruby to C++ and PHP. It’s great for function testing, experimenting, and learning on the fly or when you don’t have a language installed on your computer. img

Drive Notepad – If you have a Google account, you can use this simple but useful app to create code files within your Google Drive. It’s just like Microsoft Notepad, but it has syntactical highlights, and it’s in the cloud. I use it to back up code files. Drive Notepad’s only drawback is that you currently can’t share files.

drive notepad img

So these are a few of the apps I use on a regular basis. If you have any other apps or software that you use that I missed here, please feel free to comment about them!

You can probably tell from all the screenshots above that I’m biased toward Python. 🙂

Breadboard Videogame Controller + Pygame Rectangle Animation

controller up closeI was inspired to work on a homemade videogame controller for my Raspberry Pi using a breadboard after taking apart two old video game controllers and seeing another maker’s idea. A breadboard with buttons in the right spot makes a controller that fits quite nicely in your hand.

My design included two four-way keypads on either side of the breadboard plus two extra buttons in the center to serve as maybe ‘start’ or ‘pause’ buttons. I also added two indicator LEDs that can be used for various purposes. Wiring it was a bit difficult, as I had to keep wires out of the way of the buttons. I ended up connecting the button signals (they’re all pull-downs) to the center of the breadboard, and running jumper wires from there to another breadboard, connected to my Raspberry Pi. I tested the controller with a few simple Python programs and verified that it works. The pic below shows the controller next to the Pi breadboard.100_4257

To put it to practical purposes, I made a simple Python program with Pygame that makes abstract art with rectangles. Basically, running the program opens a window where various sized rectangles are placed randomly on the screen every 0.1 seconds. Pressing the keypad buttons changes the rectangle colors, and pressing one of the center buttons saves the image. Unfortunately, Pygame saves images in .tga format, which I am trying to currently convert to .jpg or .png format so I can share the images.

You can see in the image below the whole controller and how it connects to the Pi. You can also see part of my monitor, which has the rectangle animation program open.100_4255

Here’s the code for the controller version on my Pi. There’s comments and more information.

I also made another version of my Abstract Art/Rectangles/Generator/Animation (not sure what to call it) that doesn’t use my controller, just a mouse if you want to test it out on your Pi (Pygame is installed by default in Raspbian).

Now I have to actually make a game for my controller! That will be a challenge. I might program it to control Minecraft on the Pi.


I figured out how to save images in Pygame in .png and .jpg format. In the code, you just have to add the file suffix to the save file name, so that it doesn’t save as the default .tga. I’ve updated the code links above to reflect the change. Here’s an image generated by the mouse version of the rectangle animation. rectangles0

Drawer Open/Close LED Sensor with Raspberry Pi

After discovering how to run the Pi headless without an internet connection, I made a simple sensor to detect if one of my bureau drawers is opened or closed. Basically, an LED turns on if the drawer is closed, and turns off when the drawer is opened.

View the code here. I used a Model B Pi.

I wired the drawer like a pull-up resistor button setup, and made contacts with Meccano Erector set pieces and lots of electrical tape. I added an LED, and then wrote some Python 3 code to run headless on the Pi. The picture below shows the Model B Pi with the LED.

Drawer Log

This picture shows the contacts on the drawer. There’s thin piece of metal on the drawer, and the two contacts are connected to the red and black wires. When the drawer closes, the contacts both touch the metal strip, and the circuit becomes continuous.

side view of drawer wiring

Instructions For Running Headless on the Pi Without Wifi

Running headless mean having your Raspberry Pi run a program without having it hooked up to a monitor, keyboard, or mouse. Basically you just need to edit a certain system file called rc.local.

  1. Login to your Pi. Open up a terminal.
  2. Type cd /etc to change the current working directory (in Linux lingo, cd means ‘change directory’).
  3. To edit the rc.local text file, type sudo nano rc.localNavigate to the end of the file.
  4. Right before the exit0 line, add the line python3 /home/pi/ & where ‘/home/pi/’ is the absolute location of the file you want to run, and the ampersand (&) means that you want to run the program in the background and let the Pi’s boot process continue. Note that you don’t need to add sudo because rc.local runs as root.
  5. The program will now run whenever you power the Pi, regardless if there is any peripherals attached. If you want to test it out, type sudo reboot in the terminal.
  6. Now you can showcase computing projects with your Pi without a monitor!