Adafruit Neopixel Library [PORTED]

Hi @rudyvan, @BDub, the Spark_NeoPixel lib alone, e.g. with a led walk example works fine. I got the latest code up and running :slight_smile: It really just stops working for me once I combine it with some sort of spark-exposed function. What's really strange is that it works for @Bdub now.

So the full code is below. I included the latest Spark_NeoPixel lib from Github, yesterday evening. Here are the "symptoms":

  • Once I flashed the firmware, I can verify that it works. E.g. the LED is flashing and I can check that the spark core exposes the function "lights". I took out the Serial wait function - but that's pretty much the only change.

  • I'll then call the lights function, e..g with 3 - it will turn on the 4 LEDs that should be turned on. But once the function returns, correctly with a 200 response code in this case, the LED triggered in the loop function to signal if spark is fine stops flashing. Spark has halted after the first call.

  • the only way to make it work again is to hit reset. Every function call over the REST API will now yield a "Timed out."

  • also funny: I am pretty sure it worked for a single RGB led - e.g. if I am not trying to toggle 4 at once. The problem is that I later want to toggle NeoPixel Rings with 12 RGB LEDS each - so I need to be able to control 16 Rings (16 is a number defined by my project, I want to toggle the lighting of 16 things...). NeoPixel Ring - 12 x 5050 RGB LED with Integrated Drivers : ID 1643 : $7.50 : Adafruit Industries, Unique & fun DIY electronics and kits

  • the RGB123 LED board I am using right now is this: http://rgb-123.com/product/88-8x8-rgb-led-matrix/ - I checked it twice, these are WS2812B chips. I have this connected to a 4A/5V power supply and I connected the GNDs of Spark and this power supply.

  • I read somewhere that calculating an input to to a function (base+1) is not a good idea. I cannot really understand why, but maybe this could be an issue. I could try at home tonight the next time. BTW I also remember that we once had delay(50) between each setPixelColor call.

I'll be posting a more general question to the forum about spark becoming unresponsive, too. It seems in this case somehow connected with the strip.setPixelColor calls, but I am wondering what the general issue here could be. thx for all your help :slight_smile: I've not given up.

 #include "Spark_NeoPixel.h"
int lights(String command);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(64, D2, WS2812B);
uint16_t channels = 0x0000; // All lights off
bool updateTime = false; // Time to update flag
bool s = false;
void setup() {
  pinMode(D7,OUTPUT);
  digitalWrite(D7,HIGH);
  strip.begin();
  strip.show();
  Serial.begin(9600);
  Spark.function("lights", lights);
  Serial.println("Ready.");
}
void loop() {
  s = !s;
  digitalWrite(D7,s);
  delay(100);
  if(updateTime) updateLights();
}
void updateLights() 
{
  updateTime = false;
  const uint32_t c_on = strip.Color(255, 255, 255);
  const uint32_t c_off = strip.Color(0, 0, 0);
  for (uint16_t i = 0; i < 16; i++)
  {
    uint16_t val = (channels & (1 << i)) ? 1 : 0; // is bit set or clear?
    Serial.print(i, DEC);
    Serial.print("->");
    Serial.print(val, DEC);
    Serial.print(" BASE: ");
    //strip.setPixelColor(i, (val == 1) ? c_on : c_off);
    uint16_t base = i * 4;
    Serial.println(base, DEC);
    delay(50);
    strip.setPixelColor(base, (val == 1) ? c_on : c_off);
    strip.setPixelColor(base+1, (val == 1) ? c_on : c_off);
    strip.setPixelColor(base+2, (val == 1) ? c_on : c_off);
    strip.setPixelColor(base+3, (val == 1) ? c_on : c_off);      
  }
  strip.show();
}
int lights(String command) 
{
  Serial.println("lights called with command " + command);
  delay(100);
  if(command.length() == 0)
    return -1;
  uint16_t number = command.toInt();
  if(number > 15)
    return -2;
  channels ^= (1 << number); // toggle the bit (0 - 15)
  updateTime = true;
  return 200;
}