- Mon Jan 09, 2017 4:18 pm
#60752
Cool! Glad I'm not barking up the totally wrong tree then.
The only reason I'm writing about this stuff is that this is what I'm actually figuring out myself at the moment. I see you're an Arduino/C man. I'm working with Lua, I know I'll eventually have to move to C to do more heavyweight stuff, but the rapid prototyping of ideas in Lua works very well for me, for now. I've never as much as seen an Arduino board close up. they sound cool, though....
This is the gist of what I've discovered so far: Mainly through trial and error.
If you're going to do any serious programming on the ESP, forget about loops. Yes, that's right, chuck 'em out, bye-bye, not going to be needing those...
You may think the above is an extreme statement, and OK, maybe it is, you're still allowed ikkle local fast loops to do your neat stuff. What you are NOT going to be seeing is large synchronous control loops with time delays for doing stuff. No siree. If you're using Lua you can kiss the neat coroutine system goodbye, too.
If you think you are going to get an array of LEDs to flash by looping through them and lighting each one on and off for a bit, forget it, ain't going to happen. Well, not if you want the rest of the system to be working, too...
The point is that the ESP controls all its own asynch scheduling, and if you try to interfere in this basically you will only end up hogging the system and locking everything up, since your loops will stop other things from working, e.g. minor things like wifi, UART, etc.
So the thing to do is run everything off system events, provided by the internal timer - Instead of YOUR loop controlling the flow of events, you rely on the timer (the timer.alarm() function in Lua is the most convenient, there should be some C equivalent).
If you want to imagine this graphically, think of the pace-drummer in a Roman slave galley, on every beat which he provides the slaves must perform their actions. They most definitely cannot go off and do their own scheduling,
Or just think of it as a clock driving the operations, if you're that way inclined.
I've found I'm making a fair bit of progress now that I've grasped this concept, I may put up some tutorial/blog/whatchamacallit up later when I have enough material. I think most of the introductory tutorials don't really touch on this sufficiently.
HTH
Best Regards