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.

The hardware reset button comes in to play during the board boot sequence.

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

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

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

This guide was first published on Apr 02, 2018. It was last updated on Mar 03, 2018.

This page (CircuitPython Resetting) was last updated on Apr 06, 2021.

Text editor powered by tinymce.