Something is wrong - PICO #5365
Replies: 1 comment
-
Posted at 2016-07-06 by noofny Is there a way I can just reset it to factory state, like by flashing a custom firmware or some such thing? Both PICO's were working fine up to a couple of days ago, when I noticed this and initially thought my code must be broken, so I simplified it down the example above to eliminate that. Clearly there's something fundamentally wrong with the code flashing process and/or the way the WebIDE is sending code to the PICO... Posted at 2016-07-06 by noofny Well dang, I hang my head in shame for not checking the troubleshooting guide first. This answered my problem;
"This will then be loaded every time Espruino starts up. If you create a function called onInit, that will be executed too:"
So what is misleading is that if you click the "Send to Espruino" button in the WebIDE and DON'T have your startup code inside OnInit(), it runs fine, but if you DO then it doesn't run until you call save(). I'm sure there's an explanation to this somewhere. Posted at 2016-07-06 by noofny Still doesn't explain why previous code I have sent to the PICO's without being inside OnInit were running okay at startup. Obviously I have to look more into how Espruino works. Posted at 2016-07-06 by @gfwilliams Glad you got it sorted - ish :) When you type What I guess happens is you upload and the code actually starts running right then. You then type So what you're left with is maybe only the last 2 timeouts, rather than all the timeouts as you'd expected? Also, would you have fiddled with the IDE and clicked However, if you then turn Also - just tried:
here and it works great. Posted at 2016-07-06 by noofny Cheers Gordon - good explanation, does make it clearer. Being a n00b is fun ;-) Posted at 2016-07-06 by @allObjects Espruino Original/Pico/Puck lesson learned: LESSON 1 DO NOT have directly or indirectly immediate_executed / upload_executed dynamic code in your application - especially timers - such as:
or
or
All of the above examples will get timers going already while uploading which most likely get you into troubles, especially when you
Best case is that the code works in development mode, but if you then save(), disconnect from IDE and just power it for running stand-alone, it most likely will not work as expected. Reason why you should NOT have immediate_executed / upload_executed dynamic code in your application is that execution of this code may interfere already with the upload (has been experienced), interfere with the save() as explained in this conversation, ...and in general because you cannot reliably control the sequence in which things happen. Remedy is - first - to put everything**(XX)** into functions, and - second - to call the functions as needed and in correct sequence in the DO THIS:
**(XX)**everything is best practice and means also initializations, because some initializations are dynamic as well (as experienced with things such as Note that with above example nothing application-wise happens on or after upload when Web IDE save on upload is disabled. There is no need to enable it (and unnecessarily wear down you FLASH). Just enter But for the sake of defensive, deterministic, and robust coding, it is best (practice) to put these things into functions too and invoke them the same - sequence controlled way - as the other functions with dynamic code. For background details, take a look at the two times 2 cents posts #8 and #18 of conversation about simple explanation how to save code that espruino run on start?. Posted at 2016-07-07 by noofny @allObjects - wow thanks for taking the time to spell that out, really appreciate your insights here. After reading and experimenting more I was starting to "feel" the right way to do things was as you have just explained, so your explanations help cement this in confidence, cheers. Yeah I was beginning to see just how much @gfwilliams has done to abstract all the "messy" stuff away and make it easy for us to get our code on-chip and running, I agree this does come at the cost of allowing n00bs to do n00b things! Understanding how to do it properly however, removes the frustration entirely and brings back the fun, thanks guys, happy to understand some basics now and have my code working as expected. Good forum too - code blocks work well. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-07-06 by noofny
When I send my code to the PICO by calling save() in the WebIDE, everything appears to work. I then unplug the USB cable, then when I either plug the USB cable back in or connect a power source/battery, it is obvious that the PIC is not running the code I just sent it. In some cases it seems to run a previous version that I sent to it via this method, in other cases it just seems to do nothing.
No errors are reported via the WebIDE console, everything appears to be working, but it clearly is not. This happens on 2 different PICO's and both with the previous and latest firmware. Also tried on both Windows and OSX, same results.
Seriously WTF is going on here, what am I missing? So frustrating...
As an example, this is how simple the code is that I'm testing it with right now.
Beta Was this translation helpful? Give feedback.
All reactions