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():


Hard Reset

To perform a hard reset, similar to hitting the RESET button, use microcontroller.reset().

This may result in file system corruption when connected to a host computer. Be very careful when calling this! Make sure the device “Safely removed” on Windows or “ejected” on Mac OSX and Linux.

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():


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:

  • UF2

For example, to reset into BOOTLOADER mode:

import microcontroller

This guide was first published on Apr 02, 2018. It was last updated on May 25, 2024.

This page (CircuitPython Resetting) was last updated on Mar 08, 2024.

Text editor powered by tinymce.