Plugging in to your PC's USB without the Web IDE open? - I'd guess no?
Running off a USB power pack/wall charger (not your PC?) - I'd guess yes?
You actually have a bit of a problem...
Basically, Espruino's USB has flow control, so if connected it will not lose the data you send to it. However, you're writing lots of data to USB when the PC isn't receiving any of the data Espruino is trying to send.
From Espruino's point of view, it doesn't know if the PC/Web IDE is just busy handling the data in which case it shouldn't throw it away, or if there is just no application running that is reading the data, in which case maybe it should. It just knows nothing is reading the data, so it does the safe thing and waits.
So the solution is actually the troubleshooting item above the one you linked to, which is Serial1.setConsole(), notUSB.setConsole(). Of course the problem with that is that none of your print statements will be readable by the user, since after Serial1.setConsole() everything will get printed (including the command prompt) to the first serial port.
Some other notes though...
.setConsole(); should be at the top of onInit, not outside - because if it's outside it gets called at upload time, not boot time.
onInit is itself a special function that gets called at boot. You don't need E.on('init', function() { onInit(); }) since that'll just end up calling onInit twice.
DURATIONTest/DURATIONClear aren't defined, but I guess that's because you copy/pasted the code?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Ok... Does it run when:
You actually have a bit of a problem...
Basically, Espruino's USB has flow control, so if connected it will not lose the data you send to it. However, you're writing lots of data to USB when the PC isn't receiving any of the data Espruino is trying to send.
From Espruino's point of view, it doesn't know if the PC/Web IDE is just busy handling the data in which case it shouldn't throw it away, or if there is just no application running that is reading the data, in which case maybe it should. It just knows nothing is reading the data, so it does the safe thing and waits.
So the solution is actually the troubleshooting item above the one you linked to, which is
Serial1.setConsole()
, notUSB.setConsole()
. Of course the problem with that is that none of your print statements will be readable by the user, since afterSerial1.setConsole()
everything will get printed (including the command prompt) to the first serial port.Some other notes though...
.setConsole();
should be at the top ofonInit
, not outside - because if it's outside it gets called at upload time, not boot time.onInit
is itself a special function that gets called at boot. You don't needE.on('init', function() { onInit(); })
since that'll just end up callingonInit
twice.DURATIONTest
/DURATIONClear
aren't defined, but I guess that's because you copy/pasted the code?