ESP12F with ws2812 (neopixels) within arduino - Page 1
Forum section: electronics / beginners

author: lk
author_rank: Regular Contributor
timestamp: June 14, 2017, 12:25:30 pm
content: Greetings,I have run into a problem when combining the neopixel library and BasicHttpClient, But when i combine them i cant get the neopixels to work. The the http client works as expected, and the neopixels work when not combined with the BasicHttpClient.The only thing i need to have done is the color of the neopixels set based on the parsing of a webpage.I have no real idea what is going onI use an 74HCT08 and gate for level translation.-lasseESP8266 boards 2.2.0Arduino IDE 1.8.2Adafruit Neopixel version 1.1.1Code:#include <Adafruit_NeoPixel.h>/*** BasicHTTPClient.ino** Created on: 24.05.2015**/#include <Arduino.h>#include <ESP8266WiFi.h>#include <ESP8266WiFiMulti.h>#include <ESP8266HTTPClient.h>#define USE_SERIAL SerialESP8266WiFiMulti WiFiMulti;#define PIN 5// How many NeoPixels are attached to the Arduino?#define NUMPIXELS 16Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);int delayval = 500; // delay for half a secondvoid updatepixels() {for(int i=0;i<NUMPIXELS;i++){// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255pixels.setPixelColor(i, pixels.Color(150,0,0)); // Moderately bright green color.pixels.show(); // This sends the updated pixel color to the hardware.delay(delayval); // Delay for a period of time (in milliseconds).}}void setup() {USE_SERIAL.begin(115200);// USE_SERIAL.setDebugOutput(true);USE_SERIAL.println();USE_SERIAL.println();USE_SERIAL.println();for(uint8_t t = 4; t > 0; t--) {USE_SERIAL.printf(" WAIT %d...\n", t);USE_SERIAL.flush();delay(1000);}WiFiMulti.addAP("Neopixel", "ESP12f");updatepixels();}void loop() {// wait for WiFi connectionif((WiFiMulti.run() == WL_CONNECTED)) {USE_SERIAL.println("");USE_SERIAL.print("MAC: ");USE_SERIAL.println(WiFi.macAddress());USE_SERIAL.print("SSID");USE_SERIAL.println(WiFi.SSID());USE_SERIAL.print("IP address: ");USE_SERIAL.println(WiFi.localIP());HTTPClient http;USE_SERIAL.print(" begin...\n");// configure traged server and url//http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPShttp.begin("http://www.ajax.esy.es/"); //HTTPUSE_SERIAL.print(" GET...\n");// start connection and send HTTP headerint httpCode = http.GET();// httpCode will be negative on errorif(httpCode > 0) {// HTTP header has been send and Server response header has been handledUSE_SERIAL.printf(" GET... code: %d\n", httpCode);// file found at serverif(httpCode == HTTP_CODE_OK) {String payload = http.getString();USE_SERIAL.println(payload);}} else {USE_SERIAL.printf(" GET... failed, error: %s\n", http.errorToString(httpCode).c_str());}http.end();}delay(10000);}This was originally posted onhttp://www.esp8266.com/, but i got no replies so ill try here indea

author: NexusKoolaid
author_rank: Contributor
timestamp: June 14, 2017, 04:53:26 pm
content: I would double check the order in which you are including the header files required by your sketch.Adafruit_NeoPixel.h will potentially include Arduino.h, then your code explicitly includes Arduino.h. No problem so far.In the GitHub versions of these files:Code:#include <ESP8266WiFi.h>#include <ESP8266WiFiMulti.h>#include <ESP8266HTTPClient.h>Arduino.h is only included in ESP8266HTTPClient.h, after the first two headers have been included. While I'd have to follow the #include dependency tree of the first two modules to be sure (no time for that at the moment), I take this to mean these headers don't need Arduino.h, and may have been written under the assumption that the header has not been yet been included. In ESP8266WiFiMulti.h I spotted this code at line 31 and 32:Code:#undef min#undef maxIf this file is included before including Arduino.h, there is no harm. But if Arduino.h is included first, the code in ESP8266WiFiMulti.h is destructive because Arduino.h defines min and max as:Code:#define min(a,b) ((a)<(b)?(a):(b))#define max(a,b) ((a)>(b)?(a):(b))and subsequent #includes of Arduino.h won't reinstate the definitions because the following mechanism prevents a module from being included multiple times:Code:#ifndef Arduino_h#define Arduino_h[blah blah blah...]#endifThis may or may not be a contributing factor in your problem. The main takeaway is that in C/C++ is a little different in dealing with dependencies than in other languages - sometimes you need to be a little more deliberate in the ordering of your #include directives.

