4095 LEDs and everything-everything
Surprisingly , The display of the image on such a display is quite satisfactory controller ATmega328, which underlies Arduino Uno. From this all turned out to be a “pocket” console (weighing several kilos), in which a game is stitched based on Space Invaders. There are plans to come up with something else, since there’s still a lot of free memory left.
Under the cut, you can read about how such a display is arranged and how it can be controlled.
Sometimes, instead of finding old computers in a collection, I do them myself from improvised materials.
This time I wanted to do something compact with the resolution at the level of consoles and computers of the early 80s. True display in 64×64 pixels does not hold out to the Atari 2600, but on the whole 64 pixels more than the display of the Nokia 3310, where the games were also. So it should have been with a margin at least for a comfortable game of Tetris or Pong.
In addition to the display, I obtained a card compatible with Arduino Uno, and began to think, as it were, now with all this good to take off.
Adafruit company sells similar displays and on its website you can find examples of their use. There is also a link to the library for working with them. The library supports Arduino Uno and Arduino Mega.
This library organizes video memory, where it stores pixel colors. The user program recolours these pixels, and the image is displayed in the timer interrupt handler. With small displays, this works well, but in my case this method does not work. Even if you allocate one byte for each pixel (one bit for R, G, B and one extra bit), then for a 64×64 matrix you need 2 kilobytes of memory. And this is all that is with ATmega328P. You can, of course, take a processor more powerful, but this is not the path of the Jedi.
After all, who forces us to store all the lines of the screen at once? You can recalculate each line before output to the screen. For primitive graphics from several sprites, these calculations should not take too much time, so everything should work.
It was in the forest summer computer school, look for documentation on the chips and trace the board to understand what was connected, it was laziness. Therefore, I selected the algorithm for working with the display from the previously downloaded libraries:
- We set the address of the output line
- Fill the array with the colors of the pixels of the sprites that intersect with the current line
- Shuffle all the pixels in turn to the shift register that controls the LEDs
- We click the received data and submit it to the outputs of the registers
As a result, an array of only four lines of the screen is selected for video memory. Why four? All because we simultaneously push the data in two rows – after all, the matrix has two groups of inputs: R1 / G1 / B1 and R2 / G2 / B2. They control two lines, separated by 16 pixels.
But then why not two lines, and four? It turns out that the matrix 64×64 consists of two independent matrices 32×64. It would be possible to connect separate outputs of the processor to each, but ATmega328 does not have enough of them. Fortunately, the caring manufacturer has provided cascading of these matrices – the output of the shift register one can be connected to the input of the other. Then we get the logical matrix 32×128, which is physically displayed as 64×64. That is, in each phase, we need to push two lines of 128 pixels into the registers – and this is 4 lines of the physical screen.
The console prototype we made during the summer computer school. The first game was something remotely reminiscent of Space Invaders.
In reality, LEDs very much burned their eyes. Adjust their brightness using PWM is unlikely to work – the performance ATmega is not enough. It is necessary to take some ARM or FPGA.
I finished the final version in a wooden case. The screen is protected with a sanded plexiglas. Due to the scattering of light, the eyes are not burned out now, but the work of the set-top box is now more difficult to remove – the entire image becomes blurred.
The whole program uses 1101 bytes (53%) of RAM and 6432 (19%) bytes of ROM. There is still room to make a few games and menus for their selection.
Links
- Source code for this project: github.com/Dovgalyuk/BackspaceInvaders
- Description of the work of the matrix on the site adafruit: learn.adafruit.com/32×16-32×32-rgb-led-matrix
- Library from adafruit for matrix management: github.com/adafruit/RGB-matrix-Panel
- Library from adafruit for drawing graphic primitives: github.com/adafruit/Adafruit-GFX-Library
- A similar project on a more powerful processor: learn.adafruit.com/ledgames-beaglebone-black-64×64-led-game/overview
- The article about the management of a smaller display: geektimes.ru/post/275548