Code for WS2811 addressable LED

I am using Adafruits NeoPixel library to drive a string of WS2811 addressable LED's. It works fine on an Amazon Nano look alike based on the Atmel Atmega328P-AU MCU. When I compile and load on the Nano Every ATMEGA4809 I get the error message:
avrdude: jtagmkII_initialize(): Cannot locate "flash" and "boot" memories in description
which appears to be a warning and should not be an issue.
When I run the code I get improper operation of the LED's. I am assuming that the Adafruit_NeoPixel library needs to be updated for the Nano Every. Has anyone else had issues and is there an updated library somewhere that works on the Nano Every?

What do you mean by improper operation? Last time I tried it, Adafruit neopixel worked on the Nano Every, FastLED does not.

The test string I am using is 5 LED's. LED 4 & 5 come ON and stay ON when I power up.
When I turn ON LED 1 for Red it comes on Green and flickers.
When I turn ON LED 2 for Red LED 1 comes ON Red with a fast flicker and LED 2 Red with a slower flicker.
When I turn ON LED 3 for Red LED 1 comes ON Blue with a fast flicker and LED 2 Blue with a slower flicker.
When I turn ON LED 4 for Red LED 1 comes ON cycling colors with a fast flicker and LED 2 cycling colors with a fast flicker, and LED 3 cycling colors with a fast flicker.

Hello DonMcDonald,

Could you possibly upload the code that you are using to test the LEDs and a picture or illustration of the circuit you have?

Thanks,
Matt

It is configured as:
Board - Arduino Nano Every
Registers emulation - None (ATMEGA4809)
I also tried the ATMEGA328 emulation with no success.
This code does work on an Arduino Pro-Mini.

Compile Results:
Sketch uses 4264 bytes (8%) of program storage space. Maximum is 49152 bytes.
Global variables use 203 bytes (3%) of dynamic memory, leaving 5941 bytes for local variables. Maximum is 6144 bytes.
avrdude: jtagmkII_initialize(): Cannot locate "flash" and "boot" memories in description

The test code is:
// This program receives a string of numbers separated by commas.
// It is a demo for an Arduino Nano Every wired to 5 addressable LED's (WS2812).
// Sending the numbers 1-5 will light the corresponding LED.
// Sending 100 will turn all LED's OFF.

#include <Adafruit_NeoPixel.h>

#define PIN 2
uint32_t Lcolor = 0xFF0000;
int LEDnum = 0;
int numLED = 5;

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numLED, PIN, NEO_RGB + NEO_KHZ800);

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

void loop() {
while (Serial.available() > 0) {
LEDnum = Serial.parseInt();
if (LEDnum != 0) {
if (LEDnum == 100) {
alloff();
strip.show();
}
if (LEDnum < 100) {
LEDnum = LEDnum-1;
strip.setPixelColor(LEDnum, Lcolor);
strip.show();
}
}
}
}

// Turn OFF all LEDs
void alloff() {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, 0x000000);
}
}

Hello DonMcDonald,

I used a tweaked version of your code and tested it on some Neopixels that I have.

It worked fine for my Nano 33 BLE Sense and I compiled it without the error/warning you got for the Nano Every so I am assuming that would work ok too.

Here is the code, I made a few tweaks and removed the alloff function:

#include <Adafruit_NeoPixel.h>

#define PIN 2

int LEDnum = 0;
int numLED = 5;
//Adafruit_NeoPixel strip(numLED, PIN, NEO_RGB + NEO_KHZ800); 
Adafruit_NeoPixel strip(numLED, PIN, NEO_GRB + NEO_KHZ800); // I was using Neopixels so I had to switch this.

//uint32_t Lcolor = 0xFF0000;
uint32_t Lcolor = strip.Color(255, 0, 0);//I find this is an easier way to set colours than using HEX values

void setup() {
  Serial.begin(9600);
  strip.begin();
  strip.setBrightness(255);
  strip.show();//This clears all the LEDs on each reset so you are not left with lingering colours
}

