Reference¶
This page contains the API documentation of the flipperzero
module and some built-in functions.
The module is also available as a Python package on PyPI.
Install it in your local development environment if you need code completion support inside your IDE.
Vibration¶
Control the vibration motor of your Flipper.
- flipperzero.vibro_set(state: bool) bool ¶
Turn vibration on or off. This is a non-blocking operation. The vibration motor will continue to run until you stop it.
- Parameters:
state –
True
to turn on vibration.- Returns:
True
if vibration is on.
Added in version 1.0.0.
Light¶
Control the RGB LED and display backlight of your Flipper.
Constants¶
- flipperzero.LIGHT_RED: int¶
Constant value for the red LED light.
Added in version 1.0.0.
- flipperzero.LIGHT_GREEN: int¶
Constant value for the green LED light.
Added in version 1.0.0.
- flipperzero.LIGHT_BLUE: int¶
Constant value for the blue LED light.
Added in version 1.0.0.
- flipperzero.LIGHT_BACKLIGHT: int¶
Constant value for the display backlight.
Added in version 1.0.0.
Functions¶
- flipperzero.light_set(light: int, brightness: int) None ¶
Control the RGB LED on your Flipper. You can also set the brightness of multiple channels at once using bitwise operations. The
brightness
parameter accepts values from 0 (light off) to 255 (very bright).- Parameters:
light – The RGB channels to set.
brightness – The brightness to use.
Added in version 1.0.0.
import flipperzero as f0 f0.light_set(f0.LIGHT_RED | f0.LIGHT_GREEN, 250)
Tip
You can use up to seven colors using additive mixing.
- flipperzero.light_blink_start(
- light: int,
- brightness: int,
- on_time: int,
- period: int,
Let the RGB LED blink. You can define the total duration of a blink period and the duration, the LED is active during a blink period. Hence,
on_time
must be smaller thanperiod
. This is a non-blocking operation. The LED will continue to blink until you calllight_blink_stop()
.- Parameters:
light – The RGB channels to set.
brightness – The brightness to use.
on_time – The LED’s active duration in milliseconds.
period – Total duration of a blink period in milliseconds.
Added in version 1.0.0.
import flipperzero as f0 f0.light_blink_start(f0.LIGHT_RED, 150, 100, 200)
- flipperzero.light_blink_set_color(light: int) None ¶
Change the RGB LED’s color while blinking. This is a non-blocking operation. Be aware, that you must start the blinking procedure first by using the
light_blink_start()
function. Call thelight_blink_stop()
function to stop the blinking LED.- Parameters:
light – The RGB channels to set.
Added in version 1.0.0.
- flipperzero.light_blink_stop() None ¶
Stop the blinking LED.
Added in version 1.0.0.
Speaker¶
Full control over the built-in speaker module.
Musical Notes¶
- flipperzero.SPEAKER_NOTE_C0: float¶
The musical note C0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_CS0: float¶
The musical note C#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_D0: float¶
The musical note D0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_DS0: float¶
The musical note D#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_E0: float¶
The musical note E0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_F0: float¶
The musical note F0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_FS0: float¶
The musical note F#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_G0: float¶
The musical note G0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_GS0: float¶
The musical note G#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_A0: float¶
The musical note A0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_AS0: float¶
The musical note A#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_B0: float¶
The musical note B0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_C1: float¶
The musical note C0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_CS1: float¶
The musical note C#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_D1: float¶
The musical note D0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_DS1: float¶
The musical note D#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_E1: float¶
The musical note E0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_F1: float¶
The musical note F0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_FS1: float¶
The musical note F#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_G1: float¶
The musical note G0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_GS1: float¶
The musical note G#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_A1: float¶
The musical note A0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_AS1: float¶
The musical note A#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_B1: float¶
The musical note B0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_C2: float¶
The musical note C0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_CS2: float¶
The musical note C#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_D2: float¶
The musical note D0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_DS2: float¶
The musical note D#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_E2: float¶
The musical note E0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_F2: float¶
The musical note F0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_FS2: float¶
The musical note F#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_G2: float¶
The musical note G0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_GS2: float¶
The musical note G#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_A2: float¶
The musical note A0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_AS2: float¶
The musical note A#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_B2: float¶
The musical note B0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_C3: float¶
The musical note C0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_CS3: float¶
The musical note C#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_D3: float¶
The musical note D0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_DS3: float¶
The musical note D#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_E3: float¶
The musical note E0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_F3: float¶
The musical note F0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_FS3: float¶
The musical note F#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_G3: float¶
The musical note G0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_GS3: float¶
The musical note G#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_A3: float¶
The musical note A0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_AS3: float¶
The musical note A#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_B3: float¶
The musical note B0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_C4: float¶
The musical note C0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_CS4: float¶
The musical note C#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_D4: float¶
The musical note D0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_DS4: float¶
The musical note D#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_E4: float¶
The musical note E0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_F4: float¶
The musical note F0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_FS4: float¶
The musical note F#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_G4: float¶
The musical note G0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_GS4: float¶
The musical note G#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_A4: float¶
The musical note A0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_AS4: float¶
The musical note A#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_B4: float¶
The musical note B0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_C5: float¶
The musical note C0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_CS5: float¶
The musical note C#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_D5: float¶
The musical note D0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_DS5: float¶
The musical note D#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_E5: float¶
The musical note E0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_F5: float¶
The musical note F0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_FS5: float¶
The musical note F#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_G5: float¶
The musical note G0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_GS5: float¶
The musical note G#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_A5: float¶
The musical note A0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_AS5: float¶
The musical note A#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_B5: float¶
The musical note B0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_C6: float¶
The musical note C0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_CS6: float¶
The musical note C#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_D6: float¶
The musical note D0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_DS6: float¶
The musical note D#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_E6: float¶
The musical note E0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_F6: float¶
The musical note F0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_FS6: float¶
The musical note F#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_G6: float¶
The musical note G0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_GS6: float¶
The musical note G#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_A6: float¶
The musical note A0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_AS6: float¶
The musical note A#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_B6: float¶
The musical note B0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_C7: float¶
The musical note C0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_CS7: float¶
The musical note C#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_D7: float¶
The musical note D0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_DS7: float¶
The musical note D#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_E7: float¶
The musical note E0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_F7: float¶
The musical note F0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_FS7: float¶
The musical note F#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_G7: float¶
The musical note G0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_GS7: float¶
The musical note G#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_A7: float¶
The musical note A0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_AS7: float¶
The musical note A#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_B7: float¶
The musical note B0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_C8: float¶
The musical note C0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_CS8: float¶
The musical note C#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_D8: float¶
The musical note D0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_DS8: float¶
The musical note D#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_E8: float¶
The musical note E0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_F8: float¶
The musical note F0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_FS8: float¶
The musical note F#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_G8: float¶
The musical note G0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_GS8: float¶
The musical note G#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_A8: float¶
The musical note A0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_AS8: float¶
The musical note A#0 as frequency in Hz.
Added in version 1.2.0.
- flipperzero.SPEAKER_NOTE_B8: float¶
The musical note B0 as frequency in Hz.
Added in version 1.2.0.
Volume¶
- flipperzero.SPEAKER_VOLUME_MIN: float¶
The minimal volume value.
Added in version 1.2.0.
- flipperzero.SPEAKER_VOLUME_MAX: float¶
The maximum volume value.
Added in version 1.2.0.
Functions¶
- flipperzero.speaker_start(
- frequency: float,
- volume: float,
Output a steady tone of a defined frequency and volume on the Flipper’s speaker. This is a non-blocking operation. The tone will continue until you call
speaker_stop()
. Thevolume
parameter accepts values fromSPEAKER_VOLUME_MIN
(silent) up toSPEAKER_VOLUME_MAX
(very loud).- Parameters:
frequency – The frequency to play in Hz.
volume – The volume to use.
- Returns:
True
if the speaker was acquired.
Added in version 1.0.0.
import flipperzero as f0 f0.speaker_start(50.0, 0.8)
- flipperzero.speaker_set_volume(volume: float) bool ¶
Set the speaker’s volume while playing a tone. This is a non-blocking operation. The tone will continue until you call
speaker_stop()
. Thevolume
parameter accepts values from 0.0 (silent) up to 1.0 (very loud).- Parameters:
volume – The volume to use.
- Returns:
True
if the speaker was acquired.
Added in version 1.0.0.
This function can be used to play nice sounds:
import time import flipperzero as f0 volume = 0.8 f0.speaker_start(100.0, volume) for _ in range(0, 150): volume *= 0.9945679 f0.speaker_set_volume(volume) time.sleep_ms(1) f0.speaker_stop()
- flipperzero.speaker_stop() bool ¶
Stop the speaker output.
- Returns:
True
if the speaker was successfully released.
Added in version 1.0.0.
Input¶
Make your application interactive with full control over the Flipper’s hardware buttons.
Events¶
- flipperzero.INPUT_TYPE_PRESS: int¶
Constant value for the press event of a button.
Added in version 1.0.0.
- flipperzero.INPUT_TYPE_RELEASE: int¶
Constant value for the release event of a button.
Added in version 1.0.0.
- flipperzero.INPUT_TYPE_SHORT: int¶
Constant value for the short press event of a button.
Added in version 1.0.0.
- flipperzero.INPUT_TYPE_LONG: int¶
Constant value for the long press event of a button.
Added in version 1.0.0.
- flipperzero.INPUT_TYPE_REPEAT: int¶
Constant value for the repeat press event of a button.
Added in version 1.0.0.
Functions¶
- @flipperzero.on_input Callable[[int, int], None] ¶
Decorate a function to be used as input handler. The decorated function will be invoked upon interaction with one of the buttons on the Flipper.
Added in version 1.0.0.
import flipperzero as f0 @f0.on_input def input_handler(button, type): if button == f0.INPUT_BUTTON_BACK: if type == f0.INPUT_TYPE_LONG: ...
Warning
You can only decorate one function per application.
Canvas¶
Write text and draw dots and shapes on the the display.
Basics¶
- flipperzero.canvas_update() None ¶
Updates the display buffer with your drawings from the canvas.
Added in version 1.0.0.
Note
Your drawings will only appear on the display after this function call.
- flipperzero.canvas_clear() None ¶
Clear the whole canvas. This does not affect the current display buffer. You need to call
canvas_update()
to reveal your changes.Added in version 1.0.0.
- flipperzero.canvas_width() int ¶
Get the canvas width in pixels.
Added in version 1.0.0.
- Returns:
The canvas width.
- flipperzero.canvas_height() int ¶
Get the canvas height in pixels.
Added in version 1.0.0.
- Returns:
The canvas height.
Colors¶
- flipperzero.COLOR_BLACK: int¶
Constant value for the color black.
Added in version 1.0.0.
- flipperzero.COLOR_WHITE: int¶
Constant value for the color white.
Added in version 1.0.0.
- flipperzero.canvas_set_color(color: int) None ¶
Set the color to use when drawing or writing on the canvas.
Added in version 1.0.0.
- Parameters:
color – The color to use.
Alignment¶
- flipperzero.ALIGN_BEGIN: int¶
Align element at begin (horizontal or vertical, depends on the context).
Added in version 1.0.0.
- flipperzero.ALIGN_END: int¶
Align element at end (horizontal or vertical, depends on the context).
Added in version 1.0.0.
- flipperzero.ALIGN_CENTER: int¶
Align element at center (horizontal or vertical, depends on the context).
Added in version 1.0.0.
- flipperzero.canvas_set_text_align(x: int, y: int) None ¶
Define how the text should be aligned in relation to the
x
andy
coordinates when writing on the canvas, using thecanvas_set_text()
function.- Parameters:
x – The horizontal alignment.
y – The vertical alignment.
Added in version 1.0.0.
Text¶
- flipperzero.FONT_PRIMARY: int¶
Constant value for the primary font.
Added in version 1.0.0.
- flipperzero.FONT_SECONDARY: int¶
Constant value for the secondary font.
Added in version 1.0.0.
- flipperzero.canvas_set_font(font: int) None ¶
Change the font to use when writing on the canvas using the
canvas_set_text()
function.- Parameters:
font – The font to use.
Added in version 1.0.0.
- flipperzero.canvas_set_text(x: int, y: int, text: str) None ¶
Write text on the canvas at the position of
x
andy
by using the currently active color, font and alignment settings.- Parameters:
x – The horizontal position.
y – The vertical position.
text – The text to write.
Added in version 1.0.0.
import flipperzero as f0 f0.canvas_set_color(f0.COLOR_BLACK) f0.canvas_set_text_align(f0.ALIGN_CENTER, f0.ALIGN_BEGIN) f0.canvas_set_text(64, 32, 'Hello World!') f0.canvas_update()
See also
canvas_set_color()
to change the canvas color.canvas_set_text_align()
to change the alignment settings.canvas_set_font()
to change the current font.
Shapes¶
- flipperzero.canvas_draw_dot(x: int, y: int) None ¶
Draw a dot on the canvas by using the currently active color settings.
- Parameters:
x – The horizontal position.
y – The vertical position.
Added in version 1.0.0.
- flipperzero.canvas_draw_box(
- x: int,
- y: int,
- w: int,
- h: int,
- r: int,
Draw a box on the canvas. The fill color is defined by the currently active color settings. Set the corner radius to zero to draw a rectangle without rounded corners.
- Parameters:
x – The horizontal position.
y – The vertical position.
w – The width of the box.
h – The height of the box.
r – The corner radius to use.
Added in version 1.0.0.
- flipperzero.canvas_draw_frame(
- x: int,
- y: int,
- w: int,
- h: int,
- r: int,
Draw a frame on the canvas. The border color is defined by the currently active color settings. Set the corner radius to zero to draw a rectangle without rounded corners.
- Parameters:
x – The horizontal position.
y – The vertical position.
w – The width of the box.
h – The height of the box.
r – The corner radius to use.
Added in version 1.0.0.
- flipperzero.canvas_draw_line(
- x0: int,
- y0: int,
- x1: int,
- y1: int,
Draw a line on the canvas. The color is defined by the currently active color settings.
- Parameters:
x0 – The horizontal start position.
y0 – The vertical start position.
x1 – The horizontal end position.
y1 – The vertical end sposition.
Added in version 1.0.0.
- flipperzero.canvas_draw_circle(x: int, y: int, r: int) None ¶
Draw a circle on the canvas. The border color is defined by the currently active color settings.
- Parameters:
x – The horizontal position.
y – The vertical position.
r – The radius to use.
Added in version 1.0.0.
- flipperzero.canvas_draw_disc(x: int, y: int, r: int) None ¶
Draw a disc on the canvas. The fill color is defined by the currently active color settings.
- Parameters:
x – The horizontal position.
y – The vertical position.
r – The radius to use.
Added in version 1.0.0.
Dialog¶
Display message dialogs on the display for user infos and confirm actions.
- flipperzero.dialog_message_set_header(
- text: str,
- x: int,
- y: int,
- h: int,
- v: int,
Set a header text on the dialog box.
- Parameters:
text – The text to set.
x – The x coordinates to use.
y – The y coordinates to use.
h – The horizontal alignment.
v – The vertical alignment.
Added in version 1.0.0.
- flipperzero.dialog_message_set_text(
- text: str,
- x: int,
- y: int,
- h: int,
- v: int,
Set a text on the dialog box.
- Parameters:
text – The text to set.
x – The x coordinates to use.
y – The y coordinates to use.
h – The horizontal alignment.
v – The vertical alignment.
Added in version 1.0.0.
- flipperzero.dialog_message_set_button(
- text: str,
- button: int,
Set the text of a dialog box button.
- Parameters:
text – The text to set.
button – The button to use (e.g.
INPUT_BUTTON_UP
).
Added in version 1.0.0.
- flipperzero.dialog_message_show() int ¶
Display the dialog box with the configured settings. This function is blocking.
- Returns:
The button code, used to close the dialog (e.g.
INPUT_BUTTON_OK
)
Added in version 1.0.0.
import flipperzero as f0 f0.dialog_message_set_header('Important',64, 12) f0.dialog_message_set_text('It this awesome?', 64, 24) f0.dialog_message_set_button('Yes', f0.INPUT_BUTTON_LEFT) f0.dialog_message_set_button('No', f0.INPUT_BUTTON_RIGHT) while f0.dialog_message_show() is not f0.INPUT_BUTTON_LEFT: pass
GPIO¶
Access to the GPIO pins of your Flipper.
Pins¶
- flipperzero.GPIO_PIN_PC0: int¶
Constant identifier for GPIO pin PC0.
This pin can be used as ADC input.
Added in version 1.2.0.
- flipperzero.GPIO_PIN_PC1: int¶
Constant identifier for GPIO pin PC1.
This pin can be used as ADC input.
Added in version 1.2.0.
- flipperzero.GPIO_PIN_PC3: int¶
Constant identifier for GPIO pin PC3.
This pin can be used as ADC input.
Added in version 1.2.0.
- flipperzero.GPIO_PIN_PB2: int¶
Constant identifier for GPIO pin PB2.
Added in version 1.2.0.
- flipperzero.GPIO_PIN_PB3: int¶
Constant identifier for GPIO pin PB3.
Added in version 1.2.0.
- flipperzero.GPIO_PIN_PA4: int¶
Constant identifier for GPIO pin PA4.
This pin can be used as ADC input.
This pin can be used as PWM output.
Added in version 1.2.0.
- flipperzero.GPIO_PIN_PA6: int¶
Constant identifier for GPIO pin PA6.
This pin can be used as ADC input.
Added in version 1.2.0.
- flipperzero.GPIO_PIN_PA7: int¶
Constant identifier for GPIO pin PA7.
This pin can be used as ADC input.
This pin can be used as PWM output.
This pin can be used to transmit an infrared signal with an IR LED.
Added in version 1.2.0.
Modes¶
- flipperzero.GPIO_MODE_INPUT: int¶
Constant configuration value for the GPIO input mode.
Added in version 1.2.0.
- flipperzero.GPIO_MODE_OUTPUT_PUSH_PULL: int¶
Constant configuration value for the GPIO output as push-pull mode.
Added in version 1.2.0.
- flipperzero.GPIO_MODE_OUTPUT_OPEN_DRAIN: int¶
Constant configuration value for the GPIO output as open-drain mode.
Added in version 1.2.0.
- flipperzero.GPIO_MODE_ANALOG: int¶
Constant configuration value for the GPIO analog mode.
Added in version 1.2.0.
- flipperzero.GPIO_MODE_INTERRUPT_RISE: int¶
Constant configuration value for the GPIO interrupt on rising edges mode.
Added in version 1.2.0.
- flipperzero.GPIO_MODE_INTERRUPT_FALL: int¶
Constant configuration value for the GPIO interrupt on falling edges mode.
Added in version 1.2.0.
Pull¶
- flipperzero.GPIO_PULL_NO: int¶
Constant configuration value for the GPIO internal pull resistor disabled.
Added in version 1.2.0.
- flipperzero.GPIO_PULL_UP: int¶
Constant configuration value for the GPIO internal pull-up resistor enabled.
Added in version 1.2.0.
- flipperzero.GPIO_PULL_DOWN: int¶
Constant configuration value for the GPIO internal pull-down resistor enabled.
Added in version 1.2.0.
Speed¶
- flipperzero.GPIO_SPEED_LOW: int¶
Constant configuration value for the GPIO in low speed.
Added in version 1.2.0.
- flipperzero.GPIO_SPEED_MEDIUM: int¶
Constant configuration value for the GPIO in medium speed.
Added in version 1.2.0.
- flipperzero.GPIO_SPEED_HIGH: int¶
Constant configuration value for the GPIO in high speed.
Added in version 1.2.0.
- flipperzero.GPIO_SPEED_VERY_HIGH: int¶
Constant configuration value for the GPIO in very high speed.
Added in version 1.2.0.
Functions¶
- flipperzero.gpio_init_pin(
- pin: int,
- mode: int,
- pull: int = None,
- speed: int = None,
Initialize a GPIO pin.
- Parameters:
pin – The pin to initialize (e.g.
GPIO_PIN_PA4
).mode – The mode to use (e.g.
GPIO_MODE_INPUT
).pull – The pull resistor to use. Default is
GPIO_PULL_NO
.speed – The speed to use. Default is
GPIO_SPEED_LOW
.
- Returns:
True
on success,False
otherwise.
Added in version 1.2.0.
Changed in version 1.3.0: The return value changed from
None
tobool
.Hint
The interrupt modes
GPIO_MODE_INTERRUPT_RISE
andGPIO_MODE_INTERRUPT_FALL
can be combined using bitwise OR. This allows you to handle rising and falling edges.
- flipperzero.gpio_deinit_pin(pin: int) None ¶
Deinitialize a GPIO pin.
- Parameters:
pin – The pin to deinitialize (e.g.
GPIO_PIN_PA4
).
Added in version 1.3.0.
Note
It’s not strictly necessary to deinitialize your GPIO pins upon script termination, this is already covered by the interpreter.
- flipperzero.gpio_set_pin(pin: int, state: bool) None ¶
Set the state of an output pin.
- Parameters:
pin – The pin to set (e.g.
GPIO_PIN_PA4
).state – The state to set.
Added in version 1.2.0.
Hint
Don’t forget to initialize the pin first.
- flipperzero.gpio_get_pin(pin: int) bool ¶
Read the state of an input pin.
- Parameters:
pin – The pin to read (e.g.
GPIO_PIN_PA4
).- Returns:
True
if the pin is high,False
on a low signal.
Added in version 1.2.0.
Hint
Don’t forget to initialize the pin first.
- @flipperzero.on_gpio Callable[[int], None] ¶
Decorate a function to be used as GPIO interrupt handler. The decorated function will be invoked upon a GPIO interrupt.
Added in version 1.0.0.
import flipperzero as f0 f0.gpio_init_pin(f0.GPIO_PIN_PC0, f0.GPIO_MODE_INTERRUPT_RISE, f0.GPIO_PULL_UP) @f0.on_gpio def interrupt_handler(pin): if pin == f0.GPIO_PIN_PC0: ...
Warning
You can only decorate one function per application.
ADC¶
Read analog values from selected GPIO pins:
The corresponding pin must be initialized in the analog mode:
import flipperzero as f0
f0.gpio_init_pin(f0.GPIO_PIN_PC0, f0.GPIO_MODE_ANALOG)
This configures the pin as ADC input with the following settings:
Reference voltage is set to 2.048 V.
Clock speed is at 64 MHz in synchronous mode.
Oversample rate is set to 64.
This default configuration is best for relatively high impedance circuits with slowly or or not changing signals.
Functions¶
- flipperzero.adc_read_pin_value(pin: int) int ¶
Read the raw value from the ADC channel.
- Parameters:
pin – The pin to read (e.g.
GPIO_PIN_PC1
).- Returns:
The raw value between 0 and 4095.
Added in version 1.3.0.
Hint
Don’t forget to initialize the pin first.
- flipperzero.adc_read_pin_voltage(pin: int) float ¶
Read the voltage from the ADC channel.
- Parameters:
pin – The pin to read (e.g.
GPIO_PIN_PC1
).- Returns:
The voltage between 0 - 2.048 V with a precision of ~0.1%.
Added in version 1.3.0.
Hint
Don’t forget to initialize the pin first.
PWM¶
Output a PWM signal on selected GPIO pins:
Functions¶
- flipperzero.pwm_start(
- pin: int,
- frequency: int,
- duty: int,
Start or change the PWM signal on the corresponding GPIO pin.
- Parameters:
pin – The pin to read (e.g.
GPIO_PIN_PA7
).frequency – The frequency to set in Hz.
duty – The duty cycle per period in percent.
- Returns:
True
on success,False
otherwise.
Added in version 1.3.0.
Warning
You don’t have to initialize the pin first.
- flipperzero.pwm_stop(pin: int) None ¶
Stop the PWM signal on the corresponding GPIO pin.
- Parameters:
pin – The pin to use (e.g.
GPIO_PIN_PA7
).
Added in version 1.3.0.
- flipperzero.pwm_is_running(pin: int) bool ¶
Check if the corresponding GPIO pin has a PWM signal output.
- Parameters:
pin – The pin to check (e.g.
GPIO_PIN_PA7
).- Returns:
True
on success,False
otherwise.
Added in version 1.3.0.
Infrared¶
Send and receive infrared signals.
Signal Format¶
The format to represent infrared signals uses a simple list of integers. Each value represents the duration between two signal edges in microseconds. Since this is a digital signal, there are only two levels: high and low. The timing list always starts with a high level.
────┐ ┌──┐ ┌────┐ ┌──┐ ┌────┐ ┌ ⋅ ⋅ ⋅
│ │ │ │ │ │ │ │ │ │
└───────┘ └────┘ └──────┘ └──────────────┘ └──────┘
40 | 70 |20| 40 | 40 | 60 |20| 140 | 40 | 60 | ⋅ ⋅ ⋅
Hint
This is equal to the raw signal format of the IR file specification.
Functions¶
- flipperzero.infrared_receive(
- timeout: int = 1000000,
Receive an infrared signal. This is a blocking method. The method blocks until a timeout occurs or the internal signal buffer (capacity is 1024 timings) is filled.
- Parameters:
timeout – The timeout to use in microseconds.
- Returns:
A list of timings in microseconds, starting with high.
Added in version 1.3.0.
- flipperzero.infrared_transmit(
- signal: List[int],
- repeat: int = 1,
- use_external_pin: bool = False,
- frequency: int = 38000,
- duty: float = 0.33,
Transmit an infrared signal. This is a blocking method. The method blocks until the whole signal is sent. The signal list has the same format as the return value of
infrared_receive()
. Hence you can directly re-send a received signal without any further processing.- Parameters:
signal – The signal to use.
repeat – How many times the signal should be sent.
use_external_pin –
True
to use an external IR LED on GPIO pinflipperzero.GPIO_PIN_PA7
.frequency – The frequency to use for the PWM signal.
duty – The duty cycle to use for the PWM signal.
- Returns:
True
on success,False
otherwise.
Added in version 1.3.0.
- flipperzero.infrared_is_busy() bool ¶
Check if the infrared subsystem is busy.
- Returns:
True
if occupied,False
otherwise.
Added in version 1.3.0.
UART¶
Connect to UART enabled devices.
Modes¶
- flipperzero.UART_MODE_LPUART: int¶
Constant value for the low power UART mode.
Added in version 1.5.0.
- flipperzero.UART_MODE_USART: int¶
Constant value for the USART mode.
Added in version 1.5.0.
Functions¶
- flipperzero.uart_open(
- mode: int,
- baud_rate: int,
Open a connection to an UART enabled device by using the specified mode and baud rate.
- Parameters:
mode – The mode to use, either
UART_MODE_LPUART
orUART_MODE_USART
.baud_rate – The baud rate to use.
- Returns:
A
UART
object on success,None
otherwise.
Added in version 1.5.0.
import flipperzero as f0 with f0.uart_open(f0.UART_MODE_USART, 115200) as uart: ...
Classes¶
- class flipperzero.UART¶
This represents an UART connection. The class has no
__init__
method, useuart_open()
to start an UART connection and receive an instance.Added in version 1.5.0.
An
UART
instance is iterable:import flipperzero as f0 with f0.open(f0.UART_MODE_USART, 115200) as uart: lines = [line for line in uart]
An
UART
instance can be used with a context manager:import flipperzero as f0 with f0.open(f0.UART_MODE_USART, 115200) as uart: ...
Hint
The read and write methods are non-blocking in terms of data availability. They don’t block code execution upon data is available. Just an empty result will be returned.
- read(size: int = -1) bytes ¶
Read from the connection. The method will read up to
size
bytes and return them. Ifsize
is not specified, all available data will be returned. The method will return zero bytes, if no data is available.- Parameters:
size – The maximum number of bytes to read.
- Returns:
Up to
size
bytes.
Added in version 1.5.0.
- readline(size: int = -1) bytes ¶
Read and return one line from the connection. If
size
is specified, at mostsize
bytes will be read. The line terminator is alwaysb'\n'
.- Parameters:
size – The maximum number of bytes to read.
- Returns:
Up to
size
bytes.
Added in version 1.5.0.
- readlines() List[bytes] ¶
Read and return a list of lines from the connection. The line terminator is always
b'\n'
.- Returns:
A list of bytes.
Added in version 1.5.0.
- write(data: bytes) int ¶
Write the given bytes to the connection stream. The number of written bytes will be returned. This can be less than the length of the provided data. Be aware, that the data is not sent synchronously. Call
flush()
if you have to wait for the data to be sent.- Parameters:
data – The data to transmit.
- Returns:
The number of bytes sent.
Added in version 1.5.0.
- flush() None ¶
Flush the transmission buffer to the underlying UART connection. This method blocks until all data is sent.
Added in version 1.5.0.
- close() None ¶
Close the UART connection.
Added in version 1.5.0.
- __enter__() UART ¶
This method is invoked, when the instance enters a runtime context.
- Returns:
The
UART
connection.
Added in version 1.5.0.
Logging¶
Log messages to the Flipper’s own logging backend. Check out the Flipper Zero docs on how to reveal them in the CLI. Be aware, that you can’t change Flipper’s global log level from within your script. Change the corresponding settings instead or use the log command in the CLI with the desired log level as the first argument.
Levels¶
- logging.TRACE: int = 6¶
Constant value for the trace log level.
Added in version 1.5.0.
- logging.DEBUG: int = 5¶
Constant value for the debug log level.
Added in version 1.5.0.
- logging.INFO: int = 4¶
Constant value for the info log level.
Added in version 1.5.0.
- logging.WARN: int = 3¶
Constant value for the warn log level.
Added in version 1.5.0.
- logging.ERROR: int = 2¶
Constant value for the error log level.
Added in version 1.5.0.
- logging.NONE: int = 1¶
Constant value for logging disabled.
Added in version 1.5.0.
- logging.level: int¶
The threshold log level, as set by the
setLevel()
function. The initial value is set to theINFO
level.Added in version 1.5.0.
Hint
Don’t change the value of this variable, use
setLevel()
instead.
Functions¶
- logging.setLevel(level: int) None ¶
Set the current log level of the application.
- Parameters:
level – The log level to set (e.g.
INFO
).
Added in version 1.5.0.
Hint
This doesn’t change the Flipper’s effective log level settings. Check out the Flipper’s documentation for details on this topic.
- logging.getEffectiveLevel() int ¶
Get the effective log level from the Flipper’s settings.
- Returns:
The effective log level.
Added in version 1.5.0.
- logging.trace(message: str, *args) None ¶
Log a message with level
TRACE
. Themessage
argument can be a format string with%
placeholders. No % formatting operation is performed whenargs
is empty.- Parameters:
message – The message to log.
args – Values for the % formatting.
Added in version 1.5.0.
import logging value = 42 logging.trace('value is %d', value)
- logging.debug(message: str, *args) None ¶
Log a message with level
DEBUG
. Seetrace()
for details on the usage.- Parameters:
message – The message to log.
args – Values for the % formatting.
Added in version 1.5.0.
- logging.info(message: str, *args) None ¶
Log a message with level
INFO
. Seetrace()
for details on the usage.- Parameters:
message – The message to log.
args – Values for the % formatting.
Added in version 1.5.0.
- logging.warn(message: str, *args) None ¶
Log a message with level
WARN
. Seetrace()
for details on the usage.- Parameters:
message – The message to log.
args – Values for the % formatting.
Added in version 1.5.0.
I/O¶
Read and write SD card files.
Constants¶
- io.SEEK_SET: int = 0¶
Set the pointer position relative to the beginning of the stream.
Added in version 1.5.0.
- io.SEEK_CUR: int = 1¶
Set the pointer position relative to the current position.
Added in version 1.5.0.
- io.SEEK_END: int = 2¶
Set the pointer position relative to the end of the stream.
Added in version 1.5.0.
Functions¶
- io.open(
- path: str,
- mode: str,
- *args,
- **kwargs,
Open a file on the file system with the specified mode. The file path must always be absolute, beginning with
/ext
. The following modifiers are available:Character
Description
'r'
Open for reading. This is the default. Will fail, if the file not exists.
'w'
Open for writing, truncating an existing file first.
'b'
Open the file in binary mode. The return value will be a
BinaryFileIO
instance.'t'
Open the in text mode. This is the default. The return value will be a
TextFileIO
instance.'+'
Open for reading and writing. Will create the file, if it not exists. The pointer will be placed at the end of the file.
The modifiers can be combined, e.g.
'rb+'
would open a file for reading and writing in binary mode.- Parameters:
path – The path to the file to open.
mode – How the file should be opened.
args – Is ignored at the moment.
kwargs – Is ignored at the moment.
Added in version 1.5.0.
Classes¶
- class io.BinaryFileIO¶
Represents a file, opened in binary mode.
Added in version 1.5.0.
- name: str¶
The name of the file.
Added in version 1.5.0.
- readable: bool¶
Read-only attribute, indicating if the file is readable.
Added in version 1.5.0.
- writable: bool¶
Read-only attribute, indicating if the file is writable.
Added in version 1.5.0.
- read(size: int = -1) bytes ¶
Read from the file. The method will read up to
size
bytes and return them. Ifsize
is not specified, all content up to EOF will be returned. If the internal pointer is already at EOF, an empty byte stringb''
will be returned.- Parameters:
size – The maximum number of bytes to read.
- Returns:
Up to
size
bytes.
Added in version 1.5.0.
- readline(size: int = -1) bytes ¶
Read and return one line from the file. If
size
is specified, at mostsize
bytes will be read. The line terminator is defined asb'\n'
. The new line character is included in the return value. If the internal pointer is at EOF, an empty byte stringb''
will be returned.- Parameters:
size – The maximum number of bytes to read.
- Returns:
Up to
size
bytes.
Added in version 1.5.0.
- readlines() List[bytes] ¶
Read and return a list of lines from the file. The line terminator is defined as
b'\n'
. The new line character is included in the return value. If the internal pointer is at EOF, an empty list will be returned.- Returns:
A list of bytes.
Added in version 1.5.0.
- write(data: bytes) int ¶
Write the given bytes to the file. The number of written bytes will be returned. This can be less than the length of the provided data.
- Parameters:
data – The data to write.
- Returns:
The number of bytes written.
Added in version 1.5.0.
- flush() None ¶
Write the contents of the file buffer to the file on the SD card.
Added in version 1.5.0.
- seek(
- offset: int,
- whence: int = 0,
Set the pointer position by the given
offset
, relative to the position indicated bywhence
. The new absolute position will be returned.- Parameters:
offset – The offset to use.
whence – How to interpret the offset (e.g.
SEEK_SET
).
- Returns:
The new absolute position.
Added in version 1.5.0.
- tell() int ¶
Get the current pointer position.
- Returns:
The absolute position of the pointer.
Added in version 1.5.0.
- close() None ¶
Close the file handle.
Added in version 1.5.0.
- __enter__() BinaryFileIO ¶
This method is invoked, when the instance enters a runtime context.
- Returns:
The
BinaryFileIO
instance.
Added in version 1.5.0.
- class io.TextFileIO¶
Represents a file, opened in text mode.
Added in version 1.5.0.
- name: str¶
The name of the file.
Added in version 1.5.0.
- readable: bool¶
Read-only attribute, indicating if the file is readable.
Added in version 1.5.0.
- writable: bool¶
Read-only attribute, indicating if the file is writable.
Added in version 1.5.0.
- read(size: int = -1) str ¶
Read from the file. The method will read up to
size
characters and return them. Ifsize
is not specified, all content up to EOF will be returned. If the internal pointer is already at EOF, an empty string will be returned.- Parameters:
size – The maximum number of characters to read.
- Returns:
Up to
size
characters.
Added in version 1.5.0.
- readline(size: int = -1) str ¶
Read and return one line from the file. If
size
is specified, at mostsize
characters will be read. The line terminator is defined as'\n'
. The new line character is included in the return value. If the internal pointer is at EOF, an empty string will be returned.- Parameters:
size – The maximum number of characters to read.
- Returns:
Up to
size
characters.
Added in version 1.5.0.
- readlines() List[str] ¶
Read and return a list of lines from the file. The line terminator is defined as
'\n'
. The new line character is included in the return value. If the internal pointer is at EOF, an empty list will be returned.- Returns:
A list of strings.
Added in version 1.5.0.
- write(data: str) int ¶
Write the given string to the file. The number of written characters will be returned. This can be less than the length of the provided data.
- Parameters:
data – The data to write.
- Returns:
The number of characters written.
Added in version 1.5.0.
- flush() None ¶
Write the contents of the file buffer to the file on the SD card.
Added in version 1.5.0.
- seek(
- offset: int,
- whence: int = 0,
Set the pointer position by the given
offset
, relative to the position indicated bywhence
. The new absolute position will be returned.- Parameters:
offset – The offset to use.
whence – How to interpret the offset (e.g.
SEEK_SET
).
- Returns:
The new absolute position.
Added in version 1.5.0.
- tell() int ¶
Get the current pointer position.
- Returns:
The absolute position of the pointer.
Added in version 1.5.0.
- close() None ¶
Close the file handle.
Added in version 1.5.0.
- __enter__() TextFileIO ¶
This method is invoked, when the instance enters a runtime context.
- Returns:
The
BinaryFileIO
instance.
Added in version 1.5.0.
Random¶
Generate pseudo-random number for various use cases.
Functions¶
- random.random() float ¶
Get a random float value between 0.0 (inclusive) and 1.0 (exclusive).
- Returns:
The random value.
Added in version 1.6.0.
- random.uniform(a: float, b: float) float ¶
Get a random float value between
a
(inclusive) andb
(inclusive).- Parameters:
a – The lower value.
b – The upper value.
- Returns:
The random value.
Added in version 1.6.0.
- random.randrange(
- start: int,
- stop: int,
- step: int = 1,
Get a random integer between
start
(inclusive) andstop
(exclusive) with an optionalstep
between the values.- Parameters:
start – The start value.
stop – The end value.
step – The optional step value.
- Returns:
The random value.
Added in version 1.6.0.
Hint
This function does only generate integer values.
- random.getrandbits(k: int) int ¶
Get
k
random bits.- Parameters:
k – The number of bits.
- Returns:
The random bits.
Added in version 1.6.0.
- random.randint(a: int, b: int) int ¶
Get a random integer between
a
(inclusive) andb
(inclusive).- Parameters:
a – The lower value.
b – The upper value.
- Returns:
The random value.
Added in version 1.6.0.
- random.choice(seq: list[T]) T ¶
Get a random element from the provided sequence.
- Parameters:
seq – The sequence to use.
- Returns:
A random element.
Added in version 1.6.0.
- random.seed(a: int) None ¶
Initialize the random number generator.
- Parameters:
a – The initialization value to use.
Added in version 1.6.0.
Hint
Random generator seeding is done automatically, so there is no need to call this function.
Built-In¶
The functions in this section are not part of the flipperzero
module.
They’re members of the global namespace instead.
- print(*objects, sep=' ', end='\n') None ¶
The standard Python print function. Where the output of this function will be redirected depends on how the script is invoked:
When invoked from the UI, the output will be sent to the Flipper’s log buffer. Check out the Flipper Zero docs on how to view them in the CLI interface.
In the REPL, the output will be sent to the standard output buffer.
When invoked by the py command, the output will be sent to the standard output buffer.
- Parameters:
objects – The objects to print (mostly a single string).
sep – The separator to use between the objects.
end – The line terminator character to use.
Added in version 1.0.0.
Changed in version 1.5.0: Output redirection, based on script invocation.