Last active
September 6, 2016 02:55
-
-
Save probonopd/6251b68f1efd33b28c5b to your computer and use it in GitHub Desktop.
Trying to combine ArduinoOTA with Adafruit_NeoPixel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//####################################################### | |
//# Trying to combine ArduinoOTA with JoDaNl/esp8266_ws2812_i2s # [ERROR]: No Answer | |
//####################################################### | |
#include <ESP8266WiFi.h> | |
#include <ESP8266mDNS.h> | |
#include <WiFiUdp.h> | |
#include <ArduinoOTA.h> | |
#include <ws2812_i2s.h> | |
#define NUM_LEDS 30 | |
static WS2812 ledstrip; | |
static Pixel_t pixels[NUM_LEDS]; | |
const char* ssid = "............."; | |
const char* password = ".............."; | |
void setup() { | |
Serial.begin(115200); | |
Serial.println("Booting"); | |
Serial.begin(115200); | |
Serial.println("ws2812 i2s library demo sketch"); | |
ledstrip.init(NUM_LEDS); | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(ssid, password); | |
while (WiFi.waitForConnectResult() != WL_CONNECTED) { | |
Serial.println("Connection Failed! Rebooting..."); | |
delay(5000); | |
ESP.restart(); | |
} | |
// Port defaults to 8266 | |
// ArduinoOTA.setPort(8266); | |
// Hostname defaults to esp8266-[ChipID] | |
// ArduinoOTA.setHostname("myesp8266"); | |
// No authentication by default | |
// ArduinoOTA.setPassword((const char *)"123"); | |
ArduinoOTA.onStart([]() { | |
Serial.println("Start"); | |
}); | |
ArduinoOTA.onEnd([]() { | |
Serial.println("End"); | |
}); | |
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { | |
Serial.printf("Progress: %u%%\n", (progress / (total / 100))); | |
}); | |
ArduinoOTA.onError([](ota_error_t error) { | |
Serial.printf("Error[%u]: ", error); | |
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed"); | |
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed"); | |
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed"); | |
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed"); | |
else if (error == OTA_END_ERROR) Serial.println("End Failed"); | |
}); | |
ArduinoOTA.begin(); | |
Serial.println("Ready"); | |
Serial.print("IP address: "); | |
Serial.println(WiFi.localIP()); | |
} | |
void loop() { | |
ArduinoOTA.handle(); | |
yield(); | |
uint8_t i; | |
static uint8_t c = 0; | |
static uint8_t d = 1; | |
for (i = 0; i < NUM_LEDS; i++) | |
{ | |
pixels[i].R = c; | |
pixels[i].G = c; | |
pixels[i].B = c; | |
} | |
c += d; | |
if ( (c == 255) || (c == 0) ) d = -d; | |
ledstrip.show(pixels); | |
delay(10); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//####################################################### | |
//# Trying to combine ArduinoOTA with Adafruit_NeoPixel # | |
//####################################################### | |
#include <ESP8266WiFi.h> | |
#include <ESP8266mDNS.h> | |
#include <WiFiUdp.h> | |
#include <ArduinoOTA.h> | |
#include <Adafruit_NeoPixel.h> // platformio lib install 28 | |
#define PIN 4 | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800); | |
const char* ssid = "XXXXXXXXXXXX"; | |
const char* password = "XXXXXXXXXXXXXXXX"; | |
void setup() { | |
Serial.begin(115200); | |
Serial.println("Booting"); | |
strip.begin(); | |
strip.show(); // Initialize all pixels to 'off' | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(ssid, password); | |
while (WiFi.waitForConnectResult() != WL_CONNECTED) { | |
Serial.println("Connection Failed! Rebooting..."); | |
delay(5000); | |
ESP.restart(); | |
} | |
ArduinoOTA.begin(); | |
Serial.println("Ready"); | |
Serial.print("IP address: "); | |
Serial.println(WiFi.localIP()); | |
} | |
// 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); | |
} | |
} | |
// 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); | |
} | |
if(WheelPos < 170) { | |
WheelPos -= 85; | |
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); | |
} | |
WheelPos -= 170; | |
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); | |
} | |
void rainbow(uint8_t wait) { | |
uint16_t i, j; | |
for(j=0; j<256; j++) { | |
for(i=0; i<strip.numPixels(); i++) { | |
strip.setPixelColor(i, Wheel((i+j) & 255)); | |
} | |
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); | |
} | |
} | |
// Theatre-style crawling lights. | |
void theaterChase(uint32_t c, uint8_t wait) { | |
for (int j=0; j<10; j++) { // do 10 cycles of chasing | |
for (int q=0; q < 3; q++) { | |
for (int i=0; i < strip.numPixels(); i=i+3) { | |
strip.setPixelColor(i+q, c); // turn every third pixel on | |
} | |
strip.show(); | |
delay(wait); | |
for (int i=0; i < strip.numPixels(); i=i+3) { | |
strip.setPixelColor(i+q, 0); // turn every third pixel off | |
} | |
} | |
} | |
} | |
// Theatre-style crawling lights with rainbow effect | |
void theaterChaseRainbow(uint8_t wait) { | |
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel | |
for (int q=0; q < 3; q++) { | |
for (int i=0; i < strip.numPixels(); i=i+3) { | |
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); // turn every third pixel on | |
} | |
strip.show(); | |
delay(wait); | |
for (int i=0; i < strip.numPixels(); i=i+3) { | |
strip.setPixelColor(i+q, 0); // turn every third pixel off | |
} | |
} | |
} | |
} | |
void loop() { | |
ArduinoOTA.handle(); | |
// yield(); // ########################## | |
rainbowCycle(20); // ########################## THIS LINE TOTALLY BREAKS IT | |
} |
The following combination WORKS with OTA and Pixels.
https://gist.github.com/AdySan/bd23f7be5ca5a6a4563f
IDE 1.6.7
core 2.0.0.0 (stable)
https://github.com/Imroy/pubsubclient
https://gist.github.com/AdySan/edbd96ad1c0e5990f78c
https://gist.github.com/AdySan/093772a5b09f140c6432
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AdySan
20:25
Yeah, you porbably need to call ArduinoOTA.handle() more often
the rainbowCycle() blocks it for a few seconds
probonopd
20:27
so you're saying not only use it in the main loop() but also in other functions, doesn't hurt?
i see
AdySan
20:28
try this library https://github.com/JoDaNl/esp8266_ws2812_i2s
Links2004
20:28
@probonopd Adafruit_NeoPixel us bit banging, there are DMA versions, they work much better.
AdySan
20:28
you need to connct to RX pin
probonopd
20:28
thanks for your suggestions, will try that
Links2004
20:29
@AdySan yes this is working fine for me.
AdySan
20:29
me too, but I still have problems with me strip behaving strangely sometimes, half of it gets stuck in white
only reboot helps
i thought it was due to bit banging blocking wifi and the I2s version would solve the problem, but it doesnt
so assuming its electrical
probonopd
20:31
so my OTA issue is not electrical - I also have this issue when there is no strip attached at all
@AdySan the library you suggest has a "delay(10);" in the example sketch main loop
Links2004
20:31
@AdySan how long is you stripe? i tested it with 5m - 150LEDs (300LEDs order incoming),
power from both sides and it working fine.
AdySan
20:31
yeah, its just blocking the OTA call for too long. If you try at hte right moment, you cna get lucky though
d-anders
20:31
the loop takes too much time i guess probonopd
probonopd
20:31
does it play welll with OTA to have "delay(10)" there?
Links2004
20:32
delay(10) is ok
AdySan
20:32
@Links2004 my strip is 1.5M 94 leds
probonopd
20:32
maybe the question is ridiculous, but is there the concept of different threads in the esp world?
AdySan
20:33
I guess not, no RTOS here in this firmware
Links2004
20:33
with rtos yes, ESP32 will have it, the RTOS for ESP8266 is outdate 😟
probonopd
20:33
or timer-interrupt based ota? so that no matter what the sketch does, ota would always work?
Links2004
20:33
@probonopd will not work