0

Previously I asked a question that was a bit to broad so I'm narrowing the focus to a single component board of my design.

I have a set of 3 luckylight R/G bar graphs (datasheet here: https://cdn-shop.adafruit.com/datasheets/KWL-R1230XDUGB.pdf) A 5.1 V 2A power source (recycled ac/dc converter voltage tested datasheet here: http://pdf1.alldatasheet.com/datasheet-pdf/view/322359/BOTHHAND/M1-10S05.html) a series of 5 SN74HC595 (for controlling the LED multiplexing) and an Arduino Nano.

The purpose of the bar graphs is to show the player how much of his available system energy he/she is using.

The first three bars of the graph are set to Red, the next 5 are yellow, and the final 4 are green.

As various components are switched on, or other activities drain the power of the engine core, a program level command will switch the multiplexing array to have them shut off.

The problem I'm having is getting enough power to each of the LEDs of the bar graph without overloading the IC pins on the Arduino or shift registers and making the colors appear correctly.

I know I could use Darlington arrays, or a bunch of transistors to keep the power going to the LEDs on a line independent of the ICs, but i'm not sure the right way to go about this. I have a few ULN2803 Darlingtons and a lot of 2n2222a transistors.

(Also my current Arduino code only has, at max, 8 LEDs from each register on at the same time, with a forward voltage of 2.4 volts and 20mA per LED. There are three cycles to my code because the bar graphs have three shared cathode pins that run three 2x4 matrices.)

Additionally I don't know precisely how to calculate the resistor values I would need for this arrangement to maintain the same voltage being applied to the 24 simultaneously running LEDs and get their brightness to be equivalent. Currently i'm noticing LEDs that are farther down the 595 logic chain are receiving less power and appearing weaker. (yes i have been running them off the power coming from the Arduino thus far)

Hopefully this is a narrow enough question.

closed as off-topic by Chris Stratton, per1234, jose can u c, gre_gor, VE7JRO Mar 30 '18 at 14:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Arduino, within the scope defined in the help center." – Chris Stratton, per1234, jose can u c, gre_gor, VE7JRO
If this question can be reworded to fit the rules in the help center, please edit the question.

  • LOL, you don't seem to be having much luck asking questions here. Your earlier one was closed by community voting (not by me) as too broad, and now this one as not about the Arduino. Maybe you should have mentioned Arduino in the question. I stand by my answer, but if the question isn't re-opened try asking on Electrical Engineering Stack Exchange. Make sure you put the word "Arduino" in the question, and they will quickly close it and migrate it back here. :) – Nick Gammon Mar 31 '18 at 6:19
  • As for the people that voted to close this, you know perfectly well that if the word Arduino was mentioned it wouldn't last 10 minutes on EE Stack Exchange, and would be sent back here. – Nick Gammon Mar 31 '18 at 6:20
  • I guess I didn't word something right, but i also understand this question could have been about another microprocessor environment. Either way it is an Arduino question, but about best practices when using higher output currents than the Arduino can source directly. – B. Guisgand Apr 2 '18 at 2:29
0

According to this datasheet the 595 can drive up to 6 mA per output pin with a maximum of 20 mA for the input to the chip (so, 2.5 mA if you are driving all outputs).

Since your LEDs are quoting a forward current of 25 mA it seems that you will fall somewhat short of providing the 25 mA per LED.

There are higher power shift registers, eg. the TPIC6B595.

You might want to consider a multiplexing LED driver such as the MAX7219. I have a post about using that chip.

Your LEDs sound similar to the things that the MAX7219 is designed to drive. It also has inbuilt current-limiting with the current selected by a single resistor.

It isn't clear from your question whether you have the common anode or common cathode device, but you need a common cathode for the MAX7219.


The MAX7219 is not that expensive if you buy it from eBay. For example search for "MAX7219 kit". I found hits for 4 x MAX7219 for $US 9.75 including boards, capacitors and LEDs. Just discard the LEDs (8 x 8 dot matrix) and run the wires to your bargraph.


As they are designed to run 7 segment displays how would I connect it to transfer from my current 16 bit binary shift setup ...

They can run in a couple of modes (see the Decode Mode register) and one is to send arbitrary bits. Since you can program in any combination of bits (in my link above there is an array which does a CP437 font) you can therefore make up any combination of bars on and off. I would get one as an experiment (buy one of those kits from eBay) and try the idea out. It will be a lot less mucking around than 595 chips, transistors, current-limiting resistors, and so on.

