Arduino Uno to Maxim 7219

Thread Starter

allenpitts

Joined Feb 26, 2011
163
Hello AAC forum,

Working on using the Arduino Uno and Maxim 7219
to control three hundred LEDs.

Using the schematics and LEDControl library from
http://playground.arduino.cc/Main/MAX72XXHardware

Hooked up a 7219 to 64 LEDs got anomalous result.

So broke it down to three LEDs as shown in this schematic


This would operate the first LED turing it on and off
but does nothing to the second and third LEDs.

A friend who has some electronics engineering
experience said a different sketch should be used
because
'The built in arduino library doesnt like that chip the one
they provide..the reason it doesnt work is the Uno and the Max have different clock speeds.
I'm sure if you tinker with the library you can find where to divide the clock speed inside it.
The arduino library was written for the previous version of the arduino'

The sketch provided by the friend is copied herewith below as sketch two.
Problem is I have studied it and do not understand it.
For instance, it sort of indidcates that the DataIn, Clock
and Load pins are 11, 12, and 13 on the Arduino but
there is no indication of which is which. (Found the SPI.h
file in the libraries folder to fibgure out the Arduino pins
but it is even more cryptic than the sketch.)

Have studied a dozen different articles on Arduino to Maxim7219. Examples:
http://tronixstuff.com/2013/10/11/tutorial-arduino-max7219-led-display-driver-ic/
http://www.planetarduino.org/?cat=435
http://www.instructables.com/id/16x8-LED-dot-matrix-with-MAX7219-module/
https://www.npmjs.com/package/max7219
http://www.plingboot.com/2017/01/max7219-and-common-anode-displays/
http://www.gammon.com.au/forum/?id=11516

Most of these use the LEDControl library and are on how
to use the 7219 to do scrolling matrices and/or seven segment
displays.

Question: Can anyone provide a simple sketch to turn on and then off
the first three LEDs as shown in the schematic?

Willing to remit $100 to first person able provide a simple,
working sketch.

Thanks.

Allen in Dallas




++++++++++++++++ begin Sketch 1+++++++++++++++++


#include "LedControl.h"

LedControl lc=LedControl(12,11,10,1);

unsigned long delaytime=500;

void setup() {

lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}

void loop() {

lc.setLed(0,0,0,true);
delay(delaytime);
lc.setLed(0,0,2,true);
delay(delaytime);
lc.setLed(0,0,3,true);
delay(delaytime);
lc.setLed(0,0,0,false);
delay(delaytime);
lc.setLed(0,0,2,false);
delay(delaytime);
lc.setLed(0,0,3,false);
delay(delaytime);
}

++++++++++++++++ end Sketch 1+++++++++++++++++

++++++++++++++++ begin Sketch 2+++++++++++++++++
/* program to put message on a MAX7219s.
Set up in No Decode mode.
*/
// ************************************ //
//a_presetup
#include <SPI.h>

// define pins usage
// D11-12-13 SPI interface

byte ss0 = 10;
byte x;
// define variables
// bytes to send to MAX7219s, with some initial data
byte displayArray[] = {
0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa}; //16 bytes

// define 7219 register addresses for setup
byte decode_mode = 0x09; // 0x00 = No decode for digits 7-0
byte intensity_level = 0x0A; // 0x08 = mid level. Range is 0x00 to 0x0F
byte scan_limit = 0x0B; // 0x07 for all columns
byte shutdown_normal = 0x0C; // 0x00 - shutdown, 0x01 = normal
byte display_test = 0x0F; // 0x00 = normal, 0x01 = display test mode all on full

// ************************************ //

// b_setup
void setup(){

pinMode (ss0, OUTPUT);
digitalWrite (ss0, HIGH);

Serial.begin(38400);

// turn on SPI port
SPI.begin();

/* set up MAX7219 registers */

// decode to No decode mode
digitalWrite (ss0, LOW);
SPI.transfer (decode_mode);
SPI.transfer (0x00);
digitalWrite (ss0, HIGH);

Serial.println("No decode mode");

// intensity to mid level
digitalWrite (ss0, LOW);
SPI.transfer (intensity_level);
SPI.transfer (0x0F);
digitalWrite (ss0, HIGH);

Serial.println("Intensity");

// scan limit to all 7 columns
digitalWrite (ss0, LOW);
SPI.transfer (scan_limit);
SPI.transfer (0x07);
digitalWrite (ss0, HIGH);

Serial.println("Scan Limit");


// dispay test On
digitalWrite (ss0, LOW);
SPI.transfer (display_test);
SPI.transfer (0x01);
digitalWrite (ss0, HIGH);
delay(2000);

Serial.println("Display test on");

// dispay test to normal
digitalWrite (ss0, LOW);
SPI.transfer (display_test);
SPI.transfer (0x00);
digitalWrite (ss0, HIGH);
delay(200);

Serial.println("Display test off");

// shutdown to Normal mode
digitalWrite (ss0, LOW);
SPI.transfer (shutdown_normal);
SPI.transfer (0x01);
digitalWrite (ss0, HIGH);

Serial.println("Normal mode");

delay(250);

Serial.println("setup done");

}
// ************************************ //

// c_loop
void loop(){

// ************************************ //
Serial.println("slaveSelect0 low "); // put data in registers 1 to 9. 16 bit transfer - address/data
for (x = 1; x<9; x=x+1){
digitalWrite (ss0, LOW);
SPI.transfer (x);
SPI.transfer(displayArray[x-1]);// array 0 to 7
digitalWrite (ss0, HIGH);
}

delay(1000);

Serial.println("slaveSelect0 high");

for (x = 1; x<9; x=x+1){
digitalWrite (ss0, LOW);
SPI.transfer (x);
SPI.transfer(displayArray[x+7]); // array 8 t0 15
digitalWrite (ss0, HIGH);
}

delay(1000);

} // end loop

