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.
After working with some basic 74HC74 and 555 circuits, it was time to get fancy. I replaced one of the button triggers from my 74HC74 circuit with a 555 timer delay.
Then I replaced the other button with a 555 timer delay as well.
What do you think happens if I swap out the 22 μF capacitors for 4.7 μF? Remember the capacitor charge time formula from the 555 post? Multiply the capacitance (farads) by the resistance (ohms) to get the time. I’m still using the same 100 K ohm resistors.
So the delay decreases from 2.2 seconds to 0.47.
There is really no point in the 74HC74 here. You can connect two 555s to each other for a similar result. The video shows a double 555 circuit with 3 different timings, where I swap the capacitors from 22 μF to 4.7 μF and then 1 μF (delay of 0.1 second).
Are there any other circuits I should try with the 74HC74 and/or 555?
I posted about the 74HC74 flip-flop on Saturday. For the same project I’m going to use that IC for, I’ll probably use a 555 timer. It’s often referred to as one of the most useful ICs you can get. I’ve never used the 555 either, so I wired up some simple demos using it. In order to show two common timing uses, I’ve created similar circuits each triggered by the same power source and button.
The circuit on the left shows a delay off timer and the one on the right shows a delay on timer. Notice when power is connected (or the button is used as a reset) that the red LED turns on right away and turns off after a few seconds. Just the opposite, the white LED is off when the timer is reset and turns on after a few seconds.
The length of the delays is determined by the capacitor and resistor used with the 555. I’m using an Adafruit Feather to provide 3.3 volts to the circuits with a 22 μF capacitor and 100 K ohm resistor. Using the capacitor charge time formula to multiply the capacitance (farads) by the resistance (ohms), it’s easy to get the time.
Comes out to 2.2 seconds. To change the time delay all you have to do is use a different capacitor and/or resistor.
Here is a simplified wiring setup because it’s hard to see how everything is connected in the video.
I received some advice to use a 74HC74 flip-flop for a project idea I’ve had. I’ve never used an integrated circuit so I thought a good first step was to put together a very simple demo I could hack around with it. This IC is big enough it actually provides two flip-flops, one on each side as you can see from the pin diagram on the right. Both sides work the same, but are completely independent other than sharing power and ground. I’m only using the first side for this example.
As I press the buttons connected to CLR and PRE, you can see the outputs (Q and not Q) alternate. I’ve set the data (D) and clock (CLK) pins to ground. The truth table for the 74HC74 comes in handy to understand what’s going on.
Here is a simplified wiring setup because it’s hard to see how everything is connected in the video.
Over the past couple of weeks I’ve been busy with home improvements. First my Dad came down for a weekend and we did some odds and ends, but the big project was installing a ceiling fan/light in my bedroom. Previously there wasn’t a light in the room and with it being a pretty large room it was hard to see with just a corner lamp in the room.
Neither my Dad or I are electricians or have any experience, but we got the project done and learned a lot along the way. The original configuration had a switch at the door of the room which controlled the top plug of two outlets. In the end, this switch draws power and is connected to another switch inside my closet (which is right by my bed). So now I can turn the light/fan on when walking in/out the room and also when jumping into bed. All of the plugs on the outlets are always hot now and no longer controlled by a switch. The entire project too a whole day, 4 trips to Home Depot, and who knows how many trips up into the attic. It sure does make the room look nice though.
On Sunday I started tearing down wallpaper in the closet and sink area of my bedroom. The original plan was to do both this are and the bathroom at the same time. After over 5 hours on the first room, I decided to turn them into two separate projects because not having good lighting and a mirror by the sink really sucks! Monday I moved all of my clothes out of the closet (the wallpaper stopped right before the closet area of the room) and took down all of the shelving and clothes hanging bars, then scrubbed any remaining glue from the walls and wiped them down. Last night I sanded and patched up all of the holes and marks on the walls. Hopefully tonight I can sand my patch jobs, wipe down the walls, put on some Kilz where it’s needed, and get the painting done. That would leave Thursday night to put everything back together in the room, move in my clothes, and finally unpack some boxes which hadn’t been done since moving in.
Every project turns out to be much harder and more time consuming than you originally think, but of course I then add on to them as well. I don’t like to do shit half-ass, so I do the extra work. I figure if I’m working on it, might as well do things right the first time and spend the extra time.
Owning a home is really a lot of work, but it feels great to accomplish something and know you are adding value to your home at the same time as you’re making it look great.