NEOPXL8, LEDs glitching by analogRead()

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tomjennings
 
Posts: 102
Joined: Thu Aug 17, 2006 1:21 am

NEOPXL8, LEDs glitching by analogRead()

Post by tomjennings »

I've got a problem where analogRead() causes spurious led LEDs on W2812B strings. This is not a power supply issue. Hardware is a Metro M4, the NEOPXL8 breakout, an external 12V to 5V/30A supply powering the Metro and two 160-LED strings. All is well until I do analogRead(). The supply feeding the 12V/5V converter has a voltmeter and ammeter, there's no droop. Other code in the project lights all 320 LEDs to full brightness without a single hitch, perfect.

I've reduced the project to the test program below. All that it does is init one string (160 LEDs), then runs one lit LED up the string. Current draw is negligible. Also in loop() is an analogRead(). Both are timed using millis(), LED "motion" every 30 mS, analog read every 20.

Increasing analogRead() frequency increases the number of glitches. The green LED (#0) lit is a glitch. If the analogRead() is commented out, it does not happen. If the read is done once per second, you often can't see it at all.

Anyone have any insight here?

Code: Select all

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_NeoPXL8.h>

// NEOPXL8 board on Metro M4 pins.
//
int8_t NEO_PINS[8] = { 7, 6, 5, 4, 3, 2, 10, 11 };
const int LEDS = 160;
Adafruit_NeoPXL8 leds (LEDS, NEO_PINS, NEO_GRB);

long T1, T2;

void setup () {

  leds.begin();
  leds.setBrightness (128);
  for (int i= 0; i < LEDS; i++) {
    leds.setPixelColor (i, 64, 64, 64);
  }
  leds.show();

  T1= millis() + 31;
  T2= millis() + 7;
}

void loop () {
static int p;

  // read analog, spurious LEDs light...
  //
  if (millis() > T2) {
    T2= millis() + 3;
    analogRead (A0);
  }



  // Walk a single lit LED up the string.
  //
  if (millis() < T1) return;
  T1= millis() + 31;
 
  leds.setPixelColor (p, 0);
  if (++p >= LEDS) p= 0;
  leds.setPixelColor (p, 64, 128, 64);
  leds.show();
}

PXL_20211205_000037143.jpg
PXL_20211205_000037143.jpg (258.03 KiB) Viewed 105 times

User avatar
tomjennings
 
Posts: 102
Joined: Thu Aug 17, 2006 1:21 am

Re: NEOPXL8, LEDs glitching by analogRead()

Post by tomjennings »

Hmm thought I could edit my post... corrections & additions:

I'm using a Metro Express board with SAMD21, not an M4. With NEOPXL8 Friend, https://www.adafruit.com/product/3975.

The NEOPXL8 example "strandtest" doesn't actually state pin mappings for Metro M0 Express and Friend, but I'm using the Metro M4 pin map, only two strands, and that works fine, so I'm assuming the pin selection won't have other side effects (famous last words?). However, substituting an M4 board doesn't work, two strands on pins 6, 7 do not light at all. (I wouldn't mind using the M4 though, as I'm doing some audio processing of a microphone, a low-res FFT, and some minor I/O stuff.)



> We recommend using with Arduino Zero or Metro M0 Express, with pins 0-7, that's what our library works best with.

EEP! Just saw this, in a re-read of the NEOPXL8 Friend product page. This isn't mentioned elsewhere. Pins 0, 1? The USB Serial pins? Or has USB Serial been entirely divorced from the old '328 functions entirely?

What on earth does "works best with" mean? Does it work? Or not?

The pin assignment documentation seems a bit of a jumble. Given that it's critical a succinct table with footnoted caveats would be nice.




Nothing in the Friend docs or examples references analog inputs in any way. I tried reading A0..A5 and same results.



The symptom is spuriously-lit LEDs in particular locations, such as LED #0. "Glitch" is incorrect and not meaningful here. Other than the spurious LEDs, the LEDs I do light with setPixelColor() do exactly as they're told. It's the spurious lighting that's odd.

Commenting out analogRead() stops the spurious LEDs. The frequency of spurious LEDs is proportional to the frequency of analogRead().

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”