Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: 8BitJustice on Jan 24, 2016, 02:17 am

Title: [SOLVED] LED Matrix and Code with a RNG stops working after a few minutes
Post by: 8BitJustice on Jan 24, 2016, 02:17 am
Hello

I'm a novice to Arduino as will be apparent and could really use some insight. I've tried a few projects after many successful tutorial projects and small experiments I wanted to use a max7219 LED matrix that I got and see what it inspired me to make. At first I tried to make a dice roller for the sake of simplicity and it worked quite well...at first. Pick a flash several "Sprite Numbers" on the LED matrix until it slows and stops on one. At first it was activated by a button and after a few presses I just looped it because I just wanted to watch it. After about 5 or so minutes the LED matrix turned off. I reset the Arduino and it worked again, for another amount of time and turned off. Re-uploading caused it to start again, and again it stopped. I tried it with the button input again, and after so many presses, it also eventually stopped displaying.

I went back to looping and added an LED as an output to blink within the loop to see if it was still executing or running my code. It did, but the LED matrix would still turn off. I scrapped the project feeling that I must have made a coding mistake or a wiring mistake.

A few weeks later I tried another project a bit simpler. Sprite face that looked left and right and blinked randomly. New circuit, new code, same problem. The LED matrix just turns itself off. Tried with a battery powering my Arduino and same problem. The LED face code will hopefully posted below. (I haven't used a forum in a long time). I did try at one point a code where it randomly selected one of 6 LED outputs to turn on and never seemed to be an issue. So I assumed it was an issue with the max7219.

I did use a Sprite (library?) to help draw my animations. I thought that might have been the issue so I told it to count up with sprite numbers and looped it over from sprite 1 to sprite 20. Never turned the matrix off.

Thoughts? Questions? I appreciate it.

Code: [Select]
#include <Sprite.h>  // Sprite before Matrix
#include <Matrix.h>

//                  DIN, CLK, LOAD, #chips
Matrix myLeds = Matrix(8, 10, 9, 1);

  int rnd;
  int rndDelay;
  int action;
  int cnt;
void setup() {

  Sprite awake1 = Sprite(8, 8,
  B00000000,
  B00010000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00010000,
  B00000000
  );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake1);

  delay(1000);

  Sprite awake2 = Sprite(8, 8,
  B00000000,
  B00010000,
  B00010000,
  B00000000,
  B00000000,
  B00010000,
  B00010000,
  B00000000
  );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake2);

  delay(1000);
 
  Sprite awake3 = Sprite(8, 8,
  B00000000,
  B00010000,
  B00010000,
  B10000000,
  B10000000,
  B00010000,
  B00010000,
  B00000000
  );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake3);

  delay(1000);

  Sprite awake4 = Sprite(8, 8,
  B00000000,
  B00010000,
  B10010000,
  B10000000,
  B10000000,
  B10010000,
  B00010000,
  B00000000
  );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake4);

  delay(1000);

  Sprite awake5 = Sprite(8, 8,
  B00000000,
  B00010000,
  B10010000,
  B10000000,
  B10000000,
  B10010000,
  B00010000,
  B00000000
  );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake5);

  delay(1000);

  Sprite awake6 = Sprite(8, 8,
  B00000000,
  B00010000,
  B00010001,
  B00000001,
  B00000001,
  B00010001,
  B00010000,
  B00000000
  );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake6);

  delay(1000);

  Sprite awake7 = Sprite(8, 8,
  B00000000,
  B00000000,
  B00011001,
  B00000001,
  B00000001,
  B00011001,
  B00000000,
  B00000000
  );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake7);

  delay(500);

  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake6);

  delay(250);

  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake7);

  delay(500);

  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake6);

  delay(250);
 
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake7);

  Serial.begin(9600);
  randomSeed(analogRead(A0));
  Serial.println("Randomize!");


  //sprite definitions

}

void loop() {
  Sprite neutral = Sprite(8, 8,
  B00000000,
  B00000000,
  B00011001,
  B00000001,
  B00000001,
  B00011001,
  B00000000,
  B00000000
  );
  Sprite lookleft = Sprite(8, 8,
  B00000000,
  B00000000,
  B00000001,
  B00011001,
  B00000001,
  B00000001,
  B00011000,
  B00000000
  );
  Sprite lookright = Sprite(8, 8,
  B00000000,
  B00011000,
  B00000001,
  B00000001,
  B00011001,
  B00000001,
  B00000000,
  B00000000
  );
  Sprite blinkNeutral = Sprite(8, 8,
  B00000000,
  B00010000,
  B00010001,
  B00000001,
  B00000001,
  B00010001,
  B00010000,
  B00000000
  );
 
  //looking loop
  rnd = random(4);
  rndDelay = random(700) + 250;
  rnd++;
  for(int i = 0; i < rnd; i++){
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, neutral);

  delay(rndDelay);

  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, lookleft);

  delay(rndDelay);

  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, lookright);

  delay(rndDelay);
 
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, neutral);

  delay(rndDelay);
}

