The problem that I am having with the LedControl library is a peculiar one. I'm using an Arduino Uno, three Max7219's daisy-chained together controlling three 8x8 LED grids, and I am using the LedControl library. Everything works and runs fine. I've got no problems except this:
When I first plug in my LED matrix, my Arduino Uno receives power via the 5V line and my whole system turns on together. When everything first turns on, the number of MaxDevices is set to 3. All the LEDs turn on and function properly except only the LEDs on the first Max are at the proper brightness. The LEDs on the 2nd and 3rd Max's are significantly dimmer.
Now, if I change MaxDevices to 1 and re-flash the Uno with the same program except MaxDevice is set to 1, all the LEDs are restored to full brightness, but the program doesn't work properly because it thinks there is only 1 Max. So, I change the number of MaxDevices to 3, reflash the program, and now everything works as intended and all the LEDs are full brightness. I don't understand what the problem could be.
Here is my code.
#include "LedControl.h"
//Thanks to Eberhard Fahle
// LedControl Pins
int MAX_DATA_IN = 12; // RED
int MAX_CLOCK = 11; // BLUE
int MAX_LOAD = 10; // GREEN
int MaxDevice = 3; // 1, 2, 3
LedControl MaxMatrix (MAX_DATA_IN, MAX_CLOCK, MAX_LOAD, MaxDevice); // Initialize Led Controller library called MaxMatrix
int timer = 200;
void setup(){
// 1. Set MAX Devices
for(byte i=0;i<MaxMatrix.getDeviceCount();i++){
MaxMatrix.shutdown(i, false); // Bring the Max out of Shutdown Mode and into Normal Operation Mode
MaxMatrix.setIntensity(0, 10);
MaxMatrix.clearDisplay(i); // Clear the display
}
MaxTest();
} //---------------------------------------------------- END SETUP
void loop(){
}
void MaxTest(){
for (int i = 0; i < 3; i++){
for (int t = 0; t < 8; t++){
MaxMatrix.setColumn(i, t, 128);
delay(timer);
MaxMatrix.setColumn(i, t, 192);
delay(timer);
MaxMatrix.setColumn(i, t, 224);
delay(timer);
MaxMatrix.setColumn(i, t, 240);
delay(timer);
MaxMatrix.setColumn(i, t, 248);
delay(timer);
MaxMatrix.setColumn(i, t, 252);
delay(timer);
MaxMatrix.setColumn(i, t, 254);
delay(timer);
MaxMatrix.setColumn(i, t, 255);
delay(timer);
}}
for (int i = 0; i < 3; i++){
for (int t = 0; t < 8; t++){
MaxMatrix.setColumn(i,t,0);
}}
for (int i = 0; i < 3; i++){
for (int t = 0; t < 8; t++){
MaxMatrix.setRow(i, t, 128);
delay(timer);
MaxMatrix.setRow(i, t, 192);
delay(timer);
MaxMatrix.setRow(i, t, 224);
delay(timer);
MaxMatrix.setRow(i, t, 240);
delay(timer);
MaxMatrix.setRow(i, t, 248);
delay(timer);
MaxMatrix.setRow(i, t, 252);
delay(timer);
MaxMatrix.setRow(i, t, 254);
delay(timer);
MaxMatrix.setRow(i, t, 255);
delay(timer);
}}
for (int i = 0; i < 3; i++){
for (int t = 0; t < 8; t++){
MaxMatrix.setRow(i, t, 0);
}}}//----------------------------------------------------- END MaxTest
So the process basically goes:
- Turn on system and begin running sketch. (Max Device is set to 3 from previous use)
- LEDs on 2nd and 3rd Max's are dim
- Reflash Arduino with MaxDevices set to 1
- All LEDs at correct brightness but sketch does not work correctly
- Reflash Arduino with MaxDevices set to 3
- All LEDs at correct brightness and sketch works correctly
I'm reluctant to post a schematic because I've spent more time trying to figure out how to draw a Max7219 in Fritzing to show the layout on the breadboard (with no success) than I have actually trying to solve the problem. So here are some pictures.
I have a 5V DC, 6 Amp regulated power supply and I've had all LEDs set to on at the same time no problem so I don't think it is a power supply issue.
I have caps on each chip for noise.
Just the fact that I flash the Arduino and change nothing but the number of Max Devices from 3 to 1 to 3 solves it, makes me think it has something to do with the LedControl library but I don't know.
I'm truly at a loss for this issue and it is driving me crazy.