Go Down

Topic: LEDS change colour fine when powered with USB, not via VIN (Read 816 times) previous topic - next topic

abasel

If I am reading the documentation correctly, you can power a Nano V3 via VIN using 6-20V power source.

When I run the following project powered via the USB it works fine. When I try via a 12V power supply via VIN, the LEDs start changing but then get stuck somewhere in the RED->PURPLE loop - it appears not to move to the next colour range.



Code: [Select]
/* Remember to change LED_COUNT to the number of led's on your strip, currently set to 14.
   Pin 2 to ground will pause at the color
   Pin 3 to ground will cycle the colours slower - PIN 3 High (default) will cycle fast.
*/


#include <EEPROM.h>
#include <FastLED.h>
#define DATA_PIN 12
#define LED_COUNT 12 //104
#define COLOR_ORDER GRB

int colour_buttonPin = 2;     // Pause the colours
int colour_buttonState = 0;

int speed_buttonPin = 3; // Speed button
int speed_buttonState = 0;

bool paused = false;
byte colour_state = '0';

bool is_red = true;
bool is_blue = false;
bool is_green = false;
bool is_green_2 = false;
bool is_yellow = false;
bool is_yellow_2 = false;
int colorStep = 0;
int r;
int g;
int b;
int delay_speed;
int counter;

CRGB leds[LED_COUNT];

void setup() {
  Serial.begin(9600);

  delay_speed = 100;

  FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, LED_COUNT);
  
  pinMode(colour_buttonPin, INPUT_PULLUP);

  pinMode(speed_buttonPin, INPUT_PULLUP);


}

void loop() {
   Serial.print("Colour state: "); Serial.print(colour_state);Serial.print(" - Paused: "); Serial.print(paused);Serial.print(" - colour_buttonState: "); Serial.print(colour_buttonState);Serial.print(" - Delay Speed: "); Serial.println(delay_speed);
  colour_buttonState = digitalRead(colour_buttonPin);
  speed_buttonState = digitalRead(speed_buttonPin);

  if (speed_buttonState == LOW) {
    delay_speed = 0;
  } else {
    delay_speed = 50;
  }
  if (colour_buttonState == LOW) {
    delay(500);
    if (!paused) {
      FastLED.clear();
      paused = true;
    } else {
      FastLED.show();
      paused = false;
    }

  }
  else {

    // RED -> PURPLE
    if (is_red == true) {
      colour_state = 0;
      if (colorStep <= 255) {
        r = 255;
        g = 0;
        b = colorStep;
        colorStep++;
      } else {
        if (is_red == true && is_blue == false && is_green == false && is_green_2 == false && is_yellow == false && is_yellow_2 == false) {
          is_red = false;
          is_blue = true;
          colorStep = 255;
        }
      }
    }

    // PURPLE -> BLUE
    if (is_blue == true) {
      colour_state = 1;
      if (colorStep >= 0) {
        r = colorStep;
        g = 0;
        b = 255;
        colorStep--;
      } else {
        if (is_blue == true && is_red == false && is_green == false && is_green_2 == false && is_yellow == false && is_yellow_2 == false) {
          is_blue = false;
          is_green = true;
          colorStep = 0;
        }
      }
    }

    // BLUE -> TURQUOISE
    if (is_green == true) {
      colour_state = 2;
      if (colorStep <= 255) {
        r = 0;
        g = colorStep;
        b = 255;
        colorStep++;
      } else {
        if (is_green == true && is_red == false && is_blue == false && is_green_2 == false && is_yellow == false && is_yellow_2 == false) {
          is_green = false;
          is_green_2 = true;
          colorStep = 255;
        }
      }
    }

    // TURQUOISE -> GREEN
    if (is_green_2 == true) {
      colour_state = 3;
      if (colorStep >= 0) {
        r = 0;
        g = 255;
        b = colorStep;
        colorStep--;
      } else {
        //Serial.println(is_green_2);
        if (is_green_2 == true && is_red == false && is_blue == false && is_green == false && is_yellow == false && is_yellow_2 == false) {
          is_green_2 = false;
          is_yellow = true;
          colorStep = 0;
        }
      }
    }

    // GREEN -> YELLOW
    if (is_yellow == true) {
      colour_state = 4;
      if (colorStep <= 255) {
        r = colorStep;
        g = 255;
        b = 0;
        colorStep++;
      } else {
        if (is_yellow == true && is_red == false && is_blue == false && is_green_2 == false && is_green_2 == false && is_yellow_2 == false) {
          is_yellow = false;
          is_yellow_2 = true;
          colorStep = 255;
        }
      }
    }

    // YELLOW -> RED
    if (is_yellow_2 == true) {
      colour_state = 5;
      if (colorStep >= 0) {
        r = 255;
        g = colorStep;
        b = 0;
        colorStep--;
      } else {
        if (is_yellow_2 == true && is_red == false && is_blue == false && is_green_2 == false && is_green_2 == false && is_yellow == false) {
          is_yellow_2 = false;
          is_red = true;
          colorStep = 0;
        }
      }
    }

  }

  for (int x = 0; x < LED_COUNT; x++) {
    leds[x] = CRGB(r, g, b);
  }

  delay(delay_speed);
  if (!paused) {
    FastLED.show();
  }


}

