repetition problem with a sequence script

Post Reply
jones
Posts: 3
Joined: Mon Jul 20, 2009 6:36 pm

repetition problem with a sequence script

Post by jones » Mon Jul 20, 2009 7:59 pm

Hallo,
yesterday i've built my first bbb including the led matrix.
it wasn't as easy as i thought but i coped it :).
the only problem was that the original pin-allocation
from the matrix wasn't possible to connect to my bbb.
So my current positions are:

Code: Select all

(BBB Pin = Matrix Pin = Script Variable)
4 = LE = latchPin
5 = OE = outputEnable
6 = CLK = clockPin
7 = DI = dataPin 
8  = DO = (none placement in the script)
And here is a little code snippet i found in this forum.
(i hoped that i can modificate the snippet so i can play a
little movie sequence):

Code: Select all

// found on moderndevice.com form. written by paul b.
#include <avr/pgmspace.h>

    int latchPin = 4; //Pin connected to SPI latch
    int clockPin = 6; //Pin connected to SPI clock -
    int outputEnable = 5; //Pin connected to SPI output enable - high equals off
    int dataPin = 7; //Pin connected to SPI clock

    int totalFrames;         
    int frameDelay = 50;   // 10 frames per second
    
    //                      first frame,               second frame,              third frame
    unsigned int show[] = {
      28700,7280,3640,14350,   14392,3808,1904,7196,   7280,1984,992,3640,   3808,992,1984,1904,
      1984,1904,3808,992,   992,3640,7280,1984,   1904,7196,14392,3808,   3640,14350,28700,7280,   
      7196,28679,57358,14392,   14350,57351,57351,28700,   28679,57358,28679,57358,   57351,28700,14350,57351, 


    }; // put some data in here with 8x8 calculator on the 8x8 page

    void setup() {

      //set pins to output because they are addressed in the main loop
      pinMode(latchPin, OUTPUT);
      digitalWrite(latchPin, HIGH);
      pinMode(clockPin, OUTPUT);
      pinMode(dataPin, OUTPUT);
      pinMode(outputEnable, OUTPUT);
      digitalWrite(outputEnable, LOW);
      Serial.begin(9600);
      Serial.println("start");

    // finds total frames divide by 8  because 2 bytes per int, 4 ints per frame
    // sizeof may report bytes instead of ints
      totalFrames =  sizeof(show);  // find message size, counting total ints because
                                    // I'm indexing frames by 4 below (frames+=4)

    }

    void loop(){

      playAnimation();

    }

    void playAnimation(){
      // send the data to the display
      digitalWrite(latchPin, LOW);  //take latchPin LOW for as long as you are sending data
      for (int frames=0; frames<totalFrames; frames+=4){
        for (int i=0; i<4; i++){
          shiftOut(dataPin, clockPin, MSBFIRST, (show[frames + i] >> 8));   // send high byte
          shiftOut(dataPin, clockPin, MSBFIRST, show[frames + i] );         // send low byte
        }
        digitalWrite(latchPin, HIGH);    //return the latch pin HIGH to update LED's
        delay(frameDelay);
      }
    }


    void off(int pause){
      digitalWrite(outputEnable, HIGH);     // turn off enable line, you can also use analogWrite() to dim the display
      // make sure you use a PWM pin though on Arduino, or it won't work
    }
The problem is, at the end of the sequence when the delay is going to begin, it isn't a part where all led's are off but rather a crazy random led blinking phase.
my wish is that i have'nt any pause or delay between the repetitions.
Can you give me a little help

PS: I have uploaded a little video of the whole sequenz with the curios pause at the end. Here is the link.

Thank you
Jones

EDIT:
I have noticed that the "crazy blink phase" segments of sequences from older scripts contains that i've uploaded one or two times before.

2nd EDIT:
I have to correct my last edit. its exactly the last script that i've uploaded before! Does the BBB includes something like a Cache?
If its true, how can i clear it? =)

paul
Site Admin
Posts: 700
Joined: Mon May 12, 2008 4:19 pm

Re: repetition problem with a sequence script

Post by paul » Tue Jul 21, 2009 6:01 pm

I think the problem is

Code: Select all

totalFrames =  sizeof(show);
You're reading past the end of your array I think - thus the "crazy data".

Try this instead and see if it works

Code: Select all

totalFrames =  sizeof(show) / 2 ;         // divide by two to get number of ints (sizeof reports in bytes) 

jones
Posts: 3
Joined: Mon Jul 20, 2009 6:36 pm

Re: repetition problem with a sequence script

Post by jones » Tue Jul 21, 2009 6:21 pm

Thank you Paul.
Very Much. But i guess i got a question again.
Between every Frame all LEDs light up.
Of cours only 1 millisecond and very very slight,
but if you look exactly, you see it.
Can i fix it too?

paul
Site Admin
Posts: 700
Joined: Mon May 12, 2008 4:19 pm