//blink
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, blinkNeutral);
  delay(500);
}

Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: CrossRoads on Jan 24, 2016, 02:20 am
What Rset are you using with the MAX7219? Anychance it is just overheating?
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: 8BitJustice on Jan 24, 2016, 02:25 am
I used the term "Reset" in a very loosely. Power cycling is what i'm really doing. Is it possible for the matrix to be overheating?
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: CrossRoads on Jan 24, 2016, 02:36 am
Sure, but when LEDs overheat they usually fail and do not recover.
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: 8BitJustice on Jan 24, 2016, 02:49 am
Well, thankfully that is not the case. Though when it first happened I thought that's what surely happened. But a re-upload or power cycle gets it working again.
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: Grumpy_Mike on Jan 24, 2016, 09:52 am
Have you any decoupling capacitors on the 7219? It could be latching up.
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: Paul__B on Jan 24, 2016, 10:36 am
You may have misunderstood.

"Rset" is the resistor that defines the segment driver current on the MAX7219.  It should not be less than 10k, and generally is 10k.
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: 8BitJustice on Jan 31, 2016, 11:58 pm
You may have misunderstood.

"Rset" is the resistor that defines the segment driver current on the MAX7219.  It should not be less than 10k, and generally is 10k.

This is likely a dumb question but, I haven't put in a resistor anywhere on the circuit. With the exception of when I use an input. Should I be putting a 10k in series somewhere?
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: Grumpy_Mike on Feb 01, 2016, 12:01 am
Quote
Should I be putting a 10k in series somewhere?
Yes, between pin 18 and 19 of the MAX7219.
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: Paul__B on Feb 01, 2016, 10:00 am
This is likely a dumb question but, I haven't put in a resistor anywhere on the circuit. With the exception of when I use an input. Should I be putting a 10k in series somewhere?
That's OK. :smiley-lol:

There is a bit of confusion here.

You are actually using one of these (http://www.ebay.com/itm/MAX7219-Dot-led-matrix-module-MCU-control-LED-Display-module-for-Arduino-/400373209766), are you not?
(http://www.ebay.com/itm/MAX7219-Dot-led-matrix-module-MCU-control-LED-Display-module-for-Arduino-/400373209766)


Or possibly one of these (http://www.ebay.com/itm/MAX7219-dot-matrix-module-Arduino-microcontroller-module-control-Display-DIY-KIT-/311419148750) much more useful versions.
(http://www.ebay.com/itm/MAX7219-dot-matrix-module-Arduino-microcontroller-module-control-Display-DIY-KIT-/311419148750)


The 10k resistor Rset - and the decoupling capacitors mentioned - are part of the module, so that is not a problem.
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: 8BitJustice on Feb 07, 2016, 08:15 pm
Yes, the first one is exactly what i'm using! So I need a 10k with this but...i'm not seeing where it is labeled pin 18 or 19. I assume that it's referring to the shift register (I think that's what it's called) and it's pins 18 and 19. A little googling helped me find a wiring diagram with a resister in parallel across there. Again I could use some guidance on this one. I am still figuring a lot of these new parts out.

If that is the case though, I also assumed that it would have come with that resistor included, as in already on the circuit board. Does that mean I need to soldier one in on the back of the circuit board? Or is there a way to get that resistor in the circuit at another point?

Once more, help is greatly appreciated
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: Paul__B on Feb 08, 2016, 02:21 am
Either you got it as a kit, or pre-assembled.

If the latter, you will find the resistor and two capacitors (the electrolytic folded over) under the matrix display.  It will not be a concern, it will be there!

Reviewing the problem, I am going for a problem with the Sprite or Matrix library.

No!  It is a memory leak problem with your loop()!

Let me see ...

I have no idea what library you are using as I cannot make it compile in the IDE, but suggest you try this:
Code: [Select]
#include <Sprite.h>  // Sprite before Matrix
#include <Matrix.h>

//                  DIN, CLK, LOAD, #chips
Matrix myLeds = Matrix(8, 10, 9, 1);

int rnd;
int rndDelay;
int action;
int cnt;
void setup() {

  Sprite awake1 = Sprite(8, 8,
                         B00000000,
                         B00010000,
                         B00000000,
                         B00000000,
                         B00000000,
                         B00000000,
                         B00010000,
                         B00000000
                        );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake1);

  delay(1000);

  Sprite awake2 = Sprite(8, 8,
                         B00000000,
                         B00010000,
                         B00010000,
                         B00000000,
                         B00000000,
                         B00010000,
                         B00010000,
                         B00000000
                        );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake2);

  delay(1000);

  Sprite awake3 = Sprite(8, 8,
                         B00000000,
                         B00010000,
                         B00010000,
                         B10000000,
                         B10000000,
                         B00010000,
                         B00010000,
                         B00000000
                        );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake3);

  delay(1000);

  Sprite awake4 = Sprite(8, 8,
                         B00000000,
                         B00010000,
                         B10010000,
                         B10000000,
                         B10000000,
                         B10010000,
                         B00010000,
                         B00000000
                        );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake4);

  delay(1000);

  Sprite awake5 = Sprite(8, 8,
                         B00000000,
                         B00010000,
                         B10010000,
                         B10000000,
                         B10000000,
                         B10010000,
                         B00010000,
                         B00000000
                        );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake5);

  delay(1000);

  Sprite awake6 = Sprite(8, 8,
                         B00000000,
                         B00010000,
                         B00010001,
                         B00000001,
                         B00000001,
                         B00010001,
                         B00010000,
                         B00000000
                        );
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake6);

  delay(1000);

  Sprite awake7 = Sprite(8, 8,
                         B00000000,
                         B00000000,
                         B00011001,
                         B00000001,
                         B00000001,
                         B00011001,
                         B00000000,
                         B00000000
                        );
  Sprite neutral = Sprite(8, 8,
                          B00000000,
                          B00000000,
                          B00011001,
                          B00000001,
                          B00000001,
                          B00011001,
                          B00000000,
                          B00000000
                         );
  Sprite lookleft = Sprite(8, 8,
                           B00000000,
                           B00000000,
                           B00000001,
                           B00011001,
                           B00000001,
                           B00000001,
                           B00011000,
                           B00000000
                          );
  Sprite lookright = Sprite(8, 8,
                            B00000000,
                            B00011000,
                            B00000001,
                            B00000001,
                            B00011001,
                            B00000001,
                            B00000000,
                            B00000000
                           );
  Sprite blinkNeutral = Sprite(8, 8,
                               B00000000,
                               B00010000,
                               B00010001,
                               B00000001,
                               B00000001,
                               B00010001,
                               B00010000,
                               B00000000
                              );


  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake7);

  delay(500);

  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake6);

  delay(250);

  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake7);

  delay(500);

  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake6);

  delay(250);

  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, awake7);

  Serial.begin(9600);
  randomSeed(analogRead(A0));
  Serial.println("Randomize!");
}

