MikroElektronika Learn

Click Boards

Matrix RGB Panels

1 Jul , 2016  

Today, let’s talk about LED Matrices with MikroElektronikas’ MatrixRGB Click. The Click is designed to take the load off of the host MCU and make driving a matrices with ease. Whether it be a single pixel with a color, text displayed at any point on the screen, or an RGB 565 formatted bitmap, it is all made simple with our library.

 

How The Panels Work

Panels are connected to the click with 16 wires. To better explain how each wire works, here is a picture of the connection…
rgb-matrix-2016-02

Panels are driven by shift registers. There are 9 shift registers for driving LED colors and row selections effectively, along with 3 pins to latch, clock and enable leds. There are 2 for each color, 3 for row selection( A, B, C ), clock pin ( CLK ), latch pin ( STB ), and a OE / enable pin. Top row color shift registers are labeled R1, G1 and B1, while bottom row color registers are labeled R2, G2 and B2. Row selection registers are used to make re-writes appear more fluent. While your row selection is set to row 0, row 8 will also be updated. Shifting data onto R1, B1 and G1, will update row 0 data, and R2, B2, and G2 will update row 8. Here is a peak at refresh() used in our library…

First, we must reset the row to 0. Our loop is set to loop 8 times, completely taking care of all 16 possible rows of data. Before loading Led_Matrix_Data with R1, R2, G1, G2, B1 and B2 data,  Latch pin must be set to 0 or deasserted. The inner loop is set to increment until it reaches shift_reg, which is dependent on how many panels the library is initialized with. If it is initialized with a width of 2 panels and a height of 1 panel, then shift reg = ( width  * height ) * 64 for 32×32 panels and shift reg = ( width * height ) * 32 for 16×32 panels, because a single shift register for a panel is 64 or 32 bytes for one entire panel. ( We will go into more on how multiple panels work later ). Next, data from the frame buffer with a format of 0b00000RGB is placed onto Led_Matrix_Data and our clock is then toggled which shifts this data onto the display( if 565 bitmap is being used, format will be parsed and put together again into 0b00000RGB format). After a pair of rows is finished ( row ? and row ? + 8 ), Latch pin is asserted, and row is incremented.

Multiple Panels

A single panel is really cool and easy to run, but so is multiple panels! To run multiple panels, all that has to happen is proper initialization, and connecting multiple panels together in a correct order.

9L1A5553

Initialization is very simple and only takes 3 arguments, width, height and panel size. Width and height are not pixels, they are how many 32×32 or 16×32 panels in width and height that are connected. Panel size can be either “BIG_PANEL” which means 32×32 panel, or “SMALL_PANEL” which means 16×32 panel. Pretty simple! Lastly, connecting must be done correctly for the library to know what you mean when writing a pixel or drawing to “( 0, 0 )”.

How To Connect Panels

To connect multiple panels together, always connect starting from the bottom right-most corner to the top-left most corner. If your display only has 1 panel in height you can simply align the panels right to left with the right-most panel connected to the click. Otherwise, your connections should go from panel 1 to 2, 2 to 3, and 3 to 4. This way, when you initialize your display for a width and height of 2 panels, the coordinates you send will be positioned correctly on your display.

panel_connection_32_x_32

For 16×32 panels you will need to connect two 16×32 panels together from bottom to top, and follow the pattern as stated above. For example, using 16×32 panels with a width of 2 and a height of 2 would be connected like so…

panel_connection_small_png_seethrough_small_final

Also note that when connecting to the Matrix RGB Click, red wire on the strip must be on the same side as the arrow that is on the click.

rgb-matrix-2016-07

Power

To power panels, you must use a 5v power supply, with 3 amps per panel that you plan to use for your display. This is an example of a power supply used for 1 RGB 32×32 panel or 2 16×32 panels.

power-supply-unit-sys-5v-3a-thumb

 

How To Use Matrix RGB Library

MatrixRGB Click library allows you to write text to any starting coordinate on your display, manually refresh and clear your display, write to individual pixels, load RGB 565 formatted bitmaps, and much more. The library can be found on Libstock or Github at this link…

Here is a small example on ARM of how to use the Matrix RGB to drive one 32×32 panel, and play a little bit of our version of “Breakout”.

Setup

First, lets start out with an easy setup…

Main

This setup function sets up GPIOs for chip select, reset, and ready pin. Ready pin is used by firmware on the FT900 to tell our host MCU when it is ready for data transmission. Next, SPI communication is setup for MikroBus 1 on the EasyMxPro V7. After initializing host MCU side peripherals, the Matrix is reset using MATRIXRGB_RST pin, and then initialized with a width, height and panel size where BIG_PANEL means 32×32, and SMALL_PANEL means 16×32 with matrixrgb_init(). Let’s take a look at some functions…

Here, a display is set up for a width of 1 and a height of 1 using 32×32 panels. About 200 ms after setup, the Matrix is ready for use.

The first function, matrixrgb_scroll_img_right() takes a bitmap, width in pixels, height in pixels, and speed at which an image should be scrolled right across a display.  After the scrolling text animation, matrixrgb_scroll_off_scrn_down() is used to scroll an entire frame buffer off of the display at a speed given. Provided is a struct called color_t that is used to send any color you want things to be. First we make a color_t called my_color, so that later on we can use matrixrgb_set_color() to set any color we want, and use it in other functions. Finally, we call matrixrgb_scroll_text_left(). To use matrixrgb_scroll_text_left() we send text we’d like to display, along with a color, speed and length of a string you’d like to display.

Note: During scrolling the display is refreshed by the click itself, otherwise the host must use matrixrgb_refresh(). 

MCU To Click Communication

One function not mentioned in this example is matrixrgb_write_text(). Let’s look at how it is implemented and get a peak at how firmware works…

This function first sends the command through SPI to the FT900 SPI slave to alert the firmware to get ready for a text size, color, start row, start column, and then finally data. It does this by filling a buffer with data it would like to send and waiting for the ready pin to be held high and then sending data. Next, Matrix RGB firmware gets the first command byte, and enters its’ own “write_text” function to receive data in the same order it was sent, and then performing an action based on data received.

Note: Start row and start column of text is the top left corner of the first letter in the string.

Draw A Picture

Using a combination of Windows Paint and our Visual TFT program, you can create pictures to be displayed! First let’s start with Paint, and how to make sure your environment is set up for drawing correctly. First, find out a width and height in pixels of the image you’d like to draw. Here is a screenshot of a paint environment set up to draw a 32×32 bitmap…

paint_size

Canvas size has been changed to be 32 x 32px and can now be drawn on. To save correctly for using in Visual TFT, you must save it as a BMP picture like this…

export_bmp

Now that you have a bitmap of an image you’d like to display, open Visual TFT and start a new project. It will prompt you for a platform you are using, and after that you will need to add an image resource and load your image from a file like this…

resource_file_tft

After adding an image, click generate code at the top of your screen in Visual TFT, and navigate to your project_name_resources.c and project_name_resources.h to find code almost ready for implementation. Lastly, change the type from const code char to uint8_t, and adding these two files to your project!

Play A Game!

You can even use the library to create your own game!

Summary

To make using our Matrix RGB easy, we provide a great library, without a heavy setup or large processing load for your host MCU. SPI communication is used to tell a FT900 what to do, and it takes it from there. It can be used for bitmap pictures, scrolling text or non-moving text, drawings, or even a cool debugging tool if you’d like!

References:

Manual for Matrix RGB Click 2016

Libstock libraries for Matrix RGB Click 2016

Products mentioned

, , , , , , , ,

By  
Firmware Engineer at MikroElektronika from Oregon with a passion for learning and programming.