• Tue 2017.08.08

    Running 1v91 on Pico

    Trying to get Pico to start executing in stand alone mode without the WebIDE connected at power up.

    Attempting to create a tutorial with tons of embedded console.log() comments to allow viewer to easily follow along.

    Works great when WebIDE is connected via USB cable. Trying to do this stand alone.

    Have tried combinations of setTimeout(), onInit() and E.on( 'init', but code execution just doesn't start.

    Exact issue as in:
    but that was back in June 2015, my guess is that updates since then should be in place.

    Also referenced:

    Any ideas, example or tutorial perhaps? Thanks in advance.

    UPDATE: Tried USB.setConsole() as suggested at:

    also, only LEDs connected to GPIO pins nothing fancy.

  • Can you give an example of the code that's not working for you?

    Did you try the use of E.on('init' described in http://www.espruino.com/Quick+Start#star­t-writing-code- ?

    Is it just that you didn't type save()?

    But as suggested by the troubleshooting, if you're printing a lot of text then you'll want to use USB.setConsole() at the top of your init function - but it shouldn't stop simple code from working right away.

  • Tue 2017.08.08
    @Gordon Thank you for the near immediate response. Yes using save() and USB.setConsole()

    The code module is rather large and nothing out of the ordinary. So I cut down in size to get the basic idea.

    Stripped of declarations and comments but the gist is as follows. Nothing earth shattering and E.on('init' is as in troubleshooting section referenced above.

    E.on('init', function() {
      //console.log("Hello World!");
    function onInit() {
    var startSequence = function() {
      setTimeout( function() {  
        console.log("inside startSequence() setTimeout()");
        // tons of console.log() comments here and in other functions    
      }, DURATIONTest );
    var clearLEDAll = function() {
      setTimeout( function() {  
        console.log("inside clearLEDAll() setTimeout()");
        // tons of console.log() comments here and in other functions    
      }, DURATIONClear );

    Am wondering though if I should have say a five second delay timer on start up.

    UPDATE: Nope that didn't work and also tried moving USB.setConsole() inside init
    Not expecting anyone to debug this code, but I could u/l the entire file. Will need
    a couple of days to prettify the thousand lines though.

  • Ok... Does it run when:

    • Running with the Web IDE open? - it seems yes?
    • 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(), not USB.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?
  • Your explanation was helpful and added clarification to the troubleshooting section @Gordon.

    I modified onInit() and removed E.on('init' and now have another peculiar scenario.

    Verified nothing connected to B6 ,B7

    function onInit() {
      // Power up delay waiting for device to settle 
      setTimeout( function() {
      }, 9900 );  

    By adding a rather long timeout shy of ten seconds, I see how the console.log() statements are now not visible (as expected). However, now the reset button on the Pico is in-effective as Red LED doesn't illuminate or flicker ever. But, when the IDE is re-connected as in a disconnect re-apply power to the USB cable then re-connect, the left pane starts filling up with the console.log() statements and the Pico starts to be happy again. This requires the IDE to be connected, not what I desire.

    It's troubling that a hard reset doesn't perform a reset. Hard disconnect of cable does then flash the Red LED as expected, and RESET then works as expected.


    Of course the problem with that is that none of your print statements will be readable by the user

    console.log() statements only intended to be visible during development and not required stand alone, so okay there.

  • The button on the Pico is just a button, accessible by use of the BTN variable - it doesn't do a reset.

    What's happening is you're temporarily setting the console to Serial1, but then a USB connection is made and it switches back to USB automatically. You can change it to Serial1.setConsole(true); which is the I really mean it version - it'll stay on Serial1 regardless of what happens to USB.

    OR - you can move it into the setTimeout - so it'll switch the console over to serial just before it starts printing.

  • I guess we weren't shouting loud enough!!

    You can change it to Serial1.setConsole(true);

    Now that we are shouting "we really mean it" ref true code now behaves as expected.

    I should have checked the documentation: http://www.espruino.com/Reference#l_Seri­al_setConsole

    Thank you @Gordon for staying here until it was resolved. I know it's now late where you are, and I appreciate being able to put this to rest before the end of both our days. Unless you are pulling an all-nighter, I still have six hours of play time with Time Zone difference. ;-)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Use of E.on init on power up - event not as expected using Pico

Posted by Avatar for Robin @Robin