Two 3-digit 7-segment displays with MAX7219

Hi all,

I'm playing around with making a digital gauge that shows two different values from two different analog inputs. These are displayed using 7-segment LEDs; one 3-digit and one 2-digit.

I've got the LEDs wired up to a MAX7219 chip, and using a really basic tutorial (http://tok.hakynda.com/article/detail/3/max7219---4-digit-7-segment-display) I was able to get numbers counting upwards on four of the five available digits, so the wiring works. Here's the code:

#include "LedControl.h"
LedControl lc = LedControl(11,13,10,4);

int count = 1000;

void setup()
{
    lc.shutdown(0,false);
    lc.setIntensity(0,5);
    lc.clearDisplay(0);
}

void loop()
{
    String t = String(count++);
    lc.setDigit(0,0,(int)(t[0]-'0'),true);
    lc.setDigit(0,1,(int)(t[1]-'0'),false);
    lc.setDigit(0,2,(int)(t[2]-'0'),false);
    lc.setDigit(0,3,(int)(t[3]-'0'),false);
    delay(100);
    lc.shutdown(0,true);
    lc.shutdown(0,false);
}

My trouble is, how to address each digit individually, so that I can display one vale in the 3-digit LED, and a different value in the 2-digit LED?

The example uses the LedControl.h library, but I don't really understand the nomenclature of instances, devices and addresses. Can anyone give me a nudge in the right direction?

Well a nudge would be to forget about libraries and read the data sheet for the chip. It is quite a simple chip to drive directly and each digit has its own register to write to so individual manipulation of digits is easy.

The datasheet that came with the chip doesn't show anything about how to write code for an Arduino, so maybe you could elaborate on how that's simpler than using a dedicated library? Seems like messing about directly addressing memory registers is many steps more complicated than what I'm asking for right now.

You asked

Can anyone give me a nudge in the right direction?

I nudged.

Seems like messing about directly addressing memory registers is many steps more complicated than what I'm asking for right now.

No it is not. While the data sheet doesn't specifically say Arduino it tells you what address registers do what. It is very very simple to write to a register. Just one I2C write to specify the register followed by the data for that register. What is hard about that.

If you wanted more than a nudge you should say so.

Here’s the page about the led control library. (You could have found that with Google.)

While I agree with Mike that accessing the chip directly without the library is easy, doing that isn’t going to make much difference either way to you in solving your problem. So maybe leave that little adventure until later. But an execrsize worth doing at some point to help dispel the idea that libraries do “magic” that you could not do yourself.

Here’s my suggestion for an easy way to get your two value displayed.

  1. Use sprintf() function to get your two values formatted correctly as you want them into a 5 character string. The sprintf() function is not mentioned in the Arduino language reference, but it is available. Google for it. It is easy to use once you know the format string to use. “%3d%2d” should do it if I remember correctly.
char myString[6];
sprintf(myString, "%3d%2d", x, y);
  1. Use the setChar() function in the led control library to send the 5 characters from your string to the display using a for() loop.
for (byte i=0, i<5, i++) lc.setChar(0, i, myString[i]);