Hi everyone,
I used part of @Adam_Haile code here: AllPixel/Firmware.ino at master · ManiacalLabs/AllPixel · GitHub
to make a sketch on ESP8266 so that I can change the number of LEDs at runtime. The number of LEDs that light up is ok. But it is strange, when sinelon pattern runs it seems that there are a few additional LEDs beyond the last one that do not light up (as if you’ve defined NUM_LEDS to be 110 but you actually have 100). I don’t see what is the problem, here’s the code:
#include <ESP8266WiFi.h>
#include “FastLED.h”
#include “EEPROM.h”
#define DATA_PIN 4
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB * leds;
uint16_t NUM_LEDS = 1;
CLEDController * pLed = NULL;
inline void setupFastLED()
{
leds = (CRGB*)malloc(3NUM_LEDS);
memset(leds, 0, 3NUM_LEDS);
pLed = new WS2811Controller800Khz<DATA_PIN, COLOR_ORDER>();
FastLED.addLeds(pLed, leds, NUM_LEDS);
FastLED.clear();
FastLED.show();
}
void setup() {
EEPROM.begin(200);
NUM_LEDS=EEPROM.read(0);
setupFastLED();
}
I’d need to see the rest of your code to make any recommendations about what’s going on – can you post it to something like http://gist.github.com? (Please don’t post large blocks of code in g+ posts - it gets difficult to read/follow - doubly so for someone on mobile devices - gist handles it much better)http://gist.github.com
Thank you Daniel, I had just mentioned part of the code that was related to changing the number of LEDs, Here’s the complete code:
Any advice is appreciated!
You are reading the value NUM_LEDS from EEPROM(0) - however the value that you’re storing in slot zero is brightness - EEPROMupdate(0,BRIGHTNESS);
Also - note that if you change the value for NUM_LEDS after writing the new value into the eeprom you will need to force the device to restart
(And stuff like this is why I ask people to upload entire sketches - where someone thinks the problem is often isn’t correct)
Yes that’s brightness, I’ve made a mobile application for this I just wanted to test if I could change number of LEDs at runtime so I just tried to use brightness for NUM_LEDS (I also restart the device manually after changing it’s value). My problem is that when I set NUM_LEDS (=brightness) to say 100, exactly 100 of LEDs light up, but as I run sinelon pattern it’s as if the code is written for more LEDs but there are 100 physical LEDs. I hope I can convey my message.
This is a video I uploded in case my description is vague. I really don’t know what’s wrong with the code.
The problem is not from the code! I uploaded the same code on my Arduino and it works perfectly. I think there might be something wrong with this library on ESP8266. @Daniel_Garcia , I think you might want to take a look at it.
One more thing, sizeof(leds) in Arduino returns 2 while in ESP8266 it returns 4.
I can try running this on some hardware here over the weekend and see what’s going on. As for your last comment about sizeof - that’s because the type of leds is CRGB* (that is, it is a pointer to CRGB object(s)). On the arduino, a pointer is 16-bits, or 2 bytes, while on platforms like arm and the esp8266 which use 32-bit addressing the size of a pointer is 32 bits, or 4 bytes.
Out of curiosity - does your test app work the way you expect it to if you make NUM_LEDS a constant?
(e.g. #define NUM_LEDS 100 or const int NUM_LEDS=100;)
Also - what happens if you aren’t running wifi? Try making this the first line of your .ino file:
#define FASTLED_ALLOW_INTERRUPTS 0
It is possible something is going on with interrupts that are running long enough that they are blocking you from being able to write more than 100 leds worth of data at a time. (This is a somewhat constant issue with WS2812 leds).
Finally - what if you make a much simpler version of your program that is just one effect, and/or is just an even simpler loop to try to see and narrow down where the problem is — you have a lot going on in your code.
Finally - one possible culprit - @Mark_Kriegsman is it possible that beatsin16 is stepping outside of its bounds on 32 bit, non arm platforms?
(I’ll check on the range of that)
I made NUM_LEDS a constant, but it didn’t solve the problem. And it amazed me! Previously I used ESP-01 and I just used constant NUM_LEDS and as far as I remember everything worked properly like an Arduino (unfortunately I don’t have an ESP-01 now to test it again). But now I upload my sketches to an ESP-12E and I just tried variable NUM_LEDS, that’s why I thought the cause of the problem was variable NUM_LEDS.
And I also added
#define FASTLED_ALLOW_INTERRUPTS 0
to the beginning of my .ino file and also disabled WiFi, but no change. I think as you said the problem is with beatsin16. except sinelon and juggle that use beatsin16 other patterns of demoreel100 work normally. if I change beatsin16(13,0,NUM_LEDS) to beatsin16(13,0,NUM_LEDS-1) it seems to work correctly again 