The initial wiring and cutting of the box took more time than I figured and she started to lose interest until we got around to the top. We did this all on-the-fly, but there are plenty of tutorials (like one on Instructables) you can follow.
I successfully built the second piece to a large project I’m working on. I’ve essentially built my own XL Raspberry Pi HAT (Hardware Attached on Top). Since I’m not following the specs, I shouldn’t really call it a HAT.
I’m not sure how, but once again I correctly connected everything on the first try. Either I’m extremely lucky, my attention to detail is paying off, or a combination of the two. I’m just waiting for some catastrophic failure to happen soon when I solder things the wrong way one of these days. Every one of my solder bridges worked. I did run continuity tests on all of the early bridges, which I’m sure was a big factor to my success.
Any guesses on what this board does? Leave your best guess in the comments. It’ll be at least a month before I share more details because I need to finish the entire project first.
I picked up a 10 pack of these 7 segment red LED displays for less than $5. Since each display requires connecting to a minimum of 8 of the 10 pins (9 if using the decimal point), they aren’t exactly easy to work with. Sure, you can buy these where 2 or 4 displays are already connected in a nice package, controlled with the help of an integrated circuit, but where is the fun in that?
If you need to use more than 1 or 2 displays (at 8-9 pins per display), you’ll quickly run out of pins on your microcontroller or Raspberry Pi. The most common way to work with several of these displays is called multiplexing. It’s a method where you briefly turn on one display, turn it off, turn on the next one, and turn it off. You repeat this through all of your displays and then start over. If you do this fast enough, the human eye thinks all of the displays are on at once. It’s pretty slick!
The advantages of multiplexing are:
Fewer wires/pins needed to drive the displays.
Lower power consumption since the LEDs on only one display are lit.
Let’s get our hands dirty, shall we?
Seven of the pins on one of these displays match up to the 7 segments (labeled a through g), one pin is for the decimal point (DP), and the two remaining pins can be used for the common cathode (cc), though you only need to connect one or the other. Over to the right you can see how all of the pins and LED segments are arranged. Pretty straight forward.
I’m using 6 of these displays in a project, so I needed a lot of wires. It got complex and tangled in a hurry, but amazingly, I connected all the wires without a single mistake on my first try. 🙂 For the most part, I based my circuit design off of this schematic…
The end result is something like the Fritzing screenshot below. With so many wires overlapping, it’s not easy to see what’s really going on here. I suggest grabbing wiring.fzz from my GitHub repo and playing around with it in the Fritzing app.
When I went to write my proof of concept code, I decided to use the Gpiozero Python library to simplify working with the LEDs. The library allowed me to set up a couple of arrays for the LED segments and the 6 digits (displays)…
segment_leds = 
for i in range( len( segment_pins ) ) :
segment_leds.append( LED( segment_pins[i] ) )
digits = 
for i in range( len( digit_pins ) ) :
digits.append( LED( digit_pins[i] ) )
Then I could easily loop through and toggle the LEDs in a display as necessary…
for i in range( len( digits ) ) :
for j in range( 7 ) :
if ( numbers[ digit_values[i] ][j] ) :
To make sure things worked I count up from 999000 and then start back at 000000 after hitting 999999. You can see the full code on GitHub.
Now for some visual proof that I actually got it all working! Here it is running when I keep one digit lit for 5/10,000th of a second before turning it off and lighting the next digit.
You’d never know that only one digit is turned on at a time, would you?
If I change from 0.0005 to 0.05 of a second you can start to see that only one display is on at any point in time.
You may also notice it’s counting up a low slower due to the way this code increments the counter. Don’t worry about that.
When I keep each digit turned on for half of a second you can really see how this works.
An issue I’m running into on a Pi Zero is when the processor gets busy doing other tasks, there is a bit of flicker across the displays. You can see this a couple of seconds in to the first video. I’m guessing the code would perform much better on a Raspberry Pi 3B. For my project it’s not a concern, but I want to mention it in case you follow this for your own project. You may also pick up what looks like random flickering of a single digit here and there but that’s due to video timing; the human eye doesn’t see any of that when it’s in front of you.
If necessary, you can take multiplexing a step further and only light up an individual LED on each display at a time, with a method called charlieplexing. It will use even less power, but due to the speed at which you need to switch from one LED to the next, especially across an array of multiple displays, you lose brightness to the human eye.
So when part 3 of this series turned out to be a bit uneventful, I wasn’t expecting a grand finale with fireworks. I was right about it being more difficult though.
Through numerous failed attempts I was running into trouble isolating the signals between the rows and columns. Everything was getting connected in one big circuit. Then I realized it was a perfect place to use diodes! Each button needed 2 though; one for its connection to the row and one to the column. I have a bunch of 1N4148 signal diodes so I wired everything up.
Although the Fritzing is using a different board than in the implementation pictured above, it’s much easier to follow the wiring…
I’m glad I continued down this path with keypad experimentation. I learned a lot. In the beginning I was wondering why the keypads you can buy these days work the way they do and not how I had wired up the old phone keypad to function. Turns out what ended up being a simple solution for me was due to how the old phone keypad made its connections mechanically inside the device. The keypad solutions I showed in part 3 are much easier to create as I’ve now proven by recreating the circuit above.
I’m still curious if I could wire up the old phone keypad to work with the Arduino Keypad library. I guess if I ever get my hands on another old phone, I’ll have to continue with a part 5 of this series.
In parts 1 and 2, I walked through my journey of repurposing the keypad out of a phone from 1980. I learned that a more modern keypad matrix doesn’t exactly function (behind the scenes) in a way I’d expect. I wanted to understand it better so I set out to recreate a 2×2 keypad (kept it simple to make wiring easier) that would function the same way as something you can buy today. It would be a success if it worked with the Arduino Keypad Library.
From my earlier looks through the code I knew it pulsed power out to a column pin and then read in each row’s key from that column before switching to the next column and repeating the process. I figured that should be enough for me to wire this up and try example programs without going back to look at the library’s code again.
I don’t know why I was thinking this would be more complicated and at least a little more exciting, but it was unbelievably easy. I guess I should be celebrating I understood how it worked. Literally all you do is connect one side of every button in a column to a pin and one side of every button in a row to a pin. No need for connections to power, or ground. No pull up/down resistors.
It immediately worked with the Arduino Keypad library examples, even the MultiKey one. I guess being able to detect multiple key presses at once is where the advantage to this implementation comes in. It worked flawlessly when pressing 2 of the 4 buttons, but when you get to 3/4 there are too many connections to distinguish the keys.
Just to be sure I had it figured out, I added a 3rd column to make it a 2×3 grid and it was just as easy.
I love the beauty of how simple this is. I’ve added Fritzing for both of these to my phone-keypad GitHub repo (2×2 & 2×3). If you check this PDF, in the How it Works section it has a really good explanation and shows the row and column connections exactly like I came up with.
Naturally now I need to do a part 4 and attempt to recreate the keypad implementation I ended up with from the old phone. Due to how it mechanically makes the electrical connections I think it’s going to be a bit more complicated than this was. We shall see…
Go back and read Part 1 if you want to the full story on this little project. I did decide to get rid of the PCB on the old phone keypad. Good thing I’ve been getting a lot of desoldering practice. In order to remove the PCB, I first had to remove the wires I had added to the column and row contact points. That was easy and getting the PCB off was a pretty smooth process as well.
Now that I didn’t have the PCB to carry power and ground around everywhere, I had to solder in my own wires. I also had to solder back in all of my connection points to provide the outputs I’d feed into a microcontroller (I used an Adafruit Feather 32u4 Basic Proto).
Once all of the wires were in place and then connected to my microcontroller I wasn’t getting expected results from a simple little program I wrote to display the values. Took far too long for me to remember I needed to use pull down resistors to prevent floating values. I put 10k Ω resistors in each of the circuits…
Output from the pins couldn’t get any better…
I loaded an example from the Arduino KeyPad library, which gave me very weird behavior. After looking at the underlying code, I realized it wanted the outputs of the keypad to be HIGH when a key was not pressed and LOW when it was. Well, my circuit was doing the opposite, so I had to have to invert everything. I didn’t have any inverter ICs, so I used NPN transistors to create an inverter circuit on each output.
Progress. Now I was able to get the library to correctly recognize some key presses. 95% of the time it seemed to think everything was coming from column 1 (1, 4, 7, *) though. The library comes with a MultiKey example. When I ran that, it was reporting every key on the row as being pressed. WTF?!
For the life of me I could not figure out what caused this. I checked wires, measured voltages, did continuity tests, resoldered connections, changed boards, used different GPIO pins, and countless other things. Nothing made a difference. My own code was working beautifully though. Eventually I gave up on the library. It wasn’t worth the effort and I was out of ideas.
Update: Later on I went back and read the KeyPad library code again because it was bugging me. Turns out these keypads don’t actively read the column pins like they do the row pins. My assumptions about how they worked was very wrong because I hadn’t read far enough into the code before. When checking for key presses, typical keypads iterate through the columns to send a pulse which feeds over in to the rows, which are then read in. How a Key Matrix Works has a pretty good explanation with visuals. If I get my hands on another similar keypad maybe I’ll try to recreate this functionality.
I rewired everything to use the pull down resistors again (video of soldering). A huge benefit of the decision was it drastically simplified my circuitry. This would save me 49 solder points! I probably would have needed to use a half-size perma-proto board instead of the 1/4 size I ended up using.
I decided to put in a piezo buzzer to add sounds. I also used a tiny LED, which I had salvaged from some old computer speakers, to show when power is switched on to the backlight.
I tried a couple of different methods of producing touch tones (DTMF) to match up with each key, but with the microcontroller I’m using and the small piezo buzzer, the sound was terrible. I would need something a little more capable I think.
Here’s a demo video.
Hard to see the OLED screen in the video, but I was only using it to output each key press. Something like this…
I even went out of my comfort zone and did a quick share of this on Adafruit’s Show and Tell. If the video doesn’t start at the right spot you can skip ahead to the 12:42 mark. Going back to watch, my demo kind of sucked since it’s hard to hold something up to the Mac camera and push buttons at the same time.
Update: Continue on to Part 3, where I create a matrix of buttons to act as a keypad.