Neopixel flicker/error with different power supply

Hi,
Hope someone can help me :S
I have programmed some neopixels with the neopixel lib on a photon.

Works fine when run with 1,5A USB plug directly through the Photon.
Can not run with full brightness because of the low amp availability.

When I change to a larger 40A 5V power supply something strange happens.
the photon starts up normal and I have full connectivity through Blynk and Particle Web IDE.
But the neopixels behave strangely… look at the two videos in the dropbox link.
You won’t be unsure of which video is the normal operation and witch is the … not normal…

Also. Can anybody tell me why there sometimes in the normal operation is two pulses of light after the LEDs have turned on?

Drobboxlink: https://www.dropbox.com/sh/kfd5tvl5nok10f3/AAArKLIWTCpdoSdk2Ls4zSSLa?dl=0

Code:
(I know its not pretty, still in test fase;)
The only thing in use is down around the loop :wink:
(some of the includes in the code look funny in the preview)

#include <neopixel.h>
#include <OneWire.h>
#include "DS18.h"
#include "blynk.h"
#define WidgetLED_h 
#include <Blynk/BlynkWidgetBase.h>

//#define BLYNK_TIMEOUT_MS     10000UL

int r,g,b,led_brightness=127,s=20,Vent_Val;
//int lit=0;
DS18 sensor(D6);
//WidgetLED Leak_LED(V53);
uint8_t addr1[8] = { 0x28, 0xF2, 0x17, 0x1D, 0x07, 0x0, 0x0, 0xF0 }; // Rum Temp
uint8_t addr2[8] = { 0x28, 0x3D, 0x40, 0x29, 0x07, 0x0, 0x0, 0xC9 }; // Seng venstre
uint8_t addr3[8] = { 0x28, 0xFB, 0x5E, 0x2A, 0x07, 0x0, 0x0, 0xB2 }; // Seng Højre
uint8_t addr4[8] = { 0x28, 0xFB, 0x5E, 0x2A, 0x07, 0x0, 0x0, 0xB2 }; // Radiator Temp
float tempVal,tempHDDAw,tempRumAw;
char auth[] = "###";
unsigned long tid,tid2;
bool Led_status;

SYSTEM_MODE(AUTOMATIC);
#define PIXEL_PIN D5
#define PIXEL_COUNT 44
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void rainbow(uint8_t wait);
uint32_t Wheel(byte WheelPos);


uint8_t red(uint32_t c);
uint8_t green(uint32_t c);
uint8_t blue(uint32_t c);
void colorWipe(uint32_t c, uint8_t wait);
void pulseWhite(uint8_t wait);
void rainbowFade2White(uint8_t wait, int rainbowLoops, int whiteLoops);
void whiteOverRainbow(uint8_t wait, uint8_t whiteSpeed, uint8_t whiteLength);
void fullWhite();
void rainbowCycle(uint8_t wait);
/*
//Define Variables we'll be connecting to for PID Control
double Setpoint, Input, Output;
//Define the aggressive and conservative Tuning Parameters
double aggKp=4, aggKi=0.2, aggKd=1;
double consKp=1, consKi=0.05, consKd=0.25;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, PID::DIRECT);
*/
int number = 44;


