Pages: [1]   Go Down
Author Topic: 8x8 PWM Matrix, send frames through serial  (Read 1437 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
I just finished getting to work my 8x8 RGB Matrix using 4 Shift registers and the ShiftPWM Library. Everything looks great so far except for the next step of getting image input via serial through the arduino.
Basically i want to send frames from processing via serial. The problem i have is how to sync the signal? I can't use one single byte as "start frame" command since the brightness is controlled from 0 to 255. The first thing that came to my mind was using only 254 brightness levels and reserve the 0xFF for sync...is it a reasonably good idea? how are those things done usually?

Any help appreciated
Cheers!
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Send over 6 bytes every time?
2 start bytes, check that they are 0xAA & 0x55 if added together get 0xFF, if they do then process the next 4 as shift register bytes?
And if not, process the next pair. Something like this:

void setup{
read byte AA
read byte BB}
void loop {
if AA+BB == FF { process next 4, then reset AA, BB}
else {AA = BB
read byte AA} and go back to top
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

do you mean 6 bytes per pixel?
now i have a function inside the arduino to set an individual pixel, so i was preparing to receive the data as bytes a la "RGBRGBRGB....." and to do everything else on the arduino.
Now that i think about it i should rather do all of the transformations outside and send raw shift register data to the arduino to keep the refresh rate as high as possible.

But still, wouldn't it be a problem if i have brightness values like 0xAA, 0x55 ? wouldn't it be interpreted as new frame?
(let's say the 0xAA,0x55 as sync bytes would get dropped somehow and the frame data would contain the same values somewhere in the middle of the frame, then the sync gets messed up, right?
 is your hint based on the assumption that it's unlikely that 2 bytes disappear + my frame contains the pattern?)

Maybe i just didn't get your explanation?
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No I was thinking more 6 bytes per frame
AA55 says start of data
byte1, byte2, byte3, byte4 are the shift register data.
How likely is that 0xAA, 0x55 will occur back to back? I don't know.
Maybe send that 8 times to signal the show is about to start, have the arduino send an Ack back, then start the display.

But if you are sending the data via SPI bus to the shift registers, I would think you'd have a bit of a pause between the shift out and when the next data occurs, give the some time (milliseconds?) to see the display before it changes.

New info: "now i have a function inside the arduino to set an individual pixel, so i was preparing to receive the data as bytes a la "RGBRGBRGB....." and to do everything else on the arduino."

How do you know where that will start?  Same problem.

"Now that i think about it i should rather do all of the transformations outside and send raw shift register data to the arduino to keep the refresh rate as high as possible."
Really big 8x8x8 cubes I think do the same thing - poor little arduino gonna be busy jamming stuff out to the shift registers.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh ok, now i see where you're coming from...but as i said, i'm using the ShiftPWM library to do all pwm work for me, which is really one of the fastest ways to accomplish it, as i reckon.
It gets the number of my output port (in this case anywhere between 0 and 31 (8 bits x 4 registers)) and a byte value for the pwm brightness.
My job is to pass the serial data as 3 bytes per pixel for color information.(what i meant by "all of the transformations" was the assignment of the a pixel to the right ports for r, g, b and anode, which I will do outside the arduino.)
That means that one frame is composed of a sequence of 8x8x3 = 192 bytes (how big is the serial buffer? 128B ?).
Now it depends on what images i'm sending but i'd say that values of 0xAA,0x55 back to back is not unlikely to occur.

which gives me another idea:
now i am just writing off the top of my head..i could check if the bitmap data contains the desired combination and if it does then slightly "enhance" it so it won't be noticable by the eye.
for example: image contains AA55 -> i change it to AA54 before sending and i could keep the AA55 as placeholder for frame start.
It's not gonna be as much of a difference as lowering the max brightness of all pixels to 254, and it will do the trick!

any comments?
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 437
Posts: 23660
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, now even more info comes out.
Here I just thought  you needed 4 bytes for the 4 shift registers.

What you say sounds like a good plan.  PC has plenty of processing power to scan for AA55 and tweak slightly on occasion if created live, or just tweak as you say if static.

Not sure the eye could see difference between 254/255 on a moving display.

Not sure how big the buffer is, I know its in software and can be adjusted, was discussed in the forum recently.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 45
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, i'm quite new to the electronics game so i'm still learning about getting to the point with my questions.
Anyways thanks for the advice, i will search the forum for the buffer stuff.


well...and here comes a new idea smiley-razz

what if i could set the buffer to exactly 192 bytes? then i could simply pop the whole thing, send an ack back, wait a few ms (during which i hope the buffer fills up again) and proceed with the next frame.
This could spare me the comparing against AA55 on every 2 bytes i read, which would make the display faster i suppose..

"hope" is the word which makes me feel a bit anxious about that solution smiley-razz
Logged

Pages: [1]   Go Up
Jump to: