0

I am using a rpi pico to collect temperature measurements which are saved to a local file. I additionally want,when the pico is connected via usb to PC, to output them on stdout. I have tried this:

f=open('temps.txt','a+')
while True:
  temps=getTemperatures()
  f.write(temps)
  print(temps)

If the print(temps) line is commented out, measurements are collected as long as pico is powered, whether or not the PC is on or in standby. But with the print line uncommented, measurements are saved only if the PC is on. It seems the print blocks waiting for the connection to be re-established. How can I detect that the connection is active, so that print is executed only when it will not block?

BDL
  • 21,052
  • 22
  • 49
  • 55
NameOfTheRose
  • 819
  • 1
  • 8
  • 18
  • The thread [Re: Timed input routine not working](https://forum.micropython.org/viewtopic.php?f=16&t=9823&p=55001&hilit=stdout+timeout#p55029) in the micropython forum seems to imply that there is no way of doing this. I think I will have to rely on the watchdog timer. – NameOfTheRose Jun 28 '21 at 16:24
  • Unfortunately, on micropython 1.16 at least, the watchdog timer route is a dead end too: the maximum timeout parameter is just 8.3 seconds. And it resets the Real Time Clock although WDSEL is 0, which is unacceptable for a data logging application. Actually the hardware permits selective resets but this is not exposed by the SDK which declares [`// Reset everything apart from ROSC and XOSC`](https://github.com/raspberrypi/pico-sdk/blob/bfcbefafc5d2a210551a4d9d80b4303d4ae0adf7/src/rp2_common/hardware_watchdog/watchdog.c#L38) – NameOfTheRose Jul 01 '21 at 14:51

0 Answers0