-->
Page 1 of 2

Am I trying to do too much with 8266?

PostPosted: Thu Mar 03, 2016 11:38 am
by robs113
I have an Arduino sketch that animates LED strips.
I have moved it to an ESP8266 and if runs fine :D

I wish to control it via WiFi but..
The loop is busy animating LEDs so it cannot sit and wait for an incoming WiFi connection.

Would I be better to use an Arduino for the LED animation and an 8266 for the WiFi, then have the 8266 interrupt the Arduino when a WiFi command to alter the animation is received?

Advice appreciated.

Re: Am I trying to do too much with 8266?

PostPosted: Mon Mar 07, 2016 5:35 pm
by woodat
The big issue you're probably encountering is you need to give the ESP enough time to do its wifi business between loops. The easiest way to do this is to add some short delays to your program.

Sadly I don't have a have a solid number of how long you need to delay in order to handle the wifi. I know 100ms works fine (I'm guessing 50 or even 20ms would probably do and not mess up your animations too badly but I don't know for sure if that's long enough for the ESP).

In theory it should do this automatically between iterations of your loop(), but I've found if you don't add at least some delay with the delay() command it doesn't spend enough time handling the wifi and just stops serving pages properly.

Anyone have any more solid numbers or thoughts on this? (I'm rather curious as well)

Re: Am I trying to do too much with 8266?

PostPosted: Mon Mar 07, 2016 6:24 pm
by dkfradk
Hi.

Im doing something like this

Code: Select allvoid loop() {
  if (!runningApplication->getIsFinished()) {
    runningApplication->move();
    t = millis();
    yield();
    runningApplication->getPixels(pixels);
    yield();
    strip.show(pixels);
    yield();
  }
  while (millis() <= t + runningApplication->getDelay()) {
    webSocket.loop();
    server.handleClient();
  }
}


and it works flawlessly :)

UPDATE. Fixed some wrong brackets

Re: Am I trying to do too much with 8266?

PostPosted: Mon Mar 07, 2016 9:17 pm
by Mmiscool
yeild() and delay(0) are functionally equivalent and will allow the wifi stuff to work its magic. Make sure you sprinkle these about your programs especially in any loops.