Color Scrolling LED Text and Images With Arduino

by electric_piano_5k in Circuits > Arduino

797 Views, 1 Favorites, 0 Comments

Color Scrolling LED Text and Images With Arduino

LED_display_finished.jpg

This instructable shows how to use an Arduino to display color scrolling text and images on a 16x16 color LED array. Check out the video at the end of the instructable!

Supplies

IMG_3028.jpg

You need:

A color LED array (WS2812B type). This type of array has fully addressable color LEDs. I used a 16x16 array, but they are available in different sizes. You can use more than 1 array to make a larger display if you want. But, the number of arrays you can use is limited by the Arduino's RAM, because the Neopixel library stores the LED color settings in RAM. With an Arduino with 2k RAM, the maximum number of LED's is about 600, so you can use only 2 panels (512 LEDs).

An Arduino. I used Arduino Leonardo, but any Arduino should work.

A computer to program the Arduino and create the text/image file to display.

5V power supply. You can't just power the project through the Arduino USB port, this will not provide enough current to drive all the LEDs in the array (if you turn them all on at once). One panel will draw about 50 milliamps per LED if turned on white at full brightness, or 13 amps of current for a 256 LED array, so use a power supply with at least this much current capacity. I used a bench power supply or an old computer power supply. Alternatively, you can turn down the brightness of the LEDs.

Some wires, connector pins, soldering iron, etc. that you normally need when doing anything with Arduino. Check the picture, everything is there except the power supply. The breadboard is optional.

Connections

image1.jpeg

Make the following connections:

+5V from power supply to Vin on Arduino and +5V pin on the LED array.

Ground from power supply to GND on Arduino and GND on the LED array.

Pin 6 on Arduino to Data In on the LED array. If you use a different pin on Arduino, change the PIN number in the program.

That's it!

I made a cable to connect to the panel so I could place it a few feet away from the Arduino and power supply. For this I used a broken phone charging cable. The wire was broken at the plug end, I cut off the plugs and soldered a connector for the LED panel on one end, and solid wires on the other end that I could plug into the breadboard. Tip: the LED panels sometimes come with connectors that you have to solder on, so just solder one to the Data In connections and use the other one for your connection cable. You don't need a connector on the Data Out side if you have only one array. A phone charging cable is great for this because the +5V and ground wires are heavy enough to handle a few amps of current, plus there are two data wires to use (we only need one).

I taped a piece of white paper to the LED panel to act as a diffuser, as shown in the picture. This is optional.

The Program

Install the Arduino IDE if you haven't already (go to arduino.cc).. Download the Adafruit_NeoPixel library and install it in the Arduino/libraries directory.

Open the Arduino IDE and enter the following code. (The file is attached for convenience.)


#include <Adafruit_NeoPixel.h>


// This program displays a scrolling image on a 16x16 LED array or string of arrays.


#define PIN   6 // change to whatever pin you are using to send data to the LED array.

#define N_LEDS 256 // must be (number of pixels per array)*(number of arrays being used)

#define imageRows 16 // the size of the image that is going to be displayed. Height normally 16.

#define imageCols 285 // Change this number depending on the width of your scrolling image.

// number of rows and columns in each LED panel

#define numRows 16

#define numCols 16


Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);


int numPanels = N_LEDS/numRows/numCols;

int offset = numCols*numPanels;

int pixel = 0;

int imageStartCol = 0;

int imageRow = 0;

int imageCol = 0;

int r=0;

int g=0;

int b=0;

int brightness = 255; // max brightness is 255


// the image data is stored in program memory (flash memory), because there is not enough RAM in an Arduino to store the whole image.

const uint8_t pc[imageRows][imageCols][3] PROGMEM = 

#include "bonneFeteDesMeres285x16.h"  // write the name of the text file where the image data is stored.

;


void setup() {

 strip.begin();

  strip.show(); // Turn OFF all pixels ASAP

strip.setBrightness(brightness); // Set brightness.


}


