Savage///Chats

Software Development => Microcontrollers & Processors => Topic started by: Chris Savage on Aug 07, 2025, 03:48 PM

Title: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 07, 2025, 03:48 PM
So, with regards to checksums, I was thinking that, at work I often test the ROM chips in devices by simply loading up my device programmer and comparing the checksum to the one that is usually on the UV sticker on the IC. In the few cases there's no checksum printed, I often have the correct ROM image on the HD to compare against. Instead of booting an extra PC just to run the programmer to do this, I thought I would build a project; a checksum calculator, if you will, that would simply tell me the checksum to any (E)EPROM / NVRAM plugged into the ZIF socket.

20250728_221008.jpg

Initially, I figured I would use an LCD to display the menu / checksum. A coworker suggested I go retro and use an 8-digit, 7-segment display. I thought this was an awesome idea. So I ordered those displays from Amazon.

6 PCS 8-Digit, 7-Segment MAX7219 Digital Segment Module (https://a.co/d/iZZEB3k) for $10!


Unfortunately, the example code / driver I found doesn't display hex values.  :-\
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 08, 2025, 09:36 AM
If you know of a driver for this display that supports HEX values, please reply. Thanks.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: granz on Aug 08, 2025, 10:11 AM
Quote from: Chris Savage on Aug 08, 2025, 09:36 AMIf you know of a driver for this display that supports HEX values, please reply. Thanks.
I had never heard of this display, and initially thought that maybe your issue was from the device only displaying decimal digits. But, the datasheet (https://www.analog.com/media/en/technical-documentation/data-sheets/max7219-max7221.pdf - second bullet item in the Features list) shows that the LED segments can be individually addressed.

You may end up having to write your own driver (is the sample code so bad that you cannot start with that?) It appears that the thing presents itself as a serially loaded bank of eight registers, with each bit of each byte mapped to one segment of the corresponding digit. So, theoretically it seems that you just write a byte to the device, and see what appears. Write another byte, and (if I'm guessing right) the first character moves over one digit space, and the new one appears where the first one was.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 08, 2025, 01:12 PM
Quote from: granz on Aug 08, 2025, 10:11 AMYou may end up having to write your own driver (is the sample code so bad that you cannot start with that?) It appears that the thing presents itself as a serially loaded bank of eight registers, with each bit of each byte mapped to one segment of the corresponding digit.

I have used the MAX7219 in several projects, more notably the Digital Alarm Clocks (https://savagecircuits.com/digital-alarm-clocks/), and the Binary / Digital Clock (https://savagecircuits.com/binary-digital-clock/), so I am familiar with it. One of the things about the Arduino is that there are so many pre-built libraries. I find that to be both a blessing and a curse.

A blessing in the sense that you don't necessarily have to write your own driver for every piece of hardware. Someone has probably done that. The curse? Well, it took me 3 or 4 drivers to find a good one for the OLED displays I was using and about the same trying to find a good NeoPixel (WS2812) driver.

Quote from: granz on Aug 08, 2025, 10:11 AMSo, theoretically it seems that you just write a byte to the device, and see what appears. Write another byte, and (if I'm guessing right) the first character moves over one digit space, and the new one appears where the first one was.

Close! There are registers that are initialized on startup. One such register is called BCD decode. As the name implies, it decodes data for up to eight bytes into BCD. In the two projects above I am displaying the time, so that register is fully enabled for each digit.

For this application I'm going to have to manually decode, which means mapping out which segment applies to each byte and creating a table of values. This isn't an issue as I've done this for every 14-segement / 16-segment display I've ever used, and for large 7-segment displays, where the data is coming from a shift register through a ULN2803 driver. As a side-note, the MAX7219 is often used for dot-matrix displays, such as this HiLetgo MAX7219 Dot Matrix Module for Arduino (https://a.co/d/6a90KLD). In this case both letters are numbers are pixel-mapped.

I was just seeing if anyone had a good HEX-capable driver before I did take some time to write my own.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: granz on Aug 08, 2025, 01:42 PM
Quote from: Chris Savage on Aug 08, 2025, 01:12 PMOne of the things about the Arduino is that there are so many pre-built libraries. I find that to be both a blessing and a curse.

A blessing in the sense that you don't necessarily have to write your own driver for every piece of hardware. Someone has probably done that. The curse? Well, it took me 3 or 4 drivers to find a good one for the OLED displays I was using and about the same trying to find a good NeoPixel (WS2812) driver.
My biggest concern with the Arduino libraries is the way that they are documented (NOT!!!) Most of the "documentation" for Arduino libraries is "you just add it in, and use it." It is a reflection of modern "teaching" - just copy this, paste here, and now you're a programmer. I once mentioned my "Intro to Microcontrollers" book to a kid who was currently taking microcontrollers classes. When I mentioned that I have the student start with a single LED, then show how, and why, it lit with different commands, and then build from there, he said: "I wish that was how they teach us. All we get it copy this and paste that." When I was going through school, I learned the hows, and whys. When I taught logic gates, I showed the electron flow, and voltage generation within the resistors, diodes and transistors - my students knew (or at least those who passed ;) ) what was going on in the gates.

An example of my troubles is my initial tries at using a 16x04 LCD. The library said to call the commands with parameters, but nothing about what the parameters were, or what they meant. (In my looking just now, it seems that this is fixed, at least in arduino.cc tutorial - https://docs.arduino.cc/learn/electronics/lcd-displays/) But it was very frustrating for me as a beginner. When I first started using libraries (in assembly,) they were thoroughly documented. You called the routine with these variables (registers or memory locations) containing these data, then it would return this data in these variables, and while it was doing its thing, it would specify the use (change/destroy) these registers/memory locations. The documentation would even mention what type of data (byte/string/single-precision/double-precision/float/etc.) was in each location.

None of the Arduino libraries are (were?) documented that well.  Getting into the Arduino was rough.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 08, 2025, 02:23 PM
Quote from: granz on Aug 08, 2025, 01:42 PMNone of the Arduino libraries are (were?) documented that well.  Getting into the Arduino was rough.

You're right. Even when downloading them from Github, I am hard-pressed to find the list of functions that you can call with any given library. Sometimes they have specific examples, but rarely anything that shows all of the calls.

It's funny, in the lowest level languages, like assembly, you learn what it is, what it does, what addressing modes it can be used in, what registers are affected, flags affected, etc. Seems the higher up we go, the less information we get. Good documentation is a lost art (not Art).  ;)
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: granz on Aug 08, 2025, 03:17 PM
Quote from: Chris Savage on Aug 08, 2025, 02:23 PMGood documentation is a lost art (not Art).  ;)
LOL

Years ago, one of my biggest clients had to let me go. When he did, he said that the "how to" documentation that I had written was so good that he didn't need me any more.  ???
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 08, 2025, 06:05 PM
Quote from: granz on Aug 08, 2025, 03:17 PMYears ago, one of my biggest clients had to let me go. When he did, he said that the "how to" documentation that I had written was so good that he didn't need me any more.  ???

I can't handle the arrogant people that say, "Well written code is self-documenting." Tell that to someone who doesn't program or understand that particular language.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: granz on Aug 08, 2025, 07:33 PM
Quote from: Chris Savage on Aug 08, 2025, 06:05 PMI can't handle the arrogant people that say, "Well written code is self-documenting." Tell that to someone who doesn't program or understand that particular language.
Yeah, if you put in about 10-100 times the number of lines of code in comments. I've seen pretty thoroughly documented code (written some myself) but never something that really documents the full operation of the program.

On the other hand, good documentation should include the source code - like they did back in the "good ol days" in the '70s.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 08, 2025, 08:58 PM
Quote from: granz on Aug 08, 2025, 07:33 PMYeah, if you put in about 10-100 times the number of lines of code in comments. I've seen pretty thoroughly documented code (written some myself) but never something that really documents the full operation of the program.

So, just to be clear, I'm referring to people who don't think there should be comments in the individual lines of code. When I was writing code for Parallax, I was excessive with my comments and got many compliments for being so clear on what was happening. But I also remember people who disagreed and thought if the code was well written, it didn't need comments to explain things. That's the part that annoys me.

There are still a few parts of the decompiled Z80 code that I tilt my head at. I'm not sure what I was doing there. Not because I didn't comment it, but because I don't have the source anymore and had to reverse engineer it. LOL

This woman gets into the controversy...
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 08, 2025, 10:34 PM
Okay, @granz, you win! LOL I decided to map the segments, and it's more straight forward than I thought.

7_segment_display_labeled.png

So, this is how the segments on a 7-segment display are arranged and labeled.



7-seg_mapping_01.jpg

So, I wrote the following code, turning BCD Decode OFF and then sending the values in binary so I could observe the correlation of bits to segments.



20250808_220150.jpg

The results were better than expected! As you can see, in the first value I set the LSB to 1, then in each digit rotated that value so that I could map all 8 segments. The LSB is the 'G' segment, while the MSB is the DP. I commented that into the code to make it easy to create characters.

Continued in the next reply...
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 08, 2025, 11:00 PM
...continued from the previous reply.

7-seg_mapping_02.jpg

Armed with the knowledge from my bit / segment testing, I was able to reconstruct all the digits as binary patterns, and cycle between the 0-7 and 8-F using this code.



20250808_225204.jpg
20250808_225207.jpg

This is the result of this test code. So, as you can see, this display IS capable of displaying HEX and of activating the decimal points.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: granz on Aug 09, 2025, 05:33 AM
Quote from: Chris Savage on Aug 08, 2025, 08:58 PMSo, just to be clear, I'm referring to people who don't think there should be comments in the individual lines of code. When I was writing code for Parallax, I was excessive with my comments and got many compliments for being so clear on what was happening. But I also remember people who disagreed and thought if the code was well written, it didn't need comments to explain things. That's the part that annoys me.
Bah, humbug - those people don't know what they do.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: granz on Aug 09, 2025, 05:35 AM
Quote from: Chris Savage on Aug 08, 2025, 11:00 PMThis is the result of this test code. So, as you can see, this display IS capable of displaying HEX and of activating the decimal points.
Congratulations! It is sad that you needed to write the code yourself; those people selling these displays should have been able to document it decently, and include some sample code.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 09, 2025, 09:52 PM
Quote from: granz on Aug 09, 2025, 05:35 AMCongratulations! It is sad that you needed to write the code yourself; those people selling these displays should have been able to document it decently, and include some sample code.

Perhaps, but you inspired me to just code for myself, like I should have done from the start. I still need to create a function that displays the correct values when the values are passed along. Currently it's hard coded in this display demo. So, thanks for pushing me in the right direction. I guess I have gotten complacent with all these libraries and examples being available.

I was thinking about making examples for this display on several platforms, eventually.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: granz on Aug 10, 2025, 05:54 AM
Quote from: Chris Savage on Aug 09, 2025, 09:52 PM
Quote from: granz on Aug 09, 2025, 05:35 AMCongratulations! It is sad that you needed to write the code yourself; those people selling these displays should have been able to document it decently, and include some sample code.

Perhaps, but you inspired me to just code for myself, like I should have done from the start. I still need to create a function that displays the correct values when the values are passed along. Currently it's hard coded in this display demo. So, thanks for pushing me in the right direction. I guess I have gotten complacent with all these libraries and examples being available.

I was thinking about making examples for this display on several platforms, eventually.
If you need a Pi Pico, for C, Python or PicoMite BASIC, let me know.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 10, 2025, 12:38 PM
Quote from: granz on Aug 10, 2025, 05:54 AMIf you need a Pi Pico, for C, Python or PicoMite BASIC, let me know.

I just assumed you'd port my code to those platforms / languages.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: granz on Aug 10, 2025, 02:37 PM
Quote from: Chris Savage on Aug 10, 2025, 12:38 PMI just assumed you'd port my code to those platforms / languages.

I could work on that, but it would have to be after our meetup, next month. I am overwhelmed with all the stuff going on - our picnic yesterday wiped me out so bad that we missed church service today (rare.)

Actually yesterday's picnic was for our oldest son to announce that his wife was pregnant; but they found out the day before that the baby had died. Still working on consoling the two of them.

Now, tomorrow morning we head out to Chicago to visit my dad. Our plans were to continue on west from there to Erie, IL - about 200 miles west of Chi-town. Marilyn's step-mother lived there in the summers, and western TX in winters. Unfortunately, last Monday, Marilyn's half-sister called to let us know that my step-mother-in-law had died that morning. There is to be no memorial, or funeral, service, so no reason to go to Erie. The hotel is already paid, and our son (a travel agent) is still trying to get the money refunded.

So, now we are trying to decide what to do after our visit to my dad. We would love to go see the Ark Encounter (https://arkencounter.com/) a full-sized model of Noah's Ark. We also want to see the Creation Museum (https://creationmuseum.org/), a museum about the creation of the world - both of those are near Cincinatti. Also, with both of us being Air Force veterans, we have long wanted to go see the National Museum of the United States Air Force (https://www.nationalmuseum.af.mil/), at Wright-Patterson Air Force Base, near Dayton.

Then, of course, I am working on our meetup, next month. There is still a lot to get done before the end of September.

Both of us have our birthdays coming up (end of Sept, and mid Oct.) With our anniversary on the 9th of December.

Our youngest son (the one who will be attending our meetup,) will be getting married on the Saturday after our anniversary. Then we have Christmas and New Year's Day, with Thanksgiving thrown in for good measure (we try to have family get-togethers for most major holidays.) Already, we are thoroughly worn out.

So, to make a short story long ::) , I will be willing to help, but it may take a while. ;)
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: granz on Aug 10, 2025, 02:59 PM
Correction: we leave for Chicago on Tuesday - see I'm already messing things up.  :P
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 12, 2025, 01:18 PM
Quote from: granz on Aug 10, 2025, 02:37 PMSo, to make a short story long ::) , I will be willing to help, but it may take a while. ;)

I was being somewhat facetious. I figured I would write code for the BASIC Stamp 2, Propeller 1 and Arduino. Possible some ASM for Atmel. I hoped there would be sufficient information to port to anything else easily.

Essentially, when you're printing decimal digits the code is very easy. But if you're printing anything else, you need a lookup table for the segment data to create the various characters.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: granz on Aug 12, 2025, 10:22 PM
Quote from: Chris Savage on Aug 12, 2025, 01:18 PM
Quote from: granz on Aug 10, 2025, 02:37 PMSo, to make a short story long ::) , I will be willing to help, but it may take a while. ;)

I was being somewhat facetious. I figured I would write code for the BASIC Stamp 2, Propeller 1 and Arduino. Possible some ASM for Atmel. I hoped there would be sufficient information to port to anything else easily.
Yeah, I still would like to write a library routine for that thing, but as mentioned above...
Quote from: Chris Savage on Aug 12, 2025, 01:18 PMEssentially, when you're printing decimal digits the code is very easy. But if you're printing anything else, you need a lookup table for the segment data to create the various characters.
That's about what I figured. Byte magazine had an article about showing alpha characters on 7-segment display (Apr 1979 - https://archive.org/download/byte-magazine-1979-04/1979_04_BYTE_04-04_Low_Level_Programming.pdf (https://archive.org/download/byte-magazine-1979-04/1979_04_BYTE_04-04_Low_Level_Programming.pdf) page 218,) and I figured that this could be used on your display to extend the output.

(https://ia801805.us.archive.org/BookReader/BookReaderImages.php?zip=/24/items/byte-magazine-1979-04/1979_04_BYTE_04-04_Low_Level_Programming_jp2.zip&file=1979_04_BYTE_04-04_Low_Level_Programming_jp2/1979_04_BYTE_04-04_Low_Level_Programming_0221.jp2&id=byte-magazine-1979-04&scale=8&rotate=0)
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 13, 2025, 08:53 AM
Quote from: granz on Aug 12, 2025, 10:22 PMByte magazine had an article about showing alpha characters on 7-segment display (Apr 1979).

I had all but forgotten about that article. I remember there were obvious problematic characters, like "X", "M" and "K". But then, we were the generation that came up with "n00b" and "1337", after all.  ;)
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 17, 2025, 10:27 PM
On a side-note, while looking for other displays using the MAX7219, I picked up some MAX7219 ICs from Amazon, which could mean they're knock-offs.  :-X

(https://m.media-amazon.com/images/I/61eKHkbVBKS._SL1500_.jpg)

These are 5 for $9.99 on Amazon (https://a.co/d/atOIOGz).



(https://m.media-amazon.com/images/I/61GnipYZwWL._AC_SL1500_.jpg)

I also came across this MAX7219 Dot Matrix 8 in 1 Display Module (https://a.co/d/cihL6hS) for $12.99 on Amazon.
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: granz on Aug 18, 2025, 08:10 AM
Nice, but I need to limit my new purchases to only the stuff that I actually need to complete projects that I have already started. (SQUIR, err... NO, MUST NOT GIVE IN!)

We just arrived home from vacation, last night. Today is a day of recovery, then I need to clean up my workroom, and get things organized. I still have not assembled my PicoCalcs (https://savagechats.com/index.php?topic=364.0 (https://savagechats.com/index.php?topic=364.0),) and have many other projects that need to be done. So, clean up a bit, then begin orderly project work. (As if...  :-\ )
Title: Re: 8-Digit, 7-Segment Display for Arduino
Post by: Chris Savage on Aug 18, 2025, 09:52 AM
Quote from: granz on Aug 18, 2025, 08:10 AMNice, but I need to limit my new purchases to only the stuff that I actually need to complete projects that I have already started. :-\ )

Technically, this display is with respect to that goal. There is a game show simulator that I was working on (article is currently in draft mode) where the name placards were paper before. I may actually update them to use text using these displays, which would require a total of four. For names too long to fit the display, I would make them scroll.

But the digit displays are used for the player-side score, so it's the same IC being used (MAX7219).