This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
tutorials:products:rgbledmatrix:index.html [2011/12/09 23:40] ladyada [Wiring the 32x32] |
tutorials:products:rgbledmatrix:index.html [2016/01/28 18:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | + | ====== Moved! ====== | |
- | ==== Introduction ==== | + | |
- | + | ||
- | + | ||
- | Bring a little bit of Times Square into your home with our 16 x 32 and 32 x 32 RGB LED matrix panels. These panels are normally used to make video walls, here in New York we see them on the sides of busses and bus stops, to display animations or short video clips. We thought they looked really cool so we picked up a few boxes of them from a factory. One has 512 bright RGB LEDs arranged in a 16x32 grid on the front, the other has 1024 LEDs in 32 x 32. On the back there is a PCB with IDC connectors (one set for input, one foroutput: in theory you can chain these together) and 12 16-bit latches that allow you to drive the display with a 1:8 (16x32) or 1:16 (32x32) scan rate. | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/rgbmatrix.jpg|{{ http://www.ladyada.net/images/rgbmatrix/rgbmatrix_t.jpg?nolink&500x316 |}}]] | + | |
- | + | ||
- | + | ||
- | + | ||
- | These panels require 12 or 13 digital pins (6 bit data, 6 or 7 bit control) and a good 5V supply, up to 2A per panel (when on full white). We suggest our 2A regulated 5V adapter and then soldering a jack on such as from our extension cord. Please check out our tutorial for more details! | + | |
- | + | ||
- | + | ||
- | + | ||
- | Keep in mind that these displays are designed to be driven by FPGAs or other high speed processors: they do not have built in PWM control of any kind. Instead, you're supposed to redraw the screen over and over to 'manually' PWM the whole thing. On a 16 MHz Arduino, we managed to squeeze 12-bit color (4096 colors) with 20% CPU usage but this display would really shine if driven by an FPGA, CPLD, Propeller, XMOS or other high speed multi-processor controller. | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/plasma.jpg|{{ http://www.ladyada.net/images/rgbmatrix/plasma_t.jpg?nolink&500x306 |}}]] | + | |
- | + | ||
- | Of course, we wouldn't leave you with a datasheet and a "good luck!" We have a full wiring diagrams and working Arduino library code with examples from drawing pixels, lines, rectangles, circles and text. You'll get your color blasting within the hour! On an Arduino, you'll need 12 digital pins, and about 800 bytes of RAM to buffer the 12-bit color image. | + | |
- | + | ||
- | + | ||
- | ==== Powering ==== | + | |
- | + | ||
- | + | ||
- | One thing to keep in mind (again) with this display is that the matrix was designed to be run by a 250-pin 100 MHz FPGA, not a 16-MHz AVR. To keep the speed and color resolution somewhat reasonable, we've 'fixed' the pinout so that the 6-pin data bus (2 red, 2 green and 2 blue) must be on the digital pins **2** thru **7** (pins 0 and 1 are used for uploading/downloading). We've also 'fixed' the clock pin in the library to be **digital 8** The other pins can change as you'd like but for our tutorial we'll be using the analog pins **0** thru **3** and digital **9**. | + | |
- | + | ||
- | + | ||
- | + | ||
- | There's no way to avoid needing all 6 data pins and the 6 (16x32 display) or 7 (32x32 display) control pins! (While the **OE** pin is, technically, not required and could be tied permanently to ground but it would cause ghosting on the display so we don't recommend it.) | + | |
- | + | ||
- | + | ||
- | + | ||
- | One handy thing about how the matrix is designed, the power cable is seperate from the data connection, this makes it a lot easier to wire and you can easily give the matrix its own 5V supply (it needs up to 2A if you have all the LEDs on bright white!) | + | |
- | + | ||
- | + | ||
- | + | ||
- | Lets begin by connecting up a 5V supply. For the 16x32 matrix, the way we are going to do this is to [[https://www.adafruit.com/products/327|cut a 2.1mm jack from this extension cord]] and solder it to the panel back. [[https://www.adafruit.com/products/276|This way you can plug the 5V from a wall adapter]] (the one we have in the shop is suggested) right in. Simply cut the other half of the cable off, and strip the wiring so you can solder the red wire to +5 and the black wire to ground | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/dcplugcut.jpg|{{ http://www.ladyada.net/images/rgbmatrix/dcplugcut_t.jpg?nolink&500x332 |}}]] | + | |
- | + | ||
- | Solder both pins correctly to the power port. Make sure you get this right because there is no protection diode! | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/5vsoldered.jpg|{{ http://www.ladyada.net/images/rgbmatrix/5vsoldered_t.jpg?nolink&500x307 |}}]] | + | |
- | + | ||
- | For the 32x32, we can use the 2.1mm terminal block adapter and simply attach the spade lugs directly, works nice! | + | |
- | + | ||
- | ==== Wiring the 16x32 ==== | + | |
- | + | ||
- | Wiring to the 16x32 is much easier than the 32x32 since there is only one INPUT jack. You can wire without soldering. For the 32x32, see below for a diagram. Now we will connect to the IDC data port. On the here are two ports, one on either side. Look for the one on the left, with the **J-IN** label. You'll want to keep a good look at this because it also has the pinout diagram! | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/inputidc.jpg|{{ http://www.ladyada.net/images/rgbmatrix/inputidc_t.jpg?nolink&500x374 |}}]] | + | |
- | + | ||
- | Plug the IDC cable in as shown | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/idcplug.jpg|{{ http://www.ladyada.net/images/rgbmatrix/idcplug_t.jpg?nolink&500x367 |}}]] | + | |
- | + | ||
- | We will test the panel by free-wiring to the other side of the plug. There are **a lot of pins** so keep good track of the colors, and triple check if it doesn't work! The good news is that even if you mess up the wiring, you wont damage the panel because the power pins are kept seperate (but you could short your microcontroller pins to ground which they might not like) | + | |
- | + | ||
- | Start with the first 8 pins, the color data pins: R1, G1, B1, ground, R2, G2, B2. The panel requires that you write to two LEDs at a time (one on the top half and one on the bottom half. | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/inputidc.jpg|{{ http://www.ladyada.net/images/rgbmatrix/inputidc_t.jpg?nolink&500x374 |}}]] | + | |
- | + | ||
- | **HERE'S THE IMPORTANT THING TO REMEMBER!!!** The other side of the IDC cable is //flipped// when you wire it because you're looking -up- into it instead of -down- into the connector. The images below are **correct** | + | |
- | + | ||
- | We'll use red wire for the Red LEDs, green for green and blue for blue - makes sense that way! black is for the ground pins. Look carefully at how the IDC cable is placed in the vise, note where the red stripe is and the 'key' of the connector - its on the top. | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/idcwire1.jpg|{{ http://www.ladyada.net/images/rgbmatrix/idcwire1_t.jpg?nolink&500x350 |}}]] | + | |
- | + | ||
- | Now we can do the control pins. **A B **and **C** are the address pins, for multiplexing the display. Those are white wires. **CLK **(clock) is orange, **OE** (output enable) is brown, and **LAT** (data latch) is yellow. The remaining ground pins are again, black wires. | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/idcwire2.jpg|{{ http://www.ladyada.net/images/rgbmatrix/idcwire2_t.jpg?nolink&500x330 |}}]] | + | |
- | + | ||
- | Finally we can connect the wires directly to our Arduino (or other microcontroller) Connect: | + | |
- | + | ||
- | + | ||
- | ***R1** goes to **digital 2** | + | |
- | ***G1 **goes to **digital 3** | + | |
- | ***B1** goes to **digital 4** | + | |
- | ***R2** goes to **digital 5** | + | |
- | ***G2** goes to **digital 6** | + | |
- | ***B2** goes to **digital 7** | + | |
- | ***CLK** orange goes to **digital 8** | + | |
- | ***OE** brown goes to **digital 9** | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/digitalwiring.jpg|{{ http://www.ladyada.net/images/rgbmatrix/digitalwiring_t.jpg?nolink&500x290 |}}]] | + | |
- | + | ||
- | Next we'll do the remaining control pins. Connect | + | |
- | + | ||
- | + | ||
- | ***A** to **analog 0** | + | |
- | ***B** to **analog 1** | + | |
- | ***C** to **analog 2** | + | |
- | ***LAT** yellow to **analog 3** | + | |
- | + | ||
- | This leaves you with digital **10, 11, 12, 13** and analog **4, 5** to use for other sensors, switches, outputs, etc. | + | |
- | + | ||
- | + | ||
- | + | ||
- | Now you're ready to test the matrix! | + | |
- | + | ||
- | ==== Wiring the 32x32 ==== | + | |
- | + | ||
- | The 32x32 is a little tougher to wire up, because technically its two 16x32 panels that are 'glued' together. If you look at the back you can see the seam from where the two panels are joined. Both inputs have this pinout | + | |
- | + | ||
- | || GND | A || | + | |
- | || GND | B || | + | |
- | || GND | C || | + | |
- | || OE | D || | + | |
- | || RED | GREEN || | + | |
- | || BLUE | ? || | + | |
- | || GND | LAT || | + | |
- | || GND | CLK || | + | |
- | + | ||
- | Contrast this to the 16x32 panel which has two red/green/blue sets. This panel also has an extra address pin D (which means you have 1:2^4 = 1:16 refresh rate) | + | |
- | + | ||
- | In order to make the panel as compatible as possible with our existing 16x32 panel, we'll do a trick where we connect the control pins **A**, **B**, **C**, **D**, **OE**, **LAT** and **CLK** together on both 'halves' of the panel. Then we'll write to both panels at the same time, by having two sets of **RED**, **GREEN** and **BLUE** pins. That way, it 'looks' like the 16x32 panel with 6 color lines and 6 data lines + 1 extra address pin. | + | |
- | + | ||
- | Unfortunately, this makes wiring a little hairy because you have to tie the datalines together. We suggest using a prototype board to have both IDCs connected together on the PCB. | + | |
- | + | ||
- | We'll use a protoshield, first place two sets of 2x8 header in the positions shown: | + | |
- | + | ||
- | {{ :tutorials:products:rgbledmatrix:3232headerplace.jpg?500 |}} | + | |
- | + | ||
- | Start by connecting the two RGB pin sets to digital **2-7** | + | |
- | + | ||
- | {{ :tutorials:products:rgbledmatrix:3232rgb.jpg?500 |}} | + | |
- | + | ||
- | Then tie both **CLK** pins together, and to digital **8** | + | |
- | + | ||
- | {{ :tutorials:products:rgbledmatrix:3232clk.jpg?500 |}} | + | |
- | + | ||
- | Tie both **LAT** pins together, and to digital **9** | + | |
- | + | ||
- | {{ :tutorials:products:rgbledmatrix:3232lat.jpg?500 |}} | + | |
- | + | ||
- | Tie both **OE** pins together, and to digital **10** | + | |
- | + | ||
- | {{ :tutorials:products:rgbledmatrix:3232oe.jpg?500 |}} | + | |
- | + | ||
- | Tie all four **ADDR** (**A B C D**) pins together and to **analog 0-3** | + | |
- | + | ||
- | {{ :tutorials:products:rgbledmatrix:3232addr.jpg?500 |}} | + | |
- | + | ||
- | Finally, connect one of the ground pins from each side to the common Arduino ground. The remaining GND pins are tied together on the RGB panel! | + | |
- | + | ||
- | + | ||
- | {{ :tutorials:products:rgbledmatrix:3232gnd.jpg?500 |}} | + | |
- | + | ||
- | ==== Test example code ==== | + | |
- | + | ||
- | + | ||
- | To run the matrix, you need a driver library. We wrote a library for Arduino, which should be portable to any microcontroller by adapting the C++ code. [[https://github.com/adafruit/RGB-matrix-Panel|We're assuming you'll be using an Arduino here so visit the github repository and download the RGBmatrixPanel library]] by clicking the **ZIP** button near the upper left, rename the uncompressed folder **RGBmatrixPanel**. \\ Check that the** RGBmatrixPanel** folder contains **RGBmatrixPanel.cpp** and** RGBmatrixPanel.h \\ **Place the **RGBmatrixPanel** library folder your **<arduinosketchfolder>/libraries/** folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. | + | |
- | + | ||
- | + | ||
- | Now you are ready to test! Open up the IDE and load **File->Examples->RGBmatrixPanel->testcolors_16x32** or **File->Examples->RGBmatrixPanel->testcolors_32x32** and upload it to your Arduino | + | |
- | + | ||
- | + | ||
- | + | ||
- | You should see the following: | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/allcolors.jpg|{{ http://www.ladyada.net/images/rgbmatrix/allcolors_t.jpg?nolink&500x276 |}}]] \\ | + | |
- | + | ||
- | + | ||
- | + | ||
- | This is a test pattern that shows 512 colors (out of 4096) on the 512 pixels. Since there's no really elegant way to show a 3-dimensional color space (R/G/B) in two dimensions, there's just repeating grids of red/green with increasing blue. Anyways, this shows you the range of colors you can achieve! | + | |
- | + | ||
- | + | ||
- | + | ||
- | Now that you've got it working here are a few things to look for: | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | The most useful line to look at is: | + | |
- | + | ||
- | <code C> | + | |
- | matrix.drawPixel(x, y, matrix.Color333(r, g, b)); | + | |
- | </code> | + | |
- | + | ||
- | which is where we actually draw to the display. This code only draws one pixel at a time. The **x** and** y** coordinates are the individual pixels of the display. **(0,0)** is in the top left corner, **(31, 15)** is in the bottom right (remember that we start counting at 0 here!). To create a color, you will want to use the helper funciton **Color333** which will take three 3-bit numbers and combine them into a single packed integer. So for example, the first argument, **r** can range from 0 to 7. Likewise for **g**and **b**. To make a pixel that is pure red, **r** would be 7 and **g, b** would be 0. To make a white pixel, set all to 7. To make a black (off) pixel, set the colors to 0. A similar function, **Color444**, accepts three 4-bit numbers for up to 4096 colors. | + | |
- | + | ||
- | + | ||
- | + | ||
- | Now we can open up the next example, which shows the rest of the library capabilities | + | |
- | + | ||
- | + | ||
- | ==== Library ==== | + | |
- | Next up, load the **testshapes_16x32** or **testshapes_32x32** example sketch, which will test every drawing element available | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/matrixshapes.jpg|{{ http://www.ladyada.net/images/rgbmatrix/matrixshapes_t.jpg?nolink&500x311 |}}]] | + | |
- | + | ||
- | The most simple thing you may want to do is draw a single pixel, we saw this introduced above | + | |
- | + | ||
- | <code C> | + | |
- | // draw a pixel in solid white | + | |
- | matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7)); | + | |
- | </code>Next we will fill the screen with green by drawing a really large rectangle. The first two arguments are the top left point, then the width in pixels, and the height in pixels, finally the color | + | |
- | + | ||
- | <code C> | + | |
- | // fix the screen with green | + | |
- | matrix.fillRect(0, 0, 32, 16, matrix.Color333(0, 7, 0)); | + | |
- | </code> | + | |
- | + | ||
- | Next we will draw just the outline of a rectangle, in yellow | + | |
- | + | ||
- | <code C> | + | |
- | // draw a box in yellow | + | |
- | matrix.drawRect(0, 0, 32, 16, matrix.Color333(7, 7, 0));</code> | + | |
- | + | ||
- | Next you may want to draw lines. The **drawLine** procedure will draw a line in any color you want, we used this to draw a big X | + | |
- | + | ||
- | <code C> | + | |
- | // draw an 'X' in red | + | |
- | matrix.drawLine(0, 0, 31, 15, matrix.Color333(7, 0, 0)); | + | |
- | matrix.drawLine(31, 0, 0, 15, matrix.Color333(7, 0, 0));</code> | + | |
- | + | ||
- | The next shapes we draw are circles. You can draw the outline of a circle with **drawCircle**or fill a circle with **fillCircle**. The first two arguments are the center point, the third argument is the radius in pixels, finally the color to use. | + | |
- | + | ||
- | <code C> | + | |
- | // draw a blue circle | + | |
- | matrix.drawCircle(7, 7, 7, matrix.Color333(0, 0, 7)); | + | |
- | + | ||
- | // fill a violet circle | + | |
- | matrix.fillCircle(23, 7, 7, matrix.Color333(7, 0, 7));</code>**fill** allows you to fill the entire screen with a single color<code C> | + | |
- | // fill the screen with 'black' | + | |
- | matrix.fill(matrix.Color333(0, 0, 0)); | + | |
- | </code> | + | |
- | + | ||
- | Finally, we draw the text that is shown up top as the demonstration image. We can use the **print** function, which you'll be familiar with from **Serial**. You can use **print** to print strings, numbers, variables, etc. However, we need to set up the printing before just going off and doing it! First, we must set the cursor location with **setCursor **which is where the top left pixel of the first character will go, this can be anywhere but note that text characters are 8 pixels high by default. Next **setTextSize **lets you set the size to 1 (8 pixel high) or 2 (16 pixel high for really big text!), you probably want just to stick with 1 for now. Lastly we can set the color of the text with **setTextColor**. Once this is all done, we can just use **print('1') **to print the character "1". | + | |
- | + | ||
- | <code C> | + | |
- | // draw some text! | + | |
- | matrix.setCursor(1, 0); // start at top left, with one pixel of spacing | + | |
- | matrix.setTextSize(1); // size 1 == 8 pixels high | + | |
- | + | ||
- | // print each letter with a rainbow color | + | |
- | matrix.setTextColor(matrix.Color333(7,0,0)); | + | |
- | matrix.print('1'); | + | |
- | matrix.setTextColor(matrix.Color333(7,4,0)); | + | |
- | matrix.print('6'); | + | |
- | matrix.setTextColor(matrix.Color333(7,7,0)); | + | |
- | matrix.print('x'); | + | |
- | matrix.setTextColor(matrix.Color333(4,7,0)); | + | |
- | matrix.print('3'); | + | |
- | matrix.setTextColor(matrix.Color333(0,7,0)); | + | |
- | matrix.print('2'); | + | |
- | + | ||
- | matrix.setCursor(1, 9); // next line | + | |
- | matrix.setTextColor(matrix.Color333(0,7,7)); | + | |
- | matrix.print('*'); | + | |
- | matrix.setTextColor(matrix.Color333(0,4,7)); | + | |
- | matrix.print('R'); | + | |
- | matrix.setTextColor(matrix.Color333(0,0,7)); | + | |
- | matrix.print('G'); | + | |
- | matrix.setTextColor(matrix.Color333(4,0,7)); | + | |
- | matrix.print("B"); | + | |
- | matrix.setTextColor(matrix.Color333(7,0,4)); | + | |
- | matrix.print("*"); | + | |
- | </code>[[http://www.ladyada.net/images/rgbmatrix/rgbmatrix.jpg|{{ http://www.ladyada.net/images/rgbmatrix/rgbmatrix_t.jpg?nolink&500x316 |}}]] | + | |
- | + | ||
- | + | ||
- | ==== Advanced wiring for the 16x32 ==== | + | |
- | + | ||
- | + | ||
- | Once you've tested the 16x32 panel, we suggest making a more permanent solution. We used a proto shield and some header to make a custom-wired shield that is easy to use. You can see that now because we're looking **down** at the plug, the wiring matches the diagram from the back of the panel, where **R1** is in the top left corner | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/shieldwire.jpg|{{ http://www.ladyada.net/images/rgbmatrix/shieldwire_t.jpg?nolink&500x387 |}}]] | + | |
- | + | ||
- | Match the red stripe of the cable to **R1** | + | |
- | + | ||
- | [[http://www.ladyada.net/images/rgbmatrix/shieldplug.jpg|{{ http://www.ladyada.net/images/rgbmatrix/shieldplug_t.jpg?nolink&500x385 |}}]] | + | |
- | + | ||
- | + | ||
- | ==== How the matrix works ==== | + | |
- | + | ||
- | + | ||
- | There's zero documention out there on how these matrices work, and no public datasheets or spec sheets so we are going to try to document how they work. | + | |
- | + | ||
- | + | ||
- | + | ||
- | First thing to notice is that there are 512 RGB LEDs in a 16x32 matrix. Like pretty much every matrix out there, **you can't drive all 512 at once**. One reason is that would require a lot of current, another reason is that it would be really expensive to have so many pins. Instead, the matrix is divided into 8 interleaved sections/strips. The first section is the 1st 'line' and the 9th 'line' (32 x 2 RGB LEDs = 64 RGB LEDs), the second is the 2nd and 10th line, etc until the last section which is the 7th and 16th line. You might be asking, why are the lines paired this way? wouldnt it be nicer to have the first section be the 1st and 2nd line, then 3rd and 4th, until the 15th and 16th? The reason they do it this way is so that the lines are interleaved and look better when refreshed, otherwise we'd see the stripes more clearly. | + | |
- | + | ||
- | + | ||
- | + | ||
- | So, on the PCB is 12 LED driver chips. These are like 74HC595s but they have 16 outputs and they are constant current. 16 outputs * 12 chips = 192 LEDs that can be controlled at once, and 64 * 3 (R G and B) = 192. So now the design comes together: You have 192 outputs that can control one line at a time, with each of 192 R, G and B LEDs either on or off. The controller (say an FPGA or microcontroller) selects which section to currently draw (using A, B, and C address pins - 3 bits can have 8 values). Once the address is set, the controller clocks out 192 bits of data (24 bytes) and latches it. Then it increments the address and clocks out another 192 bits, etc until it gets to address #7, then it sets the address back to #0 | + | |
- | + | ||
- | + | ||
- | + | ||
- | The only downside of this technique is that despite being very simple and fast, it has **no PWM control** built in! The controller can **only** set the LEDs **on or off**. So what do you do when you want full color? You actually need to draw the entire matrix over and over again at very high speeds to PWM the matrix manually. For that reason, you need to have a very fast controller (50 MHz is a minimum) if you want to do a lot of colors and motion video and have it look good. | + | |
- | + | ||
- | + | ||
- | ==== Downloads ==== | + | |
- | + | ||
- | + | ||
- | [[https://github.com/adafruit/RGB-matrix-Panel|Download our RGBmatrixPanel library]] by clicking the **ZIP** button near the top left corner, rename the uncompressed folder **RGBmatrixPanel**. Check that the** RGBmatrixPanel** folder contains **RGBmatrixPanel.cpp** and** RGBmatrixPanel.h \\ **Place the **RGBmatrixPanel** library folder your **<arduinosketchfolder>/libraries/** folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. | + | |
+ | This tutorial has moved to [[http://learn.adafruit.com/32x16-32x32-rgb-led-matrix/|http://learn.adafruit.com/32x16-32x32-rgb-led-matrix/]] |