Issue with printing in loops #16378
Replies: 4 comments 3 replies
-
It looks like something is caching output: the time stamp shows that print is being called every 100 ms. MicroPython's |
Beta Was this translation helpful? Give feedback.
-
I can confirm the behavior with a Seeed NRF52840 and a Arduino Nano 33 connect. It seems to be related to buffering in the USB stack. It does not happen with Micro:Bit, because that board has a serial interface at the nrf chip connected to a on-board serial/usb device, which also handles firmware upload by providing a drive. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the report and clear reproduction case @MrTinkerman and thanks for the testing @robert-hh I think this must be related to the stdio consolidation changes I made recently, though I'm really not sure why. The stdout buffering setup was changed slightly, particularly relating to buffering the startup messages etc. I'm not sure why this would prevent the regular flushing of the text though and haven't seen / heard of this on other ports. Maybe there's something slightly different with the configuration of the nrf driver, hopefully a comparison of the TinyUSB config before and after my changes might highlight a difference. |
Beta Was this translation helpful? Give feedback.
-
I've had a similar problem - started with this exact issue, but I then changed the code to toggle the LED on and off on the board in a "while(1)" loop - and saved it as main.py. Unplugging the USB and re-powering it up via 3v3/gnd pins, the board came to life and the LED started flashing - win! Unplug that power, and then plug the USB in - the board comes to life and starts flashing. Ok. Fire up Thonny... and... there's no com port for it to connect to at all. I tried numerous "reset" and reload of MP firmware and it just kept doing the same thing, no com port outside of bootloader mode (and in bootloader mode, I can't load new python code for obvious reasons). Ultimately, I put CircuitPython's firmware on there - which did wipe the storage and the board was accessible. Re-wiped with Micropython, and it's all back. So i'm wondering if everything, including com initialisation is being held until the script completes? For now i'm just going to update my loop to read a GPIO pin and put a button on the board to abort but would be great if that wasnt needed :) Thanks |
Beta Was this translation helpful? Give feedback.
-
Today i flashed uP v1.24.1 on XIAO nRF52840 to use new deque functionality.
But I'm having an issue when printing inside loops. The code I used to test and the results are below.
The results look ok, however:
Does anyone know why this is happening?
Thanks
EDIT
For now I will use v1.23.0:
-- It has the new deque functionality I want to use
-- It prints as expected inside loops
Beta Was this translation helpful? Give feedback.
All reactions