MAX7219 controlling 2 7-segment display ! help !

hello guys, i am trying to learn how to use the MAX7219 with the LedControl library so i searched and read about it here on this website and on other and made a the connection for 2 single digits 7-segment display CC of course to the MAX7219, the display number 0 is connected to the DIG 0 on the MAX and the display number 1 is connected to DIG 1 on the MAX and other segment are connected to the proper SEG on the MAX so i am trying to print individual numbers just to experiment but nothing is happening, the displays stays off, but when i remove one of the pins connected to arduino, the displays starts to flicker so i need help please to understand what is going on ?

here is my sketch:

//We always have to include the library
#include 

/*
 Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
 pin 12 is connected to the DataIn 
 pin 11 is connected to the CLK 
 pin 10 is connected to LOAD 
 We have only a single MAX72XX.
 */
LedControl lc=LedControl(12,11,10,1);

void setup() {
  /*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,15);
  /* and clear the display */
  lc.clearDisplay(0);
}


/*
 This method will display the characters for the
 word "Arduino" one after the other on digit 0. 
 */
void writeArduinoOn7Segment() {
  lc.setChar(0,0,'a',false);
  delay(delaytime);
  lc.setDigit(0, 0, 1, false);
} 

/*
  This method will scroll all the hexa-decimal
 numbers and letters on the display. You will need at least
 four 7-Segment digits. otherwise it won't really look that good.
 */


void loop() { 
  writeArduinoOn7Segment();

}

Is there a library call to setup the MAX7219 to only use 2 digits?

Do you have 10K resistor, 0.1uF, 10uF caps connected on the MAX7219 per its datasheet? Is MAX7219 Gnd connected to Arduino Gnd?

What a waste: LedControl lc=LedControl(12,11,10,1); Arduino has great SPI hardware to drive MAX7219 Clock, data, and chip select pins, works great at default 4 MHz speed - yet the library instead bit-bangs the data out to the chip.

Try calling the function less frequently, instead of as frequently as possible:

void loop() { 
  writeArduinoOn7Segment();

}

CrossRoads: Is there a library call to setup the MAX7219 to only use 2 digits?

what do you mean ? i put my codes as it is

CrossRoads: Do you have 10K resistor, 0.1uF, 10uF caps connected on the MAX7219 per its datasheet? Is MAX7219 Gnd connected to Arduino Gnd?

i have a 33K oops i forgot the capacitor ! i just added them and 1 digit the one on the right means 0 is now on and it gives letter A upper case

CrossRoads: What a waste: LedControl lc=LedControl(12,11,10,1); Arduino has great SPI hardware to drive MAX7219 Clock, data, and chip select pins, works great at default 4 MHz speed - yet the library instead bit-bangs the data out to the chip.

what do you mean ? i did not understand :/

[quote author=CrossRoads link=msg=2421072 date=1443807696] Try calling the function less frequently, instead of as frequently as possible: [code] void loop() {   writeArduinoOn7Segment();

}

what should i do here ?

seems now that it is working when i change the character, it changes except for ‘b’ when i put ‘b’ it showed A upper case but upside down

seems it's working now ! i removed the setChar() function and kept setDigit() and i made a count++ from 0 to 9 and when the count reach 9, it will display a letter on the display number 0 on the right looping threw an array containing the characters

but ! what i noticed is that the display addr should be always 0 but the number of digit must change if i wanna change from the first digit to the next going from right to left ! or, they made a mistake on the website and said in the comment number of display instead of number of MAX7219 !

here are the codes :

//We always have to include the library
#include 

/*
 Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
 pin 12 is connected to the DataIn 
 pin 11 is connected to the CLK 
 pin 10 is connected to LOAD 
 We have only a single MAX72XX.
 */
LedControl lc=LedControl(12,11,10,1);

void setup() {
  /*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,15);
  /* and clear the display */
  lc.clearDisplay(0);
  
  Serial.begin(9600);
}


/*
 This method will display the characters for the
 word "Arduino" one after the other on digit 0. 
 */
void writeArduinoOn7Segment() {
  //lc.setChar(0,0,'2',false);
  int i=0;
  static int count = 0;
  char array[9] = {'A','b','c','d','E','F','H','L','P'}; 
  lc.setChar(0,0,array[count],false);
  
  for(i=0; i<10; i++){
    lc.setDigit(0, 1, i, false);
    delay(250);
    if(i == 9){
      count++;
    }
  }
  if(count == 9){
    count = 0;
  }
} 



void loop() { 
  writeArduinoOn7Segment();

}

