Bi-Color 24 Bargraph

This version of the LED backpack is designed for these bright and colorful bi-color bargraph modules. Each module has 12 red and 12 green LEDs inside, for a total of 24 LEDs controlled as a 1x12 matrix. We put two modules on each backpack for a 24-bar long bargraph (48 total LEDs).

This backpack solves the annoyance of using lots of pins or a bunch of chips by having an I2C constant-current matrix controller sit neatly on the back of the PCB. The controller chip takes care of everything, drawing all 48 LEDs in the background. All you have to do is write data to it using the 2-pin I2C interface. There are three address select pins so you can select one of 8 addresses to control up to 8 of these on a single 2-pin I2C bus (as well as whatever other I2C chips or sensors you like). The driver chip can 'dim' the entire display from 1/16 brightness up to full brightness in 1/16th steps. It cannot dim individual LEDs, only the entire display at once.

Attaching the bar-graph modules

Pay close attention to the instructions for positioning the bargraphs. They must be oriented correctly to work and is almost impossible to remove them once soldered to the backpack!
Remove the parts from packaging and place the LED bargraphs over the outlines on the top of the PCB.

The bargraph must be soldered on the correct orientation or it will not work! Check for the side of the bargraph that has printing on it. Then look for the outline on the PCB that has "Text on this side" marked!

Do not solder the matrix onto the back of the PCB, it won't work either!
To keep the two bargraphs lined up nicely, you can use a little masking or scotch tape on the bargraph modules, tape them so they are in a straight line. There is a little play during soldering so if you don't do this the two modules may not be in a perfect line.
Turn over the PCB and bend opposite-corner pins of the modules out so that the modules are fixed in place against the PCB. Now is a good time to do a last check that you oriented the modules the right way!
Solder all the module pins in!
OK nice work!
Once soldered, clip each pin. They're quite short and the pins are thicker than usual, so do this over/inside a trash bin so that the pins don't fly off and it you or your pets.
Everything should be neat and clipped, you're done!

Soldering on breadboard pins

This is an optional step - you only need to do this step if you're planning on using the bargraph in a breadboard. Chances are you may want to solder wires directly to the pads instead, so you can mount the bargraph elsewhere. Anyhow, skip this step if its not for you!
Break off a piece of male header, 4 pins long. Plug the long ends into a solderless breadboard.
Place the PCB on top. you may need to support it a little since its quite long.
Solder these 4 pins too, since you're good at it now this should be easy.

Bi-Color Bargraph LED Backpack Wiring & Firmware

We wrote a basic library to help you work with the bi-color bargraph backpack. The library is written for the Arduino and will work with any Arduino as it just uses the I2C pins. The code is very portable and can be easily adapted to any I2C-capable micro.

Wiring to the bargraph is really easy

  • Connect SCL to the I2C clock - on Arduino UNO thats Analog #5, on the Leonardo its Digital #3, on the Mega its digital #21
  • Connect SDA to the I2C data - on Arduino UNO thats Analog #4, on the Leonardo its Digital #2, on the Mega its digital #20
  • Connect GND to common ground
  • Connect VCC to power - 5V is best but 3V also seems to work for 3V microcontrollers.

Next, download the Adafruit LED Backpack library from github . To download click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_LEDBackpack. Check that the Adafruit_LEDBackpack folder contains Adafruit_LEDBackpack.cpp and Adafruit_LEDBackpack.h Place the Adafruit_LEDBackpack library folder your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. You'll also need to download the Adafruit GFX library that provides the graphics drawing routines. Restart the IDE.

Once you've restarted you should be able to select the File->Examples->Adafruit_LEDBackpack->bargraph24 example sketch. Upload it to your Arduino as usual. You should see a basic test program that tests all the LEDs with different colors

Using the library interface is very easy. Start by creating the object with
Adafruit_24bargraph bar = Adafruit_24bargraph();
you can name it whatever you want, not just bar

Then initialize it with
bar.begin(0x70); // pass in the address
You can init with any address from 0x70 to 0x77, just make sure you solder in the matching solder jumpers!

Finally, write to the bargraph with
bar.setBar(lednumber, ledcolor);
Where lednumber is 0 thru 23. ledcolor can be LED_RED, LED_YELLOW, LED_GREEN or LED_OFF

The drawing routines only change the display memory kept by the Arduino. Don't forget to call bar.writeDisplay() after drawing to 'save' the memory out to the matrix via I2C.

There are also a few small routines that are special to the matrix:

  • setBrightness(brightness)- will let you change the overall brightness of the entire display. 0 is least bright, 15 is brightest and is what is initialized by the display when you start
  • blinkRate(rate) - You can blink the entire display. 0 is no blinking. 1, 2 or 3 is for display blinking.
This guide was first published on Jul 29, 2012. It was last updated on Jul 29, 2012. This page (Bi-Color 24 Bargraph) was last updated on Sep 18, 2019.