Go Down

Topic: MAX7219 controlling 2 7-segment display ! help ! (Read 4162 times) previous topic - next topic

firashelou

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:

Code: [Select]

//We always have to include the library
#include <LedControl.h>

/*
 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();

}
Aiming for the unreachable !

my social website and news aggregator https://www.asserter.net

CrossRoads

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:
Code: [Select]

void loop() {
  writeArduinoOn7Segment();

}
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

firashelou

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

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


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.
Code: [Select]

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 ?
Aiming for the unreachable !

my social website and news aggregator https://www.asserter.net

firashelou

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
Aiming for the unreachable !

my social website and news aggregator https://www.asserter.net

firashelou

#4
Oct 02, 2015, 08:02 pm Last Edit: Oct 02, 2015, 08:33 pm by firashelou
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 :

Code: [Select]

//We always have to include the library
#include <LedControl.h>

/*
 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();

}
Aiming for the unreachable !

my social website and news aggregator https://www.asserter.net

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 ?
Aiming for the unreachable !

my social website and news aggregator https://www.asserter.net

dwightthinker

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

firashelou

#7
Oct 02, 2015, 11:53 pm Last Edit: Oct 02, 2015, 11:53 pm by firashelou
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 :/ ?


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 :/

Aiming for the unreachable !

my social website and news aggregator https://www.asserter.net

dwightthinker

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

Paul__B

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.

firashelou

#10
Oct 03, 2015, 11:46 am Last Edit: Oct 03, 2015, 01:01 pm by firashelou
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.


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 ?
Aiming for the unreachable !

my social website and news aggregator https://www.asserter.net

Paul__B

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!

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.

third:
Is there any example for what you said ?
Sorry, I personally do not have any example to hand.

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.

firashelou

#12
Oct 03, 2015, 03:18 pm Last Edit: Oct 03, 2015, 03:19 pm by firashelou
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 !

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

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 :/
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
Aiming for the unreachable !

my social website and news aggregator https://www.asserter.net

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
synchronize to the display with updated brightness controls.
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

Go Up