++++++++++++++++++end sketch 2++++++++++++++++++++++
 

Raymond Genovese

Joined Mar 5, 2016
1,653
Try this if you would....

Code:
#include "LedControl.h"

LedControl lc=LedControl(12,11,10,1);

unsigned long delaytime=500;

void setup() {

lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}

void loop() {

lc.setLed(0,0,0,true);
delay(delaytime);
lc.setLed(0,1,0,true);
delay(delaytime);
lc.setLed(0,2,0,true);
delay(delaytime);
lc.setLed(0,0,0,false);
delay(delaytime);
lc.setLed(0,1,0,false);
delay(delaytime);
lc.setLed(0,2,0,false);
delay(delaytime);
}
 

ebeowulf17

Joined Aug 12, 2014
3,307
Try this if you would....

Code:
#include "LedControl.h"

LedControl lc=LedControl(12,11,10,1);

unsigned long delaytime=500;

void setup() {

lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}

void loop() {

lc.setLed(0,0,0,true);
delay(delaytime);
lc.setLed(0,1,0,true);
delay(delaytime);
lc.setLed(0,2,0,true);
delay(delaytime);
lc.setLed(0,0,0,false);
delay(delaytime);
lc.setLed(0,1,0,false);
delay(delaytime);
lc.setLed(0,2,0,false);
delay(delaytime);
}
Looks like a winner to me!
 

Thread Starter

allenpitts

Joined Feb 26, 2011
163
Hello Mr. Genovese and the AAC forum,

We are moving in the right direction.
The offer still stands and will be implemented.

Using the excellent sketch that you posted the
first two LEDs, 0.0 and 0.1, are now operating as expected.

But the third LED, 0.2, comes on as soon as the Ardunio
is powered and stays on.

Also the duty time of the first two LEDs can be varied
using the DelayTime variable.

It would seem that my sketch had the third parameter
in the setLed statement as cathode.
In your superior sketch the second parameter is used for the
cathode. (That's why the circuit works for the LED in
both sketches, because in both sketches the first pararmeter
is the same, 0,0,0)

But why is the third LED anomalous? I have checked the
breadboard three times:
the anode is going to Seg DP, (pin 22)
and
the cathode is going to Dig 2, (pin 6)



I believe the image above confirms the third LED hookup
as listed.

Two questions:
1. If the middle (second) parameter of the settLed method
sets the cathode. Is the first parameter the chip or the anode?

2. Why does the third LED come on and stay on?

Thanks.

Allen
 

philba

Joined Aug 17, 2017
959
Try loading a sketch that has nothing to do with the 7221 - like blink or some such. After verifying that it's loaded and working, power cycle your arduino. If led 3 (0.2) lights up, then it's a wiring problem. If not, it's a programming (or 7221 problem).

By the way, the ledcontrol line in the sketch has nothing to do with cathodes. From the arduino playground ledcontrol page.

/*
* Now we create a new LedControl.
* We use pins 12,11 and 10 on the Arduino for the SPI interface
* Pin 12 is connected to the DATA IN-pin of the first MAX7221
* Pin 11 is connected to the CLK-pin of the first MAX7221
* Pin 10 is connected to the LOAD(/CS)-pin of the first MAX7221
* There will only be a single MAX7221 attached to the arduino
*/
LedControl lc1=LedControl(12,11,10,1);
 
Hello Mr. Genovese and the AAC forum,

We are moving in the right direction.
The offer still stands and will be implemented.

Using the excellent sketch that you posted the
first two LEDs, 0.0 and 0.1, are now operating as expected.

But the third LED, 0.2, comes on as soon as the Ardunio
is powered and stays on.

Also the duty time of the first two LEDs can be varied
using the DelayTime variable.

It would seem that my sketch had the third parameter
in the setLed statement as cathode.
In your superior sketch the second parameter is used for the
cathode. (That's why the circuit works for the LED in
both sketches, because in both sketches the first pararmeter
is the same, 0,0,0)

But why is the third LED anomalous? I have checked the
breadboard three times:
the anode is going to Seg DP, (pin 22)
and
the cathode is going to Dig 2, (pin 6)



I believe the image above confirms the third LED hookup
as listed.

Two questions:
1. If the middle (second) parameter of the settLed method
sets the cathode. Is the first parameter the chip or the anode?

2. Why does the third LED come on and stay on?

Thanks.

Allen
I'm glad that I could be of some help. I think you are a man of your word and I appreciate that, but , speaking only for myself, I'm not going to accept any money (and, since the third led did not flash, the sketch would not qualify anyway). If you are happy with the help, maybe, at your discretion, make a donation to the Red Cross.

As I looked into it, the 7219 is suited for common cathode LED displays not common anode displays. The library you are using is assuming that you are using a common cathode display.

The chip, of course is going to source current on one set of pins and sink it on the other. So, yes, you can probably use the 7219 for common anode displays, but the addressing is going to be "flipped".

Using that library with common anode displays is problematic, however. I think that you were initially using a common anode display and the 'flag' for me was when you said that the results were "anomalous" - which I interpreted to mean, some segments came on but it was nutty. That sounded very much like an addressing issue and how the 7219 scans the lines.

I don't know why all three didn't flash, either the chip is damaged, or more likely, I made some kind of error in my thinking (probably the latter).

If you read this thread, you can see a fellow who has written a patch for using the chip with common anode displays and the LEDcontrol library without having to flip all the addressing.

Hope this helps.
 
Top