1

I've got a script running on my Raspberry Pi Pico W that works fine, until it doesn't. It has worked for a few days without a problem and now seems to just stop sometimes. It is hard to find out what goes wrong without logging. Is there a best practice to go about this? I'd like to (maybe?) just log all the exceptions or something. I'm running Micropython and using Thonny.

Context: I've made an automated door for my chicken coop. I've re-purposed and combined some scripts I found on the interwebs to make a clock that uses WiFi and NTP (every hour) to keep running on time. My script checks when it's time to open or close the door and then executes the open or close script that makes the 12V DC motor go. I even have limit switches checking if the door was completely opened/closed. I make the led blink every second, so I can see when it stops. It has been my very first project with Raspberry Pi, Micropython and electronics in general, so I'm actually quite surprised I got this far without messing up, so please go easy on me. I've already to content with four chicks that have sub-par service here :P

Really appreciate the help!

lammersch
  • 11
  • 2

2 Answers2

0

Hi The solution is to reset the flash memory and you can do this by dragging and dropping a special UF2 binary onto your Pico when it is in mass storage mode. To procure the UF2 Binary go here: https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#resetting-flash-memory

I hope this solved the issue.

Thank You. Naveen PS

Naveen PS
  • 13
  • 5
  • 1
    Hi Naveen, Thanks for your answer. Just a soft reset (CTRL+D) will get everything going again. At least, for a while. So flashing the Pico is not nessecary, I guess? – lammersch Sep 20 '22 at 06:46
0

I've also posted this question on the RP forum and got this answer:

The following may help if placed near the start of your script but be warned I've not tested this and it will eventually fill up the file system.

import os
logfile = open('log.txt', 'a')
# duplicate stdout and stderr to the log file
os.dupterm(logfile)

Beyond that, you're probably looking at adding yor own logging functionality and exception handling. AFIAK micropython doesn't have the logging module.

This seems to work.

https://forums.raspberrypi.com/viewtopic.php?p=2039343#p2039343

lammersch
  • 11
  • 2