void loop() {
  //looking loop
  rnd = random(4);
  rndDelay = random(700) + 250;
  rnd++;
  for (int i = 0; i < rnd; i++) {
    myLeds.clear();
    myLeds.setBrightness(1);
    myLeds.write(0, 0, neutral);

    delay(rndDelay);

    myLeds.clear();
    myLeds.setBrightness(1);
    myLeds.write(0, 0, lookleft);

    delay(rndDelay);

    myLeds.clear();
    myLeds.setBrightness(1);
    myLeds.write(0, 0, lookright);

    delay(rndDelay);

    myLeds.clear();
    myLeds.setBrightness(1);
    myLeds.write(0, 0, neutral);

    delay(rndDelay);
  }

  //blink
  myLeds.clear();
  myLeds.setBrightness(1);
  myLeds.write(0, 0, blinkNeutral);
  delay(500);
}
}
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: 8BitJustice on Feb 08, 2016, 03:26 am
I feel like memory leak is right on. The symptoms fit. I think the library might also be partial to blame. I did try running the code but it said 'neutral' was not delcared in this scope and highlighted...

Code: [Select]
void loop() {
  //looking loop
  rnd = random(4);
  rndDelay = random(700) + 250;
  rnd++;
  for (int i = 0; i < rnd; i++) {
    myLeds.clear();
    myLeds.setBrightness(1);
    myLeds.write(0, 0, neutral);

The final line of the myLeds.write(0, 0, neutral);
I don't have a good grasp on this library, or apparently proper declarations so that my loops can use the sprite objects. Is there a better library you or someone could suggest? Or even a simpler way to do the sprite drawings on the MAX?
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: Paul__B on Feb 08, 2016, 05:32 am
Can you identify where the library comes from?  It does not appear to be part of the IDE.
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: 8BitJustice on Feb 08, 2016, 05:44 am
Honestly, got it from a link from a youtube tutorial I saw a while back. It's been a while and I forgot where I got it from. Just called sprite. Here's the attachment. Heck I can't event remember is the matrix library was for. Annoying, I know. Like I said though, maybe I need to start fresh with something and try again.
Title: Re: LED Matrix and Code with a RNG stops working after a few minutes
Post by: 8BitJustice on Mar 17, 2016, 04:27 pm
I went back to normal LEDControl.h and started fresh with proper class programming for the "pixel" byte arrays. This resolved the issue. Thanks for pointing out the memory leak.

Mark this one up as solved!