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.

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.

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?

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.

Ref:

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.

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

Formatting Help

Don't worry about formatting, just type in the text and we'll take care of making sense of it. We will auto-convert links, and if you put asterisks around words we will make them bold.

Tips:

Create headers by underlining text with ==== or ----

To *italicise* text put one asterisk each side of the word

To **bold** text put two asterisks each side of the word

Embed images by entering: ![](https://www.google.co.uk/images/srpr/logo4w.png)That's the hard one: exclamation, square brackets and then the URL to the image in brackets.

* Create lists by starting lines with asterisks

1. Create numbered lists by starting lines with a number and a dot

> Quote text by starting lines with >

Mention another user by @username

For syntax highlighting, surround the code block with three backticks:

```
Your code goes here
```
Just like Github, a blank line must precede a code block.

If you upload more than 5 files we will display all attachments as thumbnails.