How to drive a Common Anode display with the MAX7219 ? Paul said it can be done by software so how is that ? or i must use logic gates ?

firashelou: How to drive a Common Anode display with the MAX7219 ? Paul said it can be done by software so how is that ? or i must use logic gates ?

I believe what he had in mind was to use the display selects to drive the segments and the segments to drive the individual displays. Of course, you won't be able to use the character library as it is and you'll only drive 7 displays ( one for each segment, maybe 8 if there is a DP out, I don't have access to the MAXIM pdf right now ). The library you have will not be the easiest to modify to do what you want. As was mentioned, it might be easier to use the SPI library and use the MAXIM data sheet to write your own interface. Dwight

dwightthinker: I believe what he had in mind was to use the display selects to drive the segments and the segments to drive the individual displays.

what do you mean by this :/ ?

dwightthinker: Of course, you won't be able to use the character library as it is and you'll only drive 7 displays ( one for each segment, maybe 8 if there is a DP out, I don't have access to the MAXIM pdf right now ). The library you have will not be the easiest to modify to do what you want. As was mentioned, it might be easier to use the SPI library and use the MAXIM data sheet to write your own interface. Dwight

but how to do this ? how to use the SPI ? in fact the tutorials about the MAX with 7-segment are rare online :/

I mean you only write to one segment at a time the digits run the segments. You do the multiplexing in software. The Maxim data sheet explains how to bypass the character ROM. As for how to use the SPI, look at:

https://www.arduino.cc/en/Reference/SPI

I think it covers it. It also has a pointer to the a software driven signals. Look at the Maxim data sheet. It explains any of the rest. You most likely need to experiment in your software to determine the desired multiplexing rate that doesn't miss or beat with the multiplexing rate of the Maxim chip. Dwight

dwightthinker: You do the multiplexing in software.

What on earth do you mean by that? You meant font generation, didn't you?

Right, the whole question has been muddled. As best can be figured here, the question is how to drive a common anode display with the MAX7219.

There is no problem here. You simply interchange digits and segments so that the common anodes are driven by the "segment" pins and the segment cathodes are driven by the "digit" pins. You clearly have to generate the font yourself, but you need to do that anyway to display other than digits 0 to 9, "H". "E", "L", "P", "-" and blank (and IIRC, in that order). As such, you can drive as always, eight seven segment displays with their decimals. You can actually drive eight common anode 7-segment displays without decimals plus one common cathode display with a decimal!

The multiplexing - as always - is performed by the MAX7219. The display limit of course, must be set to 8, or 7 if you really do not need the decimals, because it is now constraining the number of segments, not the number of digits.

The only reason to require software multiplexing is where you use two or three MAX7221s to drive RGB matrices.

Paul__B: What on earth do you mean by that? You meant font generation, didn't you?

Right, the whole question has been muddled. As best can be figured here, the question is how to drive a common anode display with the MAX7219.

Paul__B: There is no problem here. You simply interchange digits and segments so that the common anodes are driven by the "segment" pins and the segment cathodes are driven by the "digit" pins. You clearly have to generate the font yourself, but you need to do that anyway to display other than digits 0 to 9, "H". "E", "L", "P", "-" and blank (and IIRC, in that order). As such, you can drive as always, eight seven segment displays with their decimals. You can actually drive eight common anode 7-segment displays without decimals plus one common cathode display with a decimal!

The multiplexing - as always - is performed by the MAX7219. The display limit of course, must be set to 8, or 7 if you really do not need the decimals, because it is now constraining the number of segments, not the number of digits.

first question: but isn't the LedControl library made for Seg as Seg and diG as Dig ?

second question : Is it possible to use Logic Gates to perform this instead of changing the software ?

third: Is there any example for what you said ?

four: where do i have to change the characters where do i have to make them i don't get it ?

firashelou: first question: but isn't the LedControl library made for Seg as Seg and diG as Dig?

Honestly do not know, haven't used it!

firashelou: second question : Is it possible to use Logic Gates to perform this instead of changing the software ?

Oh come on!

No.

Why? Well, the logic is inside the chip, you see. That's what we are doing here, using software.

firashelou: third: Is there any example for what you said ?

Sorry, I personally do not have any example to hand.

firashelou: four: where do I have to change the characters where do I have to make them I don't get it ?

If there is not an available library, you have to make an array with the character font, and use the array to translate. For example the character "0" might be B0111110 - every segment from A to F active, not G or DP. This would mimic the built-in character generator but with segments and digits swapped, you actually have to have a temporary array to hold either the data digits to be displayed, or - probably simpler - their corresponding character patterns. You then read corresponding bits of each byte in the array into each register in the MAX7219 so that the first register contains all the bits for segments A, then next all the segments B and so on.

Paul__B:
Honestly do not know, haven’t used it!

then how do you program this chip ?!!
give me an example please online all they use is the LedControl library which here on this website too !

Paul__B:
Oh come on!

No.

Why? Well, the logic is inside the chip, you see. That’s what we are doing here, using software.

but why not ! i mean we know the connection and how they work, it lets the proper DIG opens so instead we can connect the DIG to a logic gate that will give 0 out from 1 in it’s simple

Paul__B:
If there is not an available library, you have to make an array with the character font, and use the array to translate. For example the character “0” might be B0111110 - every segment from A to F active, not G or DP. This would mimic the built-in character generator but with segments and digits swapped, you actually have to have a temporary array to hold either the data digits to be displayed, or - probably simpler - their corresponding character patterns. You then read corresponding bits of each byte in the array into each register in the MAX7219 so that the first register contains all the bits for segments A, then next all the segments B and so on.

i don’t understand :confused:
if you see my codes up top you will notice how it works, same as the LCD library some how
there is no array no nothing, all are in the library all i have to do is know how to use the function provided

Paul, I was wrong about the software multiplex but I think the problem is the uneven brightness. You'd need to know when each digit was driven so that you could rewrite the brightness control to match the number of segments turned on at that time. The digit control is just a pull high if used for segments, it doesn't know how many are driven. One could make a small circuit to sample the first digit out. It could then synchronize to the display with updated brightness controls. Dwight

Firashelou, Here is the data sheet for the display:

https://www.sparkfun.com/datasheets/Components/General/COM-09622-MAX7219-MAX7221.pdf

Here is how you use the SPI:

https://www.arduino.cc/en/Reference/SPI

Read these until you have some understanding of them. Don't ask us to write your code for you. When you have specific questions please come back we will be glad to help you but you need to be asking a specific question. The answers to the questions you've asked are in these two locations. If some part of one of these is not clear, ask us about that part that isn't clear. If you write some code and it doesn't work, you can ask about it. Dwight

dwightthinker: Firashelou, Here is the data sheet for the display:

https://www.sparkfun.com/datasheets/Components/General/COM-09622-MAX7219-MAX7221.pdf

Here is how you use the SPI:

https://www.arduino.cc/en/Reference/SPI

Read these until you have some understanding of them. Don't ask us to write your code for you. When you have specific questions please come back we will be glad to help you but you need to be asking a specific question. The answers to the questions you've asked are in these two locations. If some part of one of these is not clear, ask us about that part that isn't clear. If you write some code and it doesn't work, you can ask about it. Dwight

ok thank you i found some examples for CA display with the MAX7219 so i hope it would work

and by the way what is your opinion for the last time about Paul's method ?

You’d need to know when each digit was driven so that
you could rewrite the brightness control to match the number
of segments turned on at that time.

I can’t see that working as the MAX7219 multiplexes at 800 Hz.
With common cathode, we assume the anodes are driven, and one cathode goes low to turn on one digit.
With a common anode display, it’d be like the same segment of all digits was driven at the same time. So that’d be even harder to control the brightness.

The uneven brightness is more likely from the Scan register in the MAX7219 not being set to match the number of digits selected.
The Max7219 is just a bunch of registers.
To control them via SPI is pretty simple:

digitalWrite (ssPin, LOW);
SPI.transfer(registerAddress); // 00 to 15
SPI,transfer (dataToWrite);
digitalWrite (ssPin, HIGH);

addresses 0x09, 0A, 0B, 0C, 0F are usually written in setup() and then not changed. 0A may be changed in loop() for brightness control.
0x01 to 0x08 are the individual digits. You send the data you want displayed for the 8 segments each register controls.
For common cathode 7-segment display, one register is one digit. You can set the scan limit register to 2 to only have 2 digits being driven.
For common anode 7-segment displays, one register is one segment across the 8 digits. So you can see how writing a font is a little funny, with 1 bit of register 1 thru 8 would make up a digit. You’d need the scan limit register set to 7 or 8 to ensure that all segments were being controlled. Bits 0,1 of each register would only be used for the 2 digits for example.
The font might look like

byte fontArray[] = {
0b11101101, // segment a
0b10011111, // b
0b11111011, // c
0b01101101, // d
0b01000101, // e
0b01110001, // f
0b01111100, // g
0b00000000, // dp
};

with bit 0 = 0, 1 =1, 2 =2 , 3 =3, 4=4, 5=5, 6=6, 7=7. More bytes are needed for 8,9,0 other letters.
1 in a position = segment on.
So you’d set the NoDecode register to NoDecode mode, and send all 8 digits out.

for (byte x=0; x<8; x=x+1){
digitalWrite (ssPin, LOW);
SPI.transfer(registerAddress+1); // result is 1 to 8 for addresses
SPI,transfer (fontArray[dataArray[x]]); // double look up!
digitalWrite (ssPin, HIGH);

The fontArray, dataArray would need a little more thinking. I’m not convinced the mapping I describe above would work, this is my first time looking at it this way.

(freaking forum! messing up my simple code example with color tags. Arrgh!) (alright, all cleaned up now)

firashelou: and by the way what is your opinion for the last time about Paul's method ?

You set the Maxim chip to the direct mode, as would be done for 64 LEDs ( read the Maxim spec ). The only issue you will have is that you'll need to map the segments to the right locations ( some binary logic in your code ). I recommend you first build the bytes into a memory array of 8 bytes. You'll need to put one digits segments in as a specific bit of each byte. Then send the bytes to the display, once build up. To help out, make a map on a page to see what you need 8x8 map. I see now I was incorrect about the intensity. If you draw the map, you'll see what is going on. Each location on the grid is one segment of your LED. By transposing the axis, segments for digits, instead of lighting one LED digit up at a time with the multiplexing, you are doing it sideways across the display. You just can't use the ROM inside the display to convert the number 1 into two segments on one digit of the display. You need to make a table of each segments to light up for each number. You are switching rows for columns to write to the display. As an example, you wanted to write the number 5 in the first digit of you display. Looking at the spec, that is segments A,C,D,F and G. So, translated, that would be, Byte0, D0 =1 // your G Byte1, D0 =1 // F Byte2, D0 =0 // no E Byte3, D0 =1 // D Byte4, D0 =1 // C Byte5, D0 =0 // no B Byte6, D0 =1 // A Byte7, DP?

If you wanted the next digit to show 4, that would be B,C,F and G. or Byte0, D1 =1 // your G Byte1, D1 =1 // F Byte2, D1 =0 // no E Byte3, D1 =0 // D Byte4, D1 =1 // C Byte5, D1 =1 // no B Byte6, D1 =0 // A Byte7, DP?

so the bytes built up for the display would be 0x03,0x03,0x00,0x01,0x03,0x02,0x03 and would display 54 on the first two digits. I hope this makes some sense. Dwight

firashelou: then how do you program this chip ?!!

By writing code to put the data that I want, into the registers in the chip. :roll_eyes:

firashelou: give me an example please online

Sorry, that would take a lot of research! :astonished:

firashelou: all they use is the LedControl library which here on this website too !

Well, not having used it, I can't really help with it. Maybe some day I will, but so far I haven't.

firashelou: but why not ! i mean we know the connection and how they work, it lets the proper DIG opens so instead we can connect the DIG to a logic gate that will give 0 out from 1 in it's simple

No, it isn't. As I explain below, the MAX7219 does a whole lot of work for you. Adding "logic" (level shifting) unless there is no other way (such as when driving 12V displays), defeats the whole purpose.

firashelou: there is no array no nothing, all are in the library all i have to do is know how to use the function provided

You are stuck then! :astonished:

dwightthinker: Paul, I was wrong about the software multiplex but I think the problem is the uneven brightness. You'd need to know when each digit was driven so that you could rewrite the brightness control to match the number of segments turned on at that time. The digit control is just a pull high if used for segments, it doesn't know how many are driven. One could make a small circuit to sample the first digit out. It could then synchronise to the display with updated brightness controls.

Total and complete nonsense!

The whole point of the MAX7219 is that it is an array driver to drive an array of 64 - 8 by 8 LEDs. It does not care what the array looks like, it just drives eight at a time, the same time for each eight, and it controls the current to each of the eight LEDs that it may be driving. All segments - if it is driving an array of segments - get equal attention.

CrossRoads: The uneven brightness is more likely from the Scan register in the MAX7219 not being set to match the number of digits selected.

Equal nonsense. Gah! You didn't manage to remove the colour garbage! I give up quoting any more of your post.

If you are scanning by segment instead of digit, then the scan register is set to the number of segments - either seven or eight if you are actually using decimal points as well. That's it! That's all the scan register has to do with it, and all segments - in all digits - get equal brightness. Of course, if you only have two displays, then you are only ever driving two anodes at any time.

You - and dwightthinker who has added stuff since I wrote this - have the array buffer concept correct.