Hello, I am using a 32x32 RGB LED Matrix Panel which is connected to an Arduino to output an image of an album cover. This image has 1:1 aspect ratio and has 1024 pixels. I've computed the RGB values for each pixel on the Raspberry Pi. It is stored in an array = [(r0,g0,b0), (r1,g1,b1), (r2,g2,b2),....,(r1023,g1023,b1023].
I would like to send the RGB values of each pixel over to the Arduino so it can output it the image on the panel. On the Arduino side, the code would look like this for one pixel:
where pixel location is 0,0 and the RGB values are 7, 7, 7. How can I feed each pixel's RGB values from the array in the Pi to the code in Arduino? Would a for loop work, and I would need to convert the index of the array to coordinates too. Is this the only way? Thank you.
You want to do this repeatedly? You could pump the whole block, 1024x3 = 3072 bytes, to the Arduino, plus some form of overhead, but you'll be pumping a lot of data from Pi to Arduino. What refresh rate do you want to achieve? If you did this via serial, it would take a few seconds even at 2000000 baud, which is the highest I've heard of anyone using serial for.
If your album cover changes infrequently, I'd say give it a try.
Oh, by the way, I hope it's a Mega, not sure there's enough data available on something like a Uno or Nano to handle this. At a minimum, you'll need 3kB just for one block.
Also, you'll run into serial buffer limitations if you can't suck the data out of the serial buffer fast enough, so you'll need some tight code in the serial receive area to have any hope.
Yes repeatedly, I'm thinking that for each pixel I send in the RGB values and this would repeat for every pixel. as of right now the time it takes to output the image doesn't matter and it is only outputting one image, so a few seconds isn't bad. i am doing it over serial, if i push it all out in one line like you suggested, how would the code look on the arduino side? something like
b = Serial.read(); // 3072 values
for (int j=0; j<32, j++){
for (int i = 0; i<32, i++){
matrix.drawPixel(i, j, matrix.Color333(// ?
delay(200);
but how would i iterate through the string? and yes, it's a mega
Yes, sort of, but under the hood on this line is an assumption. You can send 3072 bytes, but serial is a primitive and awkward 'protocol'. How do you know start from end from in-between? You can't just start counting bytes and stop at the right count, because sometimes "stuff happens", and then you'll get out of sync.
How I'd do it is probably by brute force, with one char value for start, one for end. If, as I'm transmitting my data I find either my begin or end flag values, I repeat it, so that the receiver knows if there are two in a row, it's data not flag, and strips one out and keeps going. If I get to the end, and I don't get the end flag at the right point (too many or too few characters), throw away the buffer and start watching for the start flag again.
Since ASCII has both Start and End transmission character values assigned, just use those (0x02, 0x03).
Primitive, and there are probably many better ways to skin the cat. But it would work.
If you want to try that but fail, c'mon back to the forum with a plausible best try.