author: lk
author_rank: Regular Contributor
timestamp: June 15, 2017, 12:31:18 pm
content: Thank you NexusKoolaid,Based on your very detailed analysis i reordered the #include statements to this order, but i still have the same problem, and just in case i broke the hardware i tried the standalone neopixel simple, and that still works.#include <ESP8266WiFi.h>#include <ESP8266WiFiMulti.h>#include <ESP8266HTTPClient.h>#include <Adafruit_NeoPixel.h>-lasse

author: Fredderic
author_rank: Regular Contributor
timestamp: June 15, 2017, 02:38:35 pm
content: Ummms... huh.If the #undef's were the problem, you'd probably be getting compile time errors around the place. Using #define to create min and max is great for efficiency (as long as you watch the double-evaluation thing), but kind of crap if you want a variable named min or max. Which is probably why a good many libraries turn around and undefine them again, and most libraries probably avoid using them for much the same reason.I've been in Python web land for the last year or so, so I may be a bit rusty, plus I've never used either the Pixel's, or the ESP's (which is why I waited to see if someone else would chime in), but…What I would expect your code to do from just a quick reading, is set the pixel string from black to whatever colour 150,0,0 represents (the comment says green, but I'd have guessed Red or Blue…), one pixel every half second. And then, once it's finished lighting up the pixel string, it'll start logging how successfully it fetches data from that webpage, and absolutely nothing else.Are you saying it's not lighting up the pixel stringat all? If that's the case, then something is indeed broken. (I'm afraid to say, btw, you were probably being ignored because it looks very much like you need to learn to program first.)Or, are you saying it's just not changing the colours according to what you're getting from the web? If itissetting the pixels to that set colour, and then not changing them regardless of what the web page says, well, it's doingexactlywhat your code is telling it to do; you're not doinganythingwith the data you retrieve, other than:USE_SERIAL.println(payload);If the pixel string is lighting up and then not doing anything, it's because you'll need to parse that payload string into bytes, sending each triple to setPixelColor(), followed by the call to show(). I'd probably recommend as you parse the payload string, converting each hex pair into their corresponding byte, write it back out to serial also so you can check you've parsed it correctly.

author: stj
author_rank: Super Contributor
timestamp: June 15, 2017, 02:38:57 pm
content: the library's may be using a variable with the same name/label

author: NexusKoolaid
author_rank: Contributor
timestamp: June 15, 2017, 03:50:02 pm
content: Quote from: Fredderic on June 15, 2017, 02:38:35 pmThat's not at all what I was trying to get across. It was meant to serve as an illustration, hence "This['type of thing' I should have added]may or may notbe a contributing factor in your problem."Where Codebase A and Codebase B are functional, but Codebase A+B are not, the dependencies are something I would check once I've first failed to find any obvious conflicts in the combined module. And a with blatant #undef conflict found so easily a closer inspection of the dependency tree is warranted, IMO. I only say this because I've been burned by this in the past, by issues not as obvious as an undefined macro.QuoteA good many may do this, but not many good ones will.

author: darrellg
author_rank: Unknown
timestamp: June 15, 2017, 04:00:49 pm
content: The Neopixel library disables interrupts when it pulses the pixels because the WS2812 timing requirements are very critical. I would check interrupt requirements on the other libraries you are using to see if there may be a conflict. In the past, I've switched to Dotstar type LEDs because they have a clock line and don't require the interrupts to be disabled to function.

author: lk
author_rank: Regular Contributor
timestamp: June 16, 2017, 12:31:03 pm
content: Greetings,thanks for all the replies, i changed to the FastLED Library, and that seems to have solved the problem for me.https://github.com/FastLED/FastLED-lasse