There are various kits around, some are pre-soldered (which you won't want), some come with SMD chips and some with through-hole chips. Choose SMD or through-hole depending on your confidence with soldering SMD parts.


I know on my shift registers pins 1-8 go to the LED anodes and Pins 9-11 go to transistors that run the cathodes. Can you help me understand the pin connections to get the MAX to run this?

Looking at your bar graph specs:

Bar graph wiring

You have 3 rather than 8 cathodes (pins 14, 9 and 8 are duplicates of 1, 6 and 7). So, you would run the cathode wiring (1, 6, 7) to the first 3 "digit" pins (2, 11 and 6) on the MAX7219. The other 8 wires (marked anodes) would go to the 8 anodes (2, 3, 4, 5, 10, 11, 12, 13).

As you have only used 3 cathode pins you could wire up a second bargraph using another 3 cathode pins (and run the anodes in parallel). That way a single MAX7219 can drive two bargraphs, giving you a total of 24 bars, each of which can show red, green, or yellow at one time.


Example wiring and code

I ordered a couple of the LED modules and worked out a schematic for them:

LED bargraph module schematic

One MAX7219 can drive two of the modules.

Example of wiring:

LED bargraph wiring

Example code:

#include <SPI.h>

 // define max7219 registers
const byte MAX7219_REG_NOOP        = 0x0;
const byte MAX7219_REG_DIGIT0      = 0x1;
const byte MAX7219_REG_DIGIT1      = 0x2;
const byte MAX7219_REG_DIGIT2      = 0x3;
const byte MAX7219_REG_DIGIT3      = 0x4;
const byte MAX7219_REG_DIGIT4      = 0x5;
const byte MAX7219_REG_DIGIT5      = 0x6;
const byte MAX7219_REG_DIGIT6      = 0x7;
const byte MAX7219_REG_DIGIT7      = 0x8;
const byte MAX7219_REG_DECODEMODE  = 0x9;
const byte MAX7219_REG_INTENSITY   = 0xA;
const byte MAX7219_REG_SCANLIMIT   = 0xB;
const byte MAX7219_REG_SHUTDOWN    = 0xC;
const byte MAX7219_REG_DISPLAYTEST = 0xF;

// which groups of bars we are addressing
const byte BARS_1_4   = MAX7219_REG_DIGIT0;
const byte BARS_5_8   = MAX7219_REG_DIGIT1;
const byte BARS_9_12  = MAX7219_REG_DIGIT2;
const byte BARS_13_16 = MAX7219_REG_DIGIT3;
const byte BARS_17_20 = MAX7219_REG_DIGIT4;
const byte BARS_21_24 = MAX7219_REG_DIGIT5;

// within a group, which one (from the left)
const byte BAR1_RED = 0x80;
const byte BAR2_RED = 0x20;
const byte BAR3_RED = 0x08;
const byte BAR4_RED = 0x02;

const byte BAR1_GREEN = 0x40;
const byte BAR2_GREEN = 0x10;
const byte BAR3_GREEN = 0x04;
const byte BAR4_GREEN = 0x01;

// yellow is done by adding red and green
const byte BAR1_YELLOW = BAR1_RED + BAR1_GREEN;
const byte BAR2_YELLOW = BAR2_RED + BAR2_GREEN;
const byte BAR3_YELLOW = BAR3_RED + BAR3_GREEN;
const byte BAR4_YELLOW = BAR4_RED + BAR4_GREEN;

void sendByte (const byte reg, const byte data)
  {    
  digitalWrite (SS, LOW);
  SPI.transfer (reg);
  SPI.transfer (data);
  digitalWrite (SS, HIGH); 
  }  // end of sendByte

void setup () {

  SPI.begin ();

  sendByte (MAX7219_REG_SCANLIMIT, 5);   // show 6 digits
  sendByte (MAX7219_REG_DECODEMODE, 0);  // using an led matrix (not digits)
  sendByte (MAX7219_REG_DISPLAYTEST, 0); // no display test

  // clear display
  for (byte col = 0; col < 8; col++)
    sendByte (col + 1, 0);

  sendByte (MAX7219_REG_INTENSITY, 7);  // character intensity: range: 0 to 15
  sendByte (MAX7219_REG_SHUTDOWN, 1);   // not in shutdown mode (ie. start it up)
}   // end of setup

void loop () 
 {
  // send various test combinations
  sendByte(BARS_1_4, BAR1_RED | BAR2_GREEN | BAR3_RED | BAR4_GREEN);
  sendByte(BARS_5_8, BAR2_RED);
  sendByte(BARS_9_12, BAR2_YELLOW);
  sendByte(BARS_13_16, BAR1_RED | BAR2_GREEN | BAR3_RED | BAR4_GREEN);
  sendByte(BARS_17_20, BAR2_YELLOW);
  sendByte(BARS_21_24, BAR1_RED | BAR2_RED);
 }  // end of loop

This is documented in my page about the MAX7219.

  • It is common cathode. The MAX7219's are a bit pricey, considering I need 9 bar graphs for the project. I was hoping to use the cheaper 595's and just add a transistor array to increase power, but looks like the 7219 might be the way to go. As they are designed to run 7 segment displays how would I connect it to transfer from my current 16 bit binary shift setup, to the correct pins on the MAX. I know on my shift registers pins 1-8 go to the LED anodes and Pins 9-11 go to transistors that run the cathodes. Can you help me understand the pin connections to get the MAX to run this? – B. Guisgand Mar 30 '18 at 2:11
  • See amended answer. – Nick Gammon Mar 30 '18 at 4:03
  • According to the Adafruit page for that product "Since the display is multiplexed we suggest using 3 NPN transistors to drive the cathodes with microcontroller pins and then a 74HC595 to drive the 8 anodes." So, certainly using transistors and a 595 is a possibility. But for 9 of them I think you will find yourself swamped by wires, transistors and resistors, and that the MAX7219 will simply the process. – Nick Gammon Mar 30 '18 at 4:42
  • Thanks, that was very helpful. Just FYI the common cathodes are each doubled so cathodes 8,9,&14 are not necessary. They just allow you to wire from either side of the display easier. I'll try to find a better deal on the MAX7219's. I was a little nervous buying the cheap kits that came with them rather than buying from manufacturer, simply because of the massive price difference. I'll give that a try though. – B. Guisgand Mar 31 '18 at 2:56
  • So far I haven't had a problem with the eBay ones, and for the price, even if I did, I wouldn't be too concerned. I've ordered a couple of your bar LED displays to see how easy it would be to adapt them to the MAX7219. I suspect it will be fairly easy. – Nick Gammon Mar 31 '18 at 6:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.