boot.py usage with Thonny

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
clack
Posts: 20
Joined: Sat May 03, 2014 11:09 am

boot.py usage with Thonny

Post by clack » Mon Apr 04, 2022 12:37 pm

Hello,

I am directly driving a little screen from the pico and have created a crude LCD driver using the PIO

Problem is, within Thonny editor when you press "stop" it resets the pico but the enable pins stay in their current state and this causes damage to the screen (if enabled and there is no LCD signal it makes a horrible beached image which can stick).

If I add some pin output low to the boot.py file it stops this issue, is this considered bad practice or is it perfectly ok?

this is what my boot.py is (its just copied from the main.py at the moment)

Code: Select all

from machine import Pin, PWM

DISP = 4
DE = 5
BACKLIGHT = 28

disp = Pin(DISP, Pin.OUT, 1)
disp.off()
de = Pin(DE, Pin.OUT, 0)
de.off()

backlight = PWM(Pin(BACKLIGHT))
backlight.freq(500)
backlight.duty_u16(0)
I guess I am trying to understand, is this the best way to reset pins to an off state when you press "stop" in thonny?

User avatar
aivarannamaa
Posts: 171
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

Re: boot.py usage with Thonny

Post by aivarannamaa » Fri Apr 08, 2022 5:36 am

Interrupting with Ctrl+C would be a good alternative to the "Stop/Restart" button. It allows you to catch KeyboardInterrupt:

Code: Select all

try:
    main_work()
except KeyboardInterrupt:
    clean_up()
Unfortunately Thonny 3.3 is overly eager with handling Ctrl-C -- if it detects one, it sends several to the board, so that your clean_up() code could be interrupted as well. This is fixed in the first beta of Thonny 4.0.
Aivar Annamaa
https://thonny.org

Post Reply