void setup()
{
    Serial.begin(9600);
    delay(5000); // Allow board to settle
    WiFi.setCredentials("Paradis", "HLv-DH2-D9>-GJZ-Jdx-LKd");
    Blynk.begin(auth);
    Particle.syncTime();
    //Particle.disconnect();
    Blynk.virtualWrite(V9,LOW);
    pinMode(D0, OUTPUT);
    pinMode(D5, OUTPUT);
    pinMode(D1, INPUT_PULLDOWN); //knap til tænd/sluk led
    analogWrite(0,100);Blynk.virtualWrite(V42, 100);
    Blynk.virtualWrite(V9,1);
    
    //initialize the variables we're linked to
    //Input = analogRead(0);
    //Setpoint = 100;
    //turn the PID on
    //myPID.SetMode(PID::AUTOMATIC);
    
    strip.begin();
    colorWipe(strip.Color(0, 0, 0), 1); // turn LED off
    strip.show();
    Led_status=0;
    tid,tid2=millis();
}
BLYNK_WRITE(9) {
    if (param.asInt()) {
        Particle.connect();
        Particle.syncTime();
        //#define BLYNK_TIMEOUT_MS     30000UL
    } else {
        Particle.disconnect();
        //#define BLYNK_TIMEOUT_MS     10000UL
        
    }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

void Read_Sensors(){
        tempHDDAw = 0;
        tempRumAw = 0;
        Sensor_Read1();
        Sensor_Read2();
        Sensor_Read3();
        Sensor_Read4();
        Blynk.virtualWrite(V18,tempRumAw / 3);
        Blynk.virtualWrite(V19,tempHDDAw / 4);
}
void Sensor_Read1(){
        if (sensor.read(addr1)) {
            tempVal = sensor.celsius();
            BLYNK_LOG("Rum Øverst : %.2f°C ", tempVal);
            Blynk.virtualWrite(V11,tempVal);
            tempRumAw += tempVal;
        }
}
void Sensor_Read2(){
        if (sensor.read(addr2)) {
            tempVal = sensor.celsius();
            BLYNK_LOG("Rum Nederst: %.2f°C ", tempVal);
            Blynk.virtualWrite(V12,tempVal);
            tempRumAw += tempVal;
        }
}
void Sensor_Read3(){
        if (sensor.read(addr3)) {
            tempVal = sensor.celsius();
            BLYNK_LOG("Rum Forrest: %.2f°C ", tempVal);
            Blynk.virtualWrite(V13,tempVal);
            tempRumAw += tempVal;
        }
}
void Sensor_Read4(){
        if (sensor.read(addr4)) {
            tempVal = sensor.celsius();
            BLYNK_LOG("HDD Ø : %.2f°C ", tempVal);
            Blynk.virtualWrite(V14,tempVal);
            tempHDDAw += tempVal;
        }
}

//                                                          From here and down is the Blynk and LED code.

BLYNK_WRITE(V34) { // On board LED control
    if(param.asInt() == 1){
        RGB.control(true);
    }else{RGB.control(false);}
        Led_status=1;
}
BLYNK_WRITE(V33) { // LED Brightness
    led_brightness = param.asInt();
    int r2 = (r*led_brightness)/100;
    int g2 = (g*led_brightness)/100;
    int b2 = (b*led_brightness)/100;
    led_on(r2,g2,b2,s);
}
BLYNK_WRITE(V30) { // LED delay
    s = param.asInt();
}
BLYNK_WRITE(V31) { // RGB wheel
    /*r = param[0].asInt();
    g = param[1].asInt();
    b = param[2].asInt();*/
    r = (param[0].asInt()*led_brightness)/100;
    g = (param[1].asInt()*led_brightness)/100;
    b = (param[2].asInt()*led_brightness)/100;
    led_on(r,g,b,s);
}
BLYNK_WRITE(V32) {
    Vent_Val = param.asInt();
    if(Vent_Val<45){analogWrite(0,0);}else{analogWrite(0,Vent_Val);}
}
BLYNK_WRITE(V35) { // Red
    r = (255*led_brightness)/100;
    g = 0;
    b = 0;
    led_on(r,g,b,s);
}
BLYNK_WRITE(V36) { // Green
    r = 0;
    g = (255*led_brightness)/100;
    b = 0;
    led_on(r,g,b,s);
}
BLYNK_WRITE(V37) { // Blue
    r = 0;
    g = 0;
    b = (255*led_brightness)/100;
    led_on(r,g,b,s);
}
BLYNK_WRITE(V38) {
    r = (30*led_brightness)/100;
    g = (30*led_brightness)/100;
    b = (30*led_brightness)/100;
    led_on(r,g,b,s);
}
BLYNK_WRITE(V40) {
    led_off(20);
}


BLYNK_WRITE(V39) {
    rainbowCycle(10);
    Led_status=1;
}


void rainbow_stop(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, 0);
    }
    strip.show();
    delay(wait);
  }
}