Re: repetition problem with a sequence script

Post by paul » Tue Jul 21, 2009 7:59 pm

jones,
i guess i got a question again.
Between every Frame all LEDs light up.
Of cours only 1 millisecond and very very slight,
but if you look exactly, you see it.
Can i fix it too?
I'm kind of baffled by this one.

Did you try increasing the frame delay and watching for the flash?
In theory the only way all the lights could go on is if you sent four bytes of 1's to the panel. So maybe inspect your data to make sure you don't have a frame out of place.
I guess it's also possible that the computer is resetting from a low power glitch - check / swap the power supply?
But that shouldn't really light all the LED's. It would also execute your setup function again - so you should be able to check this with Arduino serial monitor.

Paul

jones
Posts: 3
Joined: Mon Jul 20, 2009 6:36 pm

Re: repetition problem with a sequence script

Post by jones » Wed Jul 22, 2009 6:59 am

Hey Paul,

its not easy to capture the right moment, but in the picture below (in the buttom left corner), hopefully you can see what i mean. everytime a new frame appears, the whole matrix lights up slightly.

http://www.grabup.com/uploads/b3a0d883b ... a6708a.png

Another problem is: now, when i increase the frame delay, only 5 frames were shown. so its not an infinite loop anymore.

I seriously have to appropriate some basicstuff, i see..

paul
Site Admin
Posts: 700
Joined: Mon May 12, 2008 4:19 pm

Re: repetition problem with a sequence script

Post by paul » Thu Jul 23, 2009 4:43 pm

OK - One theory that's worth investigating is that you are seeing the data flowing through the chip when it updates.
Try this code. After digging through the datasheet of the new chip - I'm still a little confused but convinced it doesn't work the same way as old chips.

The new code just pulses the latch line after writing. I don't have any hardware with the new chips on them to test right now. Let me know the results. I'll try and watch this forum closely for next few days.

I updated this code several times after reading the datasheet so grab the latest version before you start troubleshooting.


Code: Select all

// found on moderndevice.com form. written by paul b.
#include <avr/pgmspace.h>

    int latchPin = 4; //Pin connected to SPI latch
    int clockPin = 6; //Pin connected to SPI clock -
    int outputEnable = 5; //Pin connected to SPI output enable - high equals off
    int dataPin = 7; //Pin connected to SPI clock

    int totalFrames;         
    int frameDelay = 50;   // 10 frames per second
   
    //                      first frame,               second frame,              third frame
    unsigned int show[] = {
      28700,7280,3640,14350,   14392,3808,1904,7196,   7280,1984,992,3640,   3808,992,1984,1904,
      1984,1904,3808,992,   992,3640,7280,1984,   1904,7196,14392,3808,   3640,14350,28700,7280,   
      7196,28679,57358,14392,   14350,57351,57351,28700,   28679,57358,28679,57358,   57351,28700,14350,57351,


    }; // put some data in here with 8x8 calculator on the 8x8 page

    void setup() {

      //set pins to output because they are addressed in the main loop
      pinMode(latchPin, OUTPUT);
      digitalWrite(latchPin, HIGH);
      pinMode(clockPin, OUTPUT);
      pinMode(dataPin, OUTPUT);
      pinMode(outputEnable, OUTPUT);
      digitalWrite(outputEnable, LOW);  // ouputEnable is active low -  LED's are on
      Serial.begin(9600);
      Serial.println("start");

    // finds total frames divide by 8  because 2 bytes per int, 4 ints per frame
    // sizeof may report bytes instead of ints
      totalFrames =  sizeof(show);  // find message size, counting total ints because
                                    // I'm indexing frames by 4 below (frames+=4)

    }

    void loop(){

      playAnimation();

    }

    void playAnimation(){
      // send the data to the display
      for (int frames=0; frames<totalFrames; frames+=4){
        for (int i=0; i<4; i++){
          shiftOut(dataPin, clockPin, MSBFIRST, (show[frames + i] >> 8));   // send high byte
          shiftOut(dataPin, clockPin, MSBFIRST, show[frames + i] );         // send low byte
        }
      digitalWrite(latchPin, LOW);  // pulse the latch line to update LED's
      delayMicroseconds(1);
      digitalWrite(latchPin, HIGH);  
      delayMicroseconds(1);  
      digitalWrite(latchPin, LOW);  // pulse the latch line back low so that it latches won't respond to noise
     delay(frameDelay);
      }
    }


    void off(int pause){
      digitalWrite(outputEnable, HIGH);     // turn off enable line, you can also use analogWrite() to dim the display
      // make sure you use a PWM pin though on Arduino, or it won't work
    }

Another problem is: now, when i increase the frame delay, only 5 frames were shown. so its not an infinite loop anymore.
I can't understand why this would be. Look over your array again to make sure you're still not reading past the end of it. Try putting in some Serial.println statements to see what is going on with your variables.

Paul

Post Reply