Wawa

Power/heat generated in the 5volt regulator is voltage difference times current draw.
So with a larger voltage difference, you can draw less current from the 5volt pin.

With 12volt on V-in, you can only draw about 50mA from the 5volt pin (drive one RGB LED).
Trying to power a LED strip will overheat the 5volt regulator, and it will shut down (if you're lucky).

With 6volt on V-in, you might just be able to power the 12 LEDs.
Leo..

Paul__B

If I am reading the documentation correctly, you can power a Nano V3 via VIN using 6-20V power source.
Reading the documentation correctly.  :smiley-lol:

Problem is ...

Documentation is wrong!  :smiley-eek:

The obsolete tutorials on the Arduino site and others imply that the largely ornamental "barrel jack" and "Vin" connections to the on-board regulator imply that this is a usable source of 5 V power.  This is absolutely not the case.  It is essentially only for demonstration use of the bare board back in the very beginning of the Arduino project when "9V" power packs were common and this was a practical way to power a lone Arduino board for initial demonstration purposes.  And even then it was limited because an unloaded 9 V transformer-rectifier-capacitor supply would generally provide over 12 V which the regulator could barely handle.

When I run the following project powered via the USB it works fine. When I try via a 12V power supply via VIN, the LEDs start changing but then get stuck somewhere in the RED->PURPLE loop - it appears not to move to the next colour range.
Entirely predictable.

You need to figure out the power requirements of the LED strip.  For 12 LEDs each using up to 60 mA, that is 720 mA.  A common "phone charger" rated at either 1, 2.1 or 3.1 A should be fine, but I am not sure whether the diode between the USB socket and the 5 V pin can handle that much.  Best to supply the 5 V direct to the LED strip, then bring the three wires from that strip back to the Nano 5 V, ground and data connections.  Keep the wires together and do not forget the 1 mF capacitor across the LED power input.

You only need jumpers between the two middle points of the power rails on the solderless breadboard if there is a break in the red and blue lines,

abasel

@Paul__B many thanks for that details description. The only capacitor that I can find in may bag of tricks is a 2.2 µF (50V). Will this work or do need to buy the 1mF and with a lower voltage? Or would a 1000 µF, 6.3V or higher work?

Paul__B

The 1000 µF (i.e., 1 mF) would be appropriate.  For 5 V operation, 6.3V rating is fine.  Any higher voltage rating is of course, fine too, but unnecessarily bulky.

abasel

The 1000 µF (i.e., 1 mF) would be appropriate.  For 5 V operation, 6.3V rating is fine.  Any higher voltage rating is of course, fine too, but unnecessarily bulky.
:-[ Thanks.. I was confusing µ and m ... its all working like a dream now. I added a step down transformer and draw all power from that.

DrAzzy

Glad it's working.

As an aside:

With just 12 LEDs, that cap doesn't need to be the full 1000uF. Doesn't hurt to use it, but you could easily get by with a 100uF cap (mostly relevant if you're making piles of these).

For longer strips, you want the larger cap. I think the 1000uF size was chosen as a "worst case" value when Adafruit wrote their guide that recommended it, as a value that almost-no-matter-what will be enough, with an eye towards eliminating the burden on their tech support people from problems that could be fixed with a bigger filter on the power supply.

To be perfectly honest, I routinely get away with far less capacitance on the power rails of WS2811 LED strings - as in,just the 47uF caps on the output of the buck converters powering each 50-light section; have almost 2-dozen such sections, have run them for about half a dozen 2 or 3-day events, and have never had unexpected behavior (at least due to hardware - software bugs are another matter, naturally).
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Paul__B

It is an interesting consideration as to why you need such a (large) decoupling capacitor in any case.

What is special about the first LED?  Only the connections to the controlling microprocessor, and if wired correctly to that (i.e., separate signal and ground wires from the first LED to the microcontroller so that the power supply ground current does not affect the signal), it should make no difference how many LEDs follow.

If a reservoir is needed, it should arguably be distributed along the LED strip (and that is why each LED has a 100 nF capacitor) so there should be many of them, every 10 or 20 LEDs.  We get back to the importance of parallel feeding of the power every 30 LEDs (0.18 A), which is probably more important than the capacitors.  We presume the power supply has adequate buffering capacitance to perform its job.

The question also is whether the PWM on the LEDs tends to synchronise in any way, possibly at the moment of initialisation which is understood to be determined when the data stream ceases.  Once the PWM of individual LEDs becomes random (and presuming they do not tend in some way to synchronise themselves from the fluctuations in the supply voltage caused by others) then the fluctuations in the current draw will automatically tend to even out, minimising the requirement for the (large) decoupling capacitor.  And if they did only re-synchronise at the end of the data stream, then it would not affect the loading of data anyway.


Go Up