supervisor – Supervisor settings¶
Available on these boards
Runtime information, such as
runtime.serial_connected(USB serial connection status). This object is the sole instance of
disable_autoreload() → None¶
Disable autoreload based on USB file write activity until
set_rgb_status_brightness(brightness: int) → None¶
Set brightness of status neopixel from 0-255
reload() → None¶
Reload the main Python code and run it (equivalent to hitting Ctrl-D at the REPL).
set_next_stack_limit(size: int) → None¶
Set the size of the stack for the next vm run. If its too large, the default will be used.
set_next_code_file(filename: Optional[str], *, reload_on_success: bool = False, reload_on_error: bool = False, sticky_on_success: bool = False, sticky_on_error: bool = False, sticky_on_reload: bool = False) → None¶
Set what file to run on the next vm run.
None, the given
filenameis inserted at the front of the usual [‘code.py’, ‘main.py’] search sequence.
The optional keyword arguments specify what happens after the specified file has run:
sticky_on_…determine whether the newly set filename and options stay in effect: If True, further runs will continue to run that file (unless it says otherwise by calling
set_next_code_filename()itself). If False, the settings will only affect one run and revert to the standard code.py/main.py afterwards.
reload_on_…determine how to continue: If False, wait in the usual “Code done running. Waiting for reload. / Press any key to enter the REPL. Use CTRL-D to reload.” state. If True, reload immediately as if CTRL-D was pressed.
…_on_successtake effect when the program runs to completion or calls
…_on_errortake effect when the program exits with an exception, including the KeyboardInterrupt caused by CTRL-C.
…_on_reloadtake effect when the program is interrupted by files being written to the USB drive (auto-reload) or when it calls
These settings are stored in RAM, not in persistent memory, and will therefore only affect soft reloads. Powering off or resetting the device will always revert to standard settings.
When called multiple times in the same run, only the last call takes effect, replacing any settings made by previous ones. This is the main use of passing
Noneas a filename: to reset to the standard search sequence.
ticks_ms() → int¶
Return the time in milliseconds since an unspecified reference point, wrapping after 2**29ms.
The value is initialized so that the first overflow occurs about 65 seconds after power-on, making it feasible to check that your program works properly around an overflow.
The wrap value was chosen so that it is always possible to add or subtract two
ticks_msvalues without overflow on a board without long ints (or without allocating any long integer objects, on boards with long ints).
This ticks value comes from a low-accuracy clock internal to the microcontroller, just like
time.monotonic. Due to its low accuracy and the fact that it “wraps around” every few days, it is intended for working with short term events like advancing an LED animation, not for long term events like counting down the time until a holiday.
Addition, subtraction, and comparison of ticks values can be done with routines like the following:
_TICKS_PERIOD = const(1<<29) _TICKS_MAX = const(_TICKS_PERIOD-1) _TICKS_HALFPERIOD = const(_TICKS_PERIOD//2) def ticks_add(ticks, delta): "Add a delta to a base number of ticks, performing wraparound at 2**29ms." return (a + b) % _TICKS_PERIOD def ticks_diff(ticks1, ticks2): "Compute the signed difference between two ticks values, assuming that they are within 2**28 ticks" diff = (ticks1 - ticks2) & _TICKS_MAX diff = ((diff + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD return diff def ticks_less(ticks1, ticks2): "Return true iff ticks1 is less than ticks2, assuming that they are within 2**28 ticks" return ticks_diff(ticks1, ticks2) < 0
get_previous_traceback() → Optional[str]¶
If the last vm run ended with an exception (including the KeyboardInterrupt caused by CTRL-C), returns the traceback as a string. Otherwise, returns
An exception traceback is only preserved over a soft reload, a hard reset clears it.
Only code (main or boot) runs are considered, not REPL runs.
disable_ble_workflow() → None¶
Disable ble workflow until a reset. This prevents BLE advertising outside of the VM and the services used for it.
The reason that CircuitPython started running.
CircuitPython started the microcontroller started up. See
microcontroller.Processor.reset_reasonfor more detail on why the microcontroller was started.
CircuitPython restarted due to an external write to the filesystem.
CircuitPython started due to the user typing CTRL-D in the REPL.
Current status of runtime objects.
import supervisor if supervisor.runtime.serial_connected: print("Hello World!")
Returns the USB enumeration status (read-only).
Returns the USB serial communication status (read-only).
Returns the whether any bytes are available to read on the USB serial input. Allows for polling to see whether to call the built-in input() or wait. (read-only)
Returns why CircuitPython started running this particular time.