void loop() {

  

 offset--;

 if (offset < -imageCols) {

  offset = numCols*numPanels;

 }


 pixel = 0;

  

 for(int panel=0; panel<numPanels; panel++) {

  imageStartCol = panel*numCols-offset;

  imageRow = 0;

  for (int y=0; y<numRows/2; y++) {

   for (int x=numCols-1; x>=0; x--) {

    imageCol = imageStartCol + x;

    if ((imageCol < 0) || (imageCol >= imageCols)) {

     drawPixel(strip.Color(0, 0, 0)); // Draw black

    }

    else {

     r = int(pgm_read_byte_near(&pc[imageRow][imageCol][0]));

     g = int(pgm_read_byte_near(&pc[imageRow][imageCol][1]));

     b = int(pgm_read_byte_near(&pc[imageRow][imageCol][2]));

     drawPixel(strip.Color(r, g, b)); // Draw image pixel

    }

    pixel++;

   }

   imageRow++;

   for (int x=0; x<numCols; x++) {

    imageCol = imageStartCol + x;

    if ((imageCol < 0) || (imageCol >= imageCols)) {

     drawPixel(strip.Color(0, 0, 0)); // Draw black

    }

    else {

     r = int(pgm_read_byte_near(&pc[imageRow][imageCol][0]));

     g = int(pgm_read_byte_near(&pc[imageRow][imageCol][1]));

     b = int(pgm_read_byte_near(&pc[imageRow][imageCol][2]));

     drawPixel(strip.Color(r, g, b)); // Draw image pixel

    }

    pixel++;

   }

   imageRow++;

  }

 }

 strip.show();

 delay(25); // you can change this number to change the scrolling speed. Smaller number will be faster scrolling.


}



static void drawPixel(uint32_t c) {

 strip.setPixelColor(pixel , c); // Draw new pixel

}

Create Your Text/image

Bonne fete des meres 285x16.png

This program basically displays an image on the LED array, scrolling it from right to left. The image must be 16 pixels high (or whatever is the vertical dimension of your LED array) and it can be up to about 500 pixels wide. Why only 500 pixels? This is because the basic Arduinos like Uno and Leonardo have only 32k bytes of memory, and every pixel in the image requires 3 bytes of memory (values for red, green, and blue). So, 3x16x500 = 24,000 bytes. The rest of the program takes about 5k bytes, so this is about all that will fit. (EDIT: while I was trying to make a longer message, somewhere between 307x16 and 314x16 image size the program refused to compile, even though it said only 55% of memory was being used at 307x16. The problem here seems to be that the maximum *.h file size that you can #include is 64k bytes, my 307x16 file was 63k and my 314x16 file was 65k. To get around this, break the *.h file into 2 or more files with each file being less than 64k bytes and use 2 or more #include commands.) The image is stored in the Arduino's program memory (flash memory) not RAM, because the Arduino has only 2k RAM. The PROGMEM command is used to put the data in the program memory.

Use any word processor software (I used WordPad) to create a short message. Make the background black using the highlight feature. It is helpful to add a few spaces at the beginning and end of the message so you have some black area before and after the text. You can make the text any color you want, even make each letter a different color. You can use any font, but I find bold fonts work better. It is helpful to make the font larger, 24 point or more.

Copy the text and paste it into Paint (or another image editing software). I actually used PrintScreen and pasted that into Paint, then cropped to get just the text. You can add other images like hearts or flowers, if you are going to do that leave space for them when cropping. Make sure the images have black backgrounds, if not you can manually paint the background black. Make the images the same height as the text.

When you are happy with your message, carefully crop as close as you can to the top and bottom of the text. You should now have a wide image that is just the height of your line of text and images.

Click on "Resize and Skew" and select "Pixels", then change the Vertical number to 16. Make a note of the horizontal pixel size, you will need to change the value of imageCols in the program to this number.

Save the image as a PNG file.

Go to https://onlinepngtools.com/convert-png-to-rgb-values and upload the PNG file. Select the options 3D array and Curly brackets, channel delimiter "comma" and group delimiter "comma". This will generate text compatible with Arduino code. Copy the converted text to the clipboard.

Open Notepad and paste the text. Save it as a file "filename.h", in the same directory as your Arduino sketch. In the program, change the file name from "bonneFeteDesMeres285x16.h" to whatever you have named your new file.

After you have made the changes to the program, connect the Arduino to the USB port of your computer and upload the sketch to the Arduino. I always disconnect the Arduino from the power supply and LED strip when I am connecting to my computer. Supposedly the Arduino can handle being connected to two power sources at the same time, but I think this is risky, especially with a high current device such as the LED array connected, why risk damaging your Arduino or your computer.

That's it, you are done! Turn on the power and enjoy the display!