void loop() {
  while (Serial.available()) {
    LEDnum = Serial.parseInt();
    if (LEDnum != 0) {
      Serial.print("Number Entered: ");
      Serial.println(LEDnum);
      if (LEDnum == 100) {
        strip.clear();//clear() is an built in function that serves the same purpose as your function
        strip.show();
      }
      if (LEDnum < 100) {
        LEDnum = LEDnum - 1;
        strip.setPixelColor(LEDnum, Lcolor);
        strip.show();
      }
    }
  }
}

I do have some "knock-off" addressable LEDs in my office and in my experience they work the same with code designed for authentic Neopixels.

Considering all of that, I would double-check a few things:

  • The wiring, some of the colour issues sound like when the signal or common ground isn't wired properly, I know you said it worked on a pro-mini but check nonetheless
  • All libraries and board profiles are up to date, these boards are still relatively new so there are bug fixes from both Arduino and Adafruit that come out from time to time. I used Neopixel 1.3.4 and megaAVR 1.8.5
  • If you have any other addressable LEDs, including Adafruit ones, test those on the Nano Every too

Sorry that I couldn't help more, what brand of addressable LED are you using/where did you get them from?

Matt

1 Like

Matt,

Thank you for your response.
The LED's I was testing on were:

They were not operating correctly.

I then tested on these:

and they worked. So it appears that something is different between the Amazon and Adafruit LED's when it comes to the Nano Every.

How do you attached code in the window?

Hello DonMcDonald,

That is strange, looking at the Adafruit page, the LEDs use the RGB data stream so you would have to use: Adafruit_NeoPixel strip(numLED, PIN, NEO_RGB + NEO_KHZ800) as you did in your code...

Have you tried using a 0.1 μF capacitor between + and ground on each pixel? Adafruit says the following when using what they call Discrete NeoPixel Products:

it’s very strongly recommended that each NeoPixel have an accompanying 0.1 μF capacitor between +V and ground. This prevents communication problems due to brownout of the on-pixel driver logic. It’s occasionally sufficient to have one capacitor between pairs of pixels; some of our NeoPixel rings work that way.

That can be found here. I have never done it before but it might be worth a final shot.

If you try that and it failed and you are absolutely sure everything is wired correctly (I would even try to use different pins for the data signal just to see) then it might be better to contact Adafruit because by all accounts this should work and has worked on other boards/other led configurations.

You can make a code window by clicking the code button </> in the top left-hand corner of the reply box.

Matt

Adding the 0.1uF capacitor actually made it worse.
Not sure what it is about the Nano Every and these LED's. The Arduino Pro-Mini and Amazon Nano look alike work but those have different processors and clock speeds.
I tried a different breadboard with similar bad results. I guess do not pair those particular devices together.

DonMcDonald:
The Arduino Pro-Mini and Amazon Nano look alike work but those have different processors and clock speeds.

The Nano Every runs at 16MHz, even though the box says 20MHz. You have to modify the boards.txt file to change the clock speed. Neopixel will not run at 20MHz without modifications, unless it has been updated recently.

Hello david_2018

Thank you for the information, just to double-check as I have I never looked at the boards.txt myself, are you referring to the line:
nona4809.build.f_cpu=16000000L

which can be found in:
Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.5

Thanks,
Matt

matt_lee_smith:
Hello david_2018

Thank you for the information, just to double-check as I have I never looked at the boards.txt myself, are you referring to the line:
nona4809.build.f_cpu=16000000L

which can be found in:
Documents\ArduinoData\packages\arduino\hardware\megaavr\1.8.5

Thanks,
Matt

That is part of it, there is also a fuse setting to set the internal oscillator to the correct frequency. See this discussion: Clock speed for Nano Every for the details. Its possible to modify the boards.txt file to give a choice of 2, 4, 8, 16, or 20MHz.