void led_on(int R,int G,int B,int S){ // Turn LED on or change color
    int midt = 22;
    int t=43;
    int v=midt;
    int h=midt-1;
    while(v-2<=t){
        if( v <=t)             strip.setPixelColor(v,   (R/3),    (G/3),   (B/3));
        if(v-1>=midt && v-1<=t)strip.setPixelColor(v-1, (R/3)*2,  (G/3)*2, (B/3)*2);
        if(v-2>=midt && v-2<=t)strip.setPixelColor(v-2,  R,        G,       B);
        if( h >=0)             strip.setPixelColor(h,   (R/3),    (G/3),   (B/3));
        if(h+1<midt && h+1>=0) strip.setPixelColor(h+1, (R/3)*2,  (G/3)*2, (B/3)*2);
        if(h+2<midt && h+2>=0) strip.setPixelColor(h+2,  R,        G,       B);
        strip.show();delay(S);
        v++;
        h--;
    }
    Led_status=1;
}
void led_off(int S){ // Turn off LED 
    int midt = 22;
    int v=43;
    int h=0;
    while(v+2>=midt){
        if( v >=midt)           strip.setPixelColor(v,   (r/3),    (g/3),   (b/3));
        if(v+1<=43 && v+1>=midt)strip.setPixelColor(v+1, (r/3)*2,  (g/3)*2, (b/3)*2);
        if(v+2<=43 && v+2>=midt)strip.setPixelColor(v+2,  0,        0,       0);
        if( h < midt)           strip.setPixelColor(h,   (r/3),    (g/3),   (b/3));
        if(h-1>=0 && h-1<midt)  strip.setPixelColor(h-1, (r/3)*2,  (g/3)*2, (b/3)*2);
        if(h-2>=0 && h-2<midt)  strip.setPixelColor(h-2,  0,        0,       0);
        strip.show();delay(S);
        v--;
        h++;
    }
    Led_status=0;r=0;g=0;b=0;
}

void loop()
{
    Blynk.run();
    if(digitalRead(D1)==HIGH){
        if(Led_status==1)
            led_off(20);
        else{
            led_on(50,0,0,20);
            r=50;g=0;b=0;}
    }
    
}

//                                                          Until here is the Blynk and LED code.

void printDebugInfo() {
  // If there's an electrical error on the 1-Wire bus you'll get a CRC error
  // Just ignore the temperature measurement and try again
  if (sensor.crcError()) {
    Serial.print("CRC Error ");
  }

  // Print the sensor type
  const char *type;
  switch(sensor.type()) {
    case WIRE_DS1820: type = "DS1820"; break;
    case WIRE_DS18B20: type = "DS18B20"; break;
    case WIRE_DS1822: type = "DS1822"; break;
    case WIRE_DS2438: type = "DS2438"; break;
    default: type = "UNKNOWN"; break;
  }
  Serial.print(type);

  // Print the ROM (sensor type and unique ID)
  uint8_t addr[8];
  sensor.addr(addr);
  Serial.printf(" ROM=%02X%02X%02X%02X%02X%02X%02X%02X",addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], addr[6], addr[7]);

  // Print the raw sensor data
  uint8_t data[9];
  sensor.data(data);
  Serial.printf(
    " data=%02X%02X%02X%02X%02X%02X%02X%02X%02X",
    data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8]
  );
}
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }




}
uint8_t red(uint32_t c) {
  return (c >> 8);
}
uint8_t green(uint32_t c) {
  return (c >> 16);
}
uint8_t blue(uint32_t c) {
  return (c);
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256 * 5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< number; i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / number) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

Hello,

Let me ping of the Elites who might be able to help, @wgbartley are you able to give some insight?

Kyle

It’s possible that the 40A supply is noisier than the 1.5A supply. You may want to try some of the suggestions in Adafruit’s best practices. I’d suggest the capacitor and resistor first. If those don’t work, try the level shifter.

1 Like