[calculate] rgb leds + sparkfun spi PCB + Arduino

Hello,
I own:

(if somebody interests in further: http://www.julienbayle.net/diy/LiveInterface/ )

I have some doubts about currents etc.

I'd like to know if I could use only USB cable power supply ( max 400mA.. I think)

If I'd need an external powersupply, how it goes ?
I know for the jumper... ok :smiley:
But do I use 5V and Gnd on the arduino board too ? or may I have an external circuit for the backpack, and the couple of components I use (164, 165 PISO and SIPO) ?

any helps would be appreciated !

Assume each LED takes 20mA then 64 * 20 * 3 = 3840mA which is too much for the USB port.

You can use an external supply just for the LEDs (make sure grounds are connected together) or for both LEDs and Ardunino. In that case feed the voltage into the Arduino's +5V input not the Vin.

For 5V you need 180R resistors. However many LEDs look good with just 6mA down them (it depends on their efficiency) in which case a 510R resistor would do. The three colours will require slightly different values to make them the same brightness so experiment with values around these.

This would give you 1152mA which would still need an external supply for.
However if you are going to multiplex them then they will probably need the 20mA as the multiplexing makes them dimmer (they are only on some of the time)

hello Grumpy_Mike,

do you know the sparkfun backpack? I mean, did you advice me with all these precious infos because it is this particular PCB or were you more general?

I guess 180R = 180KOhms
But with the sparkfun backpack, all is on the little pcb... 100KOhms are put on it.
I don't know if it will be enough etc ...
Someone did this test?

Ok for multiplexing
I'll check that

Ok for the power supply female connector on the board..
I guess I'll do that... Only one power supply for all..

precious infos because it is this particular PCB

no it's just general information

I guess 180R = 180KOhms

No 180R = 180 Ohms
180KOhms is 180000 Ohms

Assume you mean 100 Ohms on the board this is probably alright but I would go for a lower current unless you are going to multiplex them.
LEDs can stand a much higher current for a short time than the continuous current so when you are flashing them you tend to put more current through them to compensate for the fact they are off some of the time.

180R is a writing system I don't know...

I read without glasses: these are 100 Ohms.

the code is: (made by Sparkfun and grab on their page:
SparkFun LED Matrix - Serial Interface - Red/Green/Blue - COM-00760 - SparkFun Electronics )

/*


*/

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <math.h>

#define sbi(var, mask)   ((var) |= (uint8_t)(1 << mask))
#define cbi(var, mask)   ((var) &= (uint8_t)~(1 << mask))

#define CLK                        0
#define CLR                        3
#define LATCH                  2
#define DATA                  1
#define EN                        4

volatile uint8_t spiTemp;
volatile uint8_t lineByte[3]; 
volatile uint32_t red[8]; 
volatile uint32_t green[8];
volatile uint32_t blue[8];
volatile uint8_t row;
volatile uint8_t frameBufferIndex;


volatile uint32_t red[]       = {0x000001, 0x040000, 0x000008, 0x200000, 0x000040, 0x010000, 0x000200, 0x002000}; 
volatile uint32_t green[]      = {0x800000, 0x000004, 0x100000, 0x000020, 0x000080, 0x008000, 0x000400, 0x004000};
volatile uint32_t blue[]      = {0x000002, 0x080000, 0x000010, 0x400000, 0x020000, 0x000100, 0x001000, 0x000800};

volatile uint8_t image[] = {            
  1,  1,  1,  1,  1,  1,  1,  1,
  0,  1,  0,  0,  0,  0,  3,  0,
  0,  0,  1,  0,  0,  3,  0,  0,
  0,  0,  0,  1,  3,  0,  0,  0,
  0,  0,  0,  3,  1,  0,  0,  0,
  0,  0,  3,  0,  0,  1,  0,  0,
  0,  3,  0,  0,  0,  0,  1,  0,
  3,  0,  0,  0,  0,  0,  0,  1,
};

ISR (SIG_SPI) 
{
  if (!(PINB & 0x04))
  {
    spiTemp = SPDR;                        // read spi data register
/*    SPDR = image[(frameBufferIndex+1)%64];      |+ Write SPI Data register +|*/
    SPDR = image[(frameBufferIndex+1)&63];
    image[frameBufferIndex] = spiTemp;            // load value to frame buffer
    frameBufferIndex++;                        // increment frame buffer index (pixel number)
/*    frameBufferIndex %= 64;                  // wrap at 64*/
    frameBufferIndex &= 63;
  }
}


void delay_ms(uint16_t x);                              // general purpose delay

void ioinit (void);                                    // initializes IO

// this is the function that shifts 16 bits out to the 74hc595 shift registers
// it is inlined to speed things up
void inline shiftLine(volatile uint8_t[], volatile uint8_t rowNum);

int main (void)
{
  uint8_t i;
  uint32_t line;

  ioinit ();

  SPCR = (1 << SPE) | (1 << SPIE);
  sei();

  cbi(PORTC, CLR);
  delay_ms(1);
  sbi(PORTC, CLR);
  cbi(PORTC, EN);

  row = 0;
  PORTD = 0;

  for (i = 0; i < 64; i++)
    image[i] = 0;

  frameBufferIndex = 6;
  i = 0;

  lineByte[0] = 0xff;
  lineByte[1] = 0xff;
  lineByte[2] = 0xff;

  for (row = 0; row < 8; row++){
    shiftLine(lineByte, row);
    delay_ms(700);
  }

  for (row = 0; row < 8; row++){
    shiftLine(lineByte, row);
    delay_ms(700);
  }


  for (row = 0; row < 8; row++){
    shiftLine(lineByte, row);
    delay_ms(700);
  }

  for (;;){      //LED_off;

    // check cs status, reset frame buffer index to 0 if set

    if (PINB & 0x04)
      frameBufferIndex = 0;

    for (row = 0; row < 8; row++){
      line = 0;
      for (i = 0; i < 8; i++){

        switch (image[i + (8 * row)]){
          case 0: line |= 0; break;
          case 1: line |= red[i]; break;
          case 2: line |= green[i]; break;
          case 3: line |= blue[i]; break; 
          case 4: line |= (red[i] | green[i]); break;
          case 5: line |= (green[i] | blue[i]); break;
          case 6: line |= (blue[i] | red[i]); break; 
          case 7: line |= (red[i] | green[i] | blue[i]); break;
        }
        //line |= red[i];
      }
      lineByte[0] = line;
      lineByte[1] = line >> 8;
      lineByte[2] = line >> 16;
      shiftLine(lineByte, row);
    }
  }
  return (0);
}

void ioinit (void) /* Note [5] */
{
  DDRB |= (1 << 4);
  DDRD = 0xFF;  // atmega8 LEDs
  PORTD = 0x01;
  DDRC = 0x1F;
  sbi(PORTC, CLK);
  sbi(PORTC, CLR);
  sbi(PORTC, DATA);
  sbi(PORTC, LATCH);
  sbi(PORTC, EN);
}

void inline shiftLine(volatile uint8_t byte[], volatile uint8_t rowNum){
  uint8_t i, j;

  cbi(PORTC, LATCH);
  //sbi(PORTC, EN);
  for (j = 0; j < 3; j++){
    for(i = 0; i < 8; i++){

      cbi(PORTC, CLK);
      if (byte[j] & (1 << i))
        sbi(PORTC, DATA);
      else
        cbi(PORTC, DATA);

      sbi(PORTC, CLK);

    }
  }

  sbi(PORTC, EN);
  sbi(PORTC, LATCH);
  PORTD = (1 << rowNum);//(1 << rowMap[rowNum]);
  cbi(PORTC, EN);
}

//General short delays
void delay_ms(uint16_t x)
{
  uint8_t y, z;
  for ( ; x > 0 ; x--){
    for ( y = 0 ; y < 4 ; y++){
      for ( z = 0 ; z < 40 ; z++){
        asm volatile ("nop");
      }


    }
  }
}

there is a multiplexing...

but, to conclude, if I take an external power supply about 12V / 2A to be safer, I guess all could work safely...?! couldn't it?

180R is a writing system I don't know..

You do now :slight_smile:

there is a multiplexing...

Yes multiplexing is turning things on an off rapidly to make it look like they are on all the time. So why bother? Because in this way you control more LEDs with fewer output pins.

if I take an external power supply about 12V / 2A to be safer,

Yes :slight_smile:

I know about multiplexing...

but in this particular case, I just would like to know about currents (I'm more in the code than in the hardware :wink: )

I guess 12V/2A would fit very well and be safe!

thx a lot!

If you are multiplexing then you have a ratio of on to off time, this is called the duty cycle. If you have a duty cycle of say 50% then with an LED taking 20mA it will only look as bright as an LED running 10mA. Therefore you can boost the current (by dropping the resistor value) to make the LED take 40mA or so. This boosting has to be within the peak current rating of both the LED and the driver. If the software crashes and you stop multiplexing with an LED on then you could burn something out.

I guess 12V/2A would fit very well and be safe!

the 2A is the maximum current the supply can deliver.
However, if you have 100R resistors and connect your LED to 12V then you will be drawing 103mA per LED which is way too much. So you need to either increase the resistor (just put another one in series with the existing ones) or reduce the input to 5V.

Are you going to use that schematic and those LEDs to make your own matrix?

In that schematic it shows Vcc but this HAS to be 5V otherwise you will blow up all the chips. This is not the same as Vin on the Arduino.
Also note that only up to 8 * 3 = 24 LEDs will be on at any one time so that's all you need to consider in your calculations.

Ok

but I guess if I use 12V / 2A, it would be ok
I read on http://arduino.cc/en/Main/ArduinoBoardDiecimila that input voltage recommended is about 7 / 12 V
I guess all the voltage after the voltage regulator are 5v... even for digital pin out etc etc

Yes BUT the internal regulators on the Arduino board can't supply the current you need. Therefore you are going to need a other source of power at 5V to supply the LEDs.

Grumpy_Mike, ok.

I could use an external power for the backpack/leds with their own Vcc + Gnd

AND

the usb for the arduino + 164 & 165 shiftregisters used for buttons.

the external power supply has to fit with 5V / 2A
the usb is already 5V and ok!

Does that make more sense now?
I guess.. yes :smiley:

the "problem"=> find a 5V / 2A power supply

Yes that makes more sense.

As they are just LEDs then it doesn't have to be exactly 5V, you might get a 6.5V supply easer.

with their own Vcc + Gnd

Make sure you connect the GND on this power supply to the GND on the Arduino. That seems to be the most common form of mistakes on the board.

okay.
all grounds together!

but they aren't just leds.
I mean, there is the backpack (it needs 5V) that drives the leds:

you know, I understand more the firmware/code questions than current questions ... I'm ashame about that. but I like to learn.

The back pack (as you call it) is the driver circuits for the LEDs. All IC on this need 5V with the exception of pin 10 of the darling ton drivers. This is the path that the LEDs get there power from. If you are going to supply JUST the LEDs you will have to inject the power here and disconnect it from the rest of the circuit. However, this is probably too much for you to do so best bet is to revert to the original idea of having and extra 5V supply for the back pack.

I'm ashame about that. but I like to learn.

If you like to learn then there is nothing to be ashamed of.

I used to tell my students that "ignorance is the prerequisite of learning", some of them were very well qualified. :slight_smile:

We have lit a RGB matrix with diecilmila like board (seeeduino). It's USB power supplied only, no external resistor applied, both 3.3V and 5V worked fine. This is a partial demo, only 2 rows are under full controlled, the rest are just lid by IO port. We didn't measure the current, but it should be working find with USB power.

Results as: Ssssssuper bright RGB matrix 8*8 - Latest Open Tech From Seeed

BTW, we are planning for designing a backpack other than the Sparkfun way, please let us know if any favors, thanks! :slight_smile:

seeedstudio,
your leds are like mine ?
how could you use only 5V ?

I really have lacks/problmes with electricity ... (I studied that, 10 years ago, but..)
the USB cannot drive more than 500mA...
all your leds require less than 500mA?

Here is the spec: http://www.seeedstudio.com/depot/datasheet/2088RGBMatrix.pdf

I think they should be quite similar but not exactly the same. We tried 3.3V, it worked fine too. 5V is too bright for close look.

For the current calculation, you should divide it by the frequency if dynamic scan. They are not lit 100% time or 100% output, the actually result should be well below 20ma each.

Let me measure the actual current consumption and post the result later.

Hi seeedstudio,
juilenb is not using an LED matrix but separate LEDs, data here:-

You should really not use LEDs without resistors as you are then relying on the driving circuits to go into current limit and this will most likely stress them. It will work, but not for very long or reliably. That is why you say the 5V was too bright, much longer and they probably would have gone out.

For the current calculation, you should divide it by the frequency if dynamic scan

It is not the scan frequency that matters at all, it is the ratio of on to off time. This should be expressed as a percentage and used to calculate the average current.
I was making the point that this not only cuts down the current but also cut down the brightness and so you might have to increase the current even further to componsate.
Measuring the current of a multiplexing display is tricky because you have a rapidly varying current and most current meters will not give you an accurate measure of this. At best a moving coil meter will show the average current not the peak current which is what you want in this situation.
The best way to measure the current is by looking at the voltage across an in line resistor, then you can see exactly what is happening.

Hi Mike: Thank you for the correction.

IMHO, the LED dot matrix is an assembled RGB LED matrix, so I think it could be of reference. And, could we see ratio of on to off time as the inverse of scan frequency? For the brightness, is it linear relation with duty rate too? I think human eyes might have some weakness distinguishing multiplexing trick... Not sure again, a controlled experiment is needed:(

We are testing the Matrix by this simple and rash way, taken assumption that the limitation of 500ma current limit would ensure the dot-matrix's safety.

Your suggestion on the current measurement is helpful, we would do it this way :slight_smile:

Lastly, apologize for not reading the post throughoutly, I read a comment on my flickr pic and it leads me here. My pleasure to join the discussion! ^^

Grumpy_Mike, to conclude, what do you advice me?

I need the easiest way.
A guy (Brian: http://www.viddler.com/explore/dioioib/videos/9/) uses exactly the same stuff and uses only the usb power...!
without problem...
I don't understand..

I put the code from the atmega8 on the backpack
I should dive into it deeper... multiplexing is in it!