Most CircuitPython boards have a physical reset button. Pressing that button will perform a hardware reset, similar to unplugging and plugging in the USB cable. There's no code involved. So the reset button should always work.
More detailed information about what happens when you press the reset button in various ways and what the status LED indicates, including a flowchart, is here.
But what if you want to reset from your program? Maybe you want to just kick the board to recover from some bad state. Or maybe you have some use case where you want to reset into bootloader mode. We cover these various options here.
Soft Reset
To preform a soft reset, similar to hitting <CTRL><D>
at the REPL prompt, use supervisor.reload()
. First, you need to import the supervisor
module:
import supervisor
And then at the point in your code where you want to reset, call reload()
:
supervisor.reload()
Hard Reset
To perform a hard reset, similar to hitting the RESET button, use microcontroller.reset()
.
First you need to import the microcontroller
module:
import microcontroller
And then at the point in your code where you want to reset, call reset()
:
microcontroller.reset()
Reset Into Specific Mode
It is also possible to specify the mode to reset into. For example, you can reset into bootloader mode if you want. To do this, use on_next_reset()
to specify the mode before calling reset()
. The available options are defined in the microcontroller.RunMode
class:
NORMAL
SAFE_MODE
UF2
BOOTLOADER
For example, to reset into BOOTLOADER mode:
import microcontroller microcontroller.on_next_reset(microcontroller.RunMode.UF2) microcontroller.reset()
Page last edited March 08, 2024
Text editor powered by tinymce.