Black Lives Matter - Action and Equality. ... Adafruit joins the Stop Hate for Profit campaign.
0

Starting Simple with Neopixel and Flora
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Starting Simple with Neopixel and Flora

by zjdoliver on Thu Feb 27, 2020 12:05 pm

Hi,

I have 2 questions that I hope someone can answer...

1) Flora v3 with 2 Neopixels v2 chained - I soldered wires between the flora and a chain of 2 neopixels for now. I uploaded the test program to have the pixels go thru various colors etc... the Flora pixel is working but the 1st neopixel is always white while the 2nd pixel does not turn on at all. I swapped out neopixels and the same result occurs. I have the wires connected to:
VBat - I have this connected via USB, not battery
#6 - i'm assuming any of the numbers are usable but if this is the wrong assumption please let me know
GND

2) Can anyone share code to simply eliminate the Flora Pixel and all the chained Neopixels the same color?

Thanks

zjdoliver
 
Posts: 7
Joined: Tue Feb 25, 2020 6:48 pm

Re: Starting Simple with Neopixel and Flora

by dastels on Thu Feb 27, 2020 12:26 pm

Can you post a clear photo of your connections (both the Flora and the Neopixels as well as your code.

Dave

dastels
 
Posts: 2755
Joined: Tue Oct 20, 2015 3:22 pm

Re: Starting Simple with Neopixel and Flora

by zjdoliver on Thu Feb 27, 2020 12:55 pm

Hi, thanks for the quick response...

Not the prettiest but just getting an initial understanding and working prototype.
20200227_113748.jpg
20200227_113748.jpg (447.58 KiB) Viewed 87 times

20200227_113732.jpg
20200227_113732.jpg (378.37 KiB) Viewed 87 times


I just used the code that was provided on the website for not but my question was to see if anyone can provide simple code that will illuminate all pixels with one color. I want to simplify and then build on with more complexity over time.

#include <Adafruit_NeoPixel.h>

#define PIN 8

Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
strip.begin();
strip.setBrightness(50);
strip.show(); // Initialize all pixels to 'off'
}

void loop() {
// Some example procedures showing how to display to the pixels:
// setColorForAllPixels(strip.Color(50, 50, 50));
colorWipe(strip.Color(255, 255, 255), 500); // White
colorWipe(strip.Color(255, 0, 0), 500); // Red
colorWipe(strip.Color(0, 255, 0), 500); // Green
colorWipe(strip.Color(0, 0, 255), 500); // Blue
rainbowCycle(20);
}

// 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< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}

zjdoliver
 
Posts: 7
Joined: Tue Feb 25, 2020 6:48 pm

Re: Starting Simple with Neopixel and Flora

by kcl1s on Thu Feb 27, 2020 1:48 pm

You have the data pin of your external pixels tied to D6. Your code is for the onboard pixel D8. For the external pixels in the IDE go to menu selection File/examples/Adafruit Neopixels/strandtest. Set the LED_PIN to 6 and LED_COUNT to 2. Then load the code. This guide talks about all things Neopixel. https://learn.adafruit.com/adafruit-neopixel-uberguide

Hope this helps.

Fellow hobbyist
Keith

kcl1s
 
Posts: 1511
Joined: Tue Aug 30, 2016 12:06 pm

Re: Starting Simple with Neopixel and Flora

by kcl1s on Thu Feb 27, 2020 2:10 pm

I just used the code that was provided on the website for not but my question was to see if anyone can provide simple code that will illuminate all pixels with one color. I want to simplify and then build on with more complexity over time.


Here is the simple code example you asked for.

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>

#define PIN 6
#define NUMPIXELS 2
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

//variables to set for neopixel color
//valid numbers are 0-255
//mix values to create other colors
int R = 125;
int G = 0;
int B = 0;

void setup() {

  pixels.begin();
  pixels.show(); // Initialize all pixels to 'off'

  //puting this in void setup() so it only runs once.
  //If you want code to change pixels put code in void loop()
  //so it runns over and over. Look at strandtest example
  for(int i = 0; i < NUMPIXELS; i++) { //loop through pixels
    pixels.setPixelColor(i, R, G, B); //set all to same color
  }
  pixels.show();      //send pixel color data out to pixel pin
}

void loop() {
  //nothing here
}


Keith

kcl1s
 
Posts: 1511
Joined: Tue Aug 30, 2016 12:06 pm

Re: Starting Simple with Neopixel and Flora

by zjdoliver on Thu Feb 27, 2020 2:41 pm

Thank you so much Keith!

Making progress, i have a few questions...

1) The Flora Pixel is always green and doesn't change when I change the code. This might be normal and isn't a deal breaker for me but just curious if I have to control that differently.
2) the 2nd Neopixel changes when i modify the color in the code but the 1st Neopixel is always white and does not change. Actually when I set color to 255,255,255 the 2nd neopixel has a very slight blue to it and not as white as the 1st neopixel

again, thank you for helping me

zjdoliver
 
Posts: 7
Joined: Tue Feb 25, 2020 6:48 pm

Re: Starting Simple with Neopixel and Flora

by kcl1s on Thu Feb 27, 2020 3:38 pm

The onboard pixel is a separate group of pixel(s) and is controlled separately. This line of code creates a Neopixel "object"
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
in Arduino/C++ code you can create more than one object. Just assign it another name such as obpixel and say how many pixels (1) and pin (8) something like this.
Adafruit_NeoPixel obpixel = Adafruit_NeoPixel(1, 8, NEO_GRB + NEO_KHZ800);
Put this line right under the the first in the code. Then use obpixel.begin(), to initiate the pixel and do the same for setPixelColor and show. You can reuse the R,G,B variables or make 3 more for it. Give it a try and post your code if you get stuck.

As for the white pixel that is a problem. Post a close-up of the pixel wiring and maybe swap out that pixel if you have others.

Keith

kcl1s
 
Posts: 1511
Joined: Tue Aug 30, 2016 12:06 pm

Re: Starting Simple with Neopixel and Flora

by kcl1s on Thu Feb 27, 2020 3:55 pm

I see a jst connector in one of the pics. Is that for power? Make sure the battery voltage is no more than 5 volts as you are powering the pixels via vbatt and they should get no more than 5 volts. Regular USB power should be OK.

Keith

kcl1s
 
Posts: 1511
Joined: Tue Aug 30, 2016 12:06 pm

Re: Starting Simple with Neopixel and Flora

by zjdoliver on Thu Feb 27, 2020 4:08 pm

Thanks again.

I swapped out the 1st pixel and it's working as it should so maybe i fried the other neopixel during soldering.

zjdoliver
 
Posts: 7
Joined: Tue Feb 25, 2020 6:48 pm

Re: Starting Simple with Neopixel and Flora

by dastels on Thu Feb 27, 2020 4:54 pm

Sorry.. I was off distracted by other things. Sounds like it's all under control!

dastels
 
Posts: 2755
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.