New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Espruino setWatch on ESP8266 #643
Comments
Today, |
Oh, finally I found this issue after an hour debugging and understanding why library http://www.espruino.com/DHT22 doesn't work =) (it was using setWatch) |
Yes, I think people are going to end up a bit disappointed when they try the really realtime stuff lime WS2811 and DHT11/IR/radio/etc I'm tempted to put a bit of a note after the Espruino banner that mentions it's not 100%? it would suck if people got the wrong impression about Espruino itself because of the ESP8266 port |
@gfwilliams I was aware it's a Beta, and I know it was brought in very lately from separate repo, so I am not surprised or disappointed much. That's BETA is for. But maybe having it said explicitly is good enough. |
But the GREAT news is that ESP8266 does indeed has interrupt handling for GPIOs ... it simply hasn't been implemented in the ESP8266 port yet. Weve been studying the Espressif SDK and it doesn't look like rocket science to add it. As such, that would then tell me that the speed of running Espruino on the ESP8266 should be no worse than other boards that are also capable of running at 160MHz. |
Yes, really good news about the IRQs. And @tve implemented the utility timer - does that run off a proper IRQ as well?
Unfortunately that's probably not entirely right - the ESP8266 is having to load a lot of program code out of SPI flash in order to run it (as far as I'm aware?) so I think realistically it's going to end up slower than even the 72Mhz parts that can execute out of on-chip flash... Not that it actually matters much though. |
Now it is time to write a use case that should work ... and then we can test against it. The primary docs for this area can be found here: http://www.espruino.com/Reference#l__global_setWatch The sample test that we are working with just now looks like:
The principle behind this is that it will start watching GPIO12 for a signal change and, should it happen, cause the callback to be invoked. In the ESP8266 SDK, we have the following functions that come into play when working with interrupts:
With these parts wired in, we are detecting that the interrupt handler is indeed seeing a pin state change ... but only once. When the pin state changes from high to low or low to high, we see the interrupt handler invoked ... but only the first time. If the pin state changes again, we don't see any further interrupt invocation. This is the area that is currently being investigated. ... much later ...
And now it works flawlessly. Do I proclaim to 100% understand this? No. I have some guesses ... but nothing for certain. Now that I can mechanically detect interrupt changes, the next step will be linking these into the Espruino event processing logic. .... To Be Continued ... |
Just call |
@nkolban maybe better write new messages? =) I was monitoring email for updates, because I am very interested and just found out you've been updating same comment ) Maybe @gfwilliams haven't noticed your progress for the same reason? =) |
@soswow There is a balance at work here .... the way I like to work is to make sure that I keep a trail of the learnings so that when I come back to an issue a few days later, I remember where I was. In addition, I am always looking for help and collaborators so keeping the story straight is super useful. I am also of an opinion that down the line, someone else may want to modify code that was previously written and the comments here might be useful for someone else. However, I don't want to flood everyones email in boxes with comment after comment. So the choices appear to be to:
|
I'm happy with the last comment changes - I saw them before I wrote up... My e-mail box is usually pretty full with GitHub comments from @nkolban as it is ;) |
@nkolban do as you like and feel right, of cause! And I am 100% for detailed trail of thought kinda comments with all those benefits you described above. As for flooding peoples inboxes - I was thinking if someone not interested in updates on an issue he can just unwatch it. |
Following on from @gfwilliams comments yesterday, now starting on the invocation of the event push to Espruino when an interrupt occurs. ... later ... I implemented a call to On a fresh boot I run
after running my script which creates one watch, I see:
I'm still trying to understand these trace decodes. The thing that has drawn my attention is the apparent size of the ... later ... It appears to me that the algorithm at play is becoming clearer. When a GPIO interrupt occurs we add an event into the IOEvent list which gets processed in ... later ... Finally nailed down the last issue (at this time). There is one more hardware (ESP8266) specific function that had not been implemented and that was |
Pull request issued for inclusion of the interrupt handler logic. Waiting on @samehhady to perform tests before closing the work item. |
@nkolban is there binary I can use to test DHT22 library? I have hardware set up |
A binary of the firmware that includes the |
The Your example Unfortunately I am on the road this week and away from electronics ... so I don't have a DHT22 available to me where I am to attempt a device test. The soonest I could look at an actual DHT22 recreate will be Saturday. |
Maybe try it out with a signal source from somewhere else (a normal Espruino board?) and dump the time:
IIRC the DHT22 actually sends signals pretty quickly, so it could be watches are working, but:
Maybe also check |
yes, with this example it works for me. I don't have logic analyser to see what my device (DHT22) spitting out to understand if setWatch doesn't work correctly or my devices doesn't spit what it should. Interesting ... I modified this code a bit and added
Is it normal, is switches only from true to true? Shouldn't it trigger onwatch function when goes down? ... |
Well, if that really is only triggering once every half second, it's definitely not fast enough! The repeated |
I have to do other things right now. But when I back I will use another microcontroller (As you suggested @gfwilliams) and will start sending toggling signal into esp8266 with some interval, which I can decrease over time and see when esp8266 will start falling behind |
Ok. I have arduino nano running with this code: int led = 7;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(1);
digitalWrite(led, LOW);
delay(1);
} And I hooked up pin 7 and ground to esp8266. On esp I am running this: var lastState = null;
setWatch(function(t) {
if(lastState !== null){
if(lastState === t.state){
console.log("error");
}
}else{
console.log("starting");
}
lastState = t.state;
}, D2, {repeat: true, edge: "both"}); I don't get any "error". Which mean there were no two sequential true or false The only problem I have is that after maybe 10 seconds of this JS code running devices resettes itself with possible error:
before that it was something ending with
|
Maybe try a bit slower? If you print too much stuff, the ESP8266 is going to block and wait for what you printed to be sent out the serial port - if it blocks too long it might reset. What about:
|
It wasn't printing anything before. With your code it's 100 almost all the time (every 14th number is 99) and it's not crashing. |
Ok, that's good news (i think)? But you're sending a 500Hz signal so you'd expect 500 (actually 1000 since it's on both edges)? |
yes. With
Maybe USB provided power is not enough ... |
Since Espruino is a JavaScript interpreter (as I understand it), that means that the path length to execute a JS statement is much, much longer than C statements performing the equivalent, GPIO bit twiddling will never (opinion) be as fast as native C code. My understanding of how the interrupt handler works is: (1) An interrupt occurs As we can see, this is very different from an Arduino style app which might:
It is likely the performance of the current interrupt handler can be dramatically improved from where it is ... and the reason for this is that there is a metric ton of debugging information being written that gets processed in the idle loop. We will add an issue to disable debug logging for timing tests such as this. Issue #655 added to allow disabling of debug information for ESP8266. |
That'd do it - if it's outputting down RS232 that'd slow things down no end - however it's kind of odd that it settles down at exactly 100 IRQs per second. |
@gfwilliams the last thing I probably need to do is to eliminate Arduino factor and make sure it actually sends blinking signal with the speed I ask it to do. This was arduino Nano. I will use some other microcontroller and try to reed this signal as well. @nkolban is it possible my esp8266 is out of ram because each event trigger do some debugging logging or some other type of memory leaking because code still contains debug entries? Is there a way to access memory usage? |
@soswow Let me invite you to come and drop by on our live Gitter stream found here: https://gitter.im/espruino/Espruino This is a great place to ask and answer questions in real time. |
@samehhady has reported that setWatch is not working. This is not the same as all interrupt abilities are now 100% but as of now, there are no known defects on interrupt handling/setWatch. |
I've been trying the
IRReceiver
module on ESP8266 and found that it is usingsetWatch
Currently this functionality is not implemented yet on ESP.
Talking to @nkolban he mentioned that at a minimum, it looks like ESP8266 has to implement
jshPinWatch
andjshCanWatch
which are stubbed to be "NONE" and "false" right now.The text was updated successfully, but these errors were encountered: