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:

stateTrue 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.

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 than period. This is a non-blocking operation. The LED will continue to blink until you call light_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)

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 the light_blink_stop() function to stop the blinking LED.

Parameters:

light – The RGB channels to set.

Added in version 1.0.0.

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,
) bool

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(). The volume parameter accepts values from SPEAKER_VOLUME_MIN (silent) up to SPEAKER_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(). The volume 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.

Buttons

flipperzero.INPUT_BUTTON_UP: int

Constant value for the up button.

Added in version 1.0.0.

flipperzero.INPUT_BUTTON_DOWN: int

Constant value for the down button.

Added in version 1.0.0.

flipperzero.INPUT_BUTTON_RIGHT: int

Constant value for the right button.

Added in version 1.0.0.

flipperzero.INPUT_BUTTON_LEFT: int

Constant value for the left button.

Added in version 1.0.0.

flipperzero.INPUT_BUTTON_OK: int

Constant value for the ok button.

Added in version 1.0.0.

flipperzero.INPUT_BUTTON_BACK: int

Constant value for the back button.

Added in version 1.0.0.

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 and y coordinates when writing on the canvas, using the canvas_set_text() function.

Parameters:
  • x – The horizontal alignment.

  • y – The vertical alignment.

Added in version 1.0.0.

Texts

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 and y 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

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,
) None

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,
) None

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,
) None

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,
) None

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,
) None

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,
) None

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,
) bool

Initialize a GPIO pin.

Parameters:
Returns:

True on success, False otherwise.

Added in version 1.2.0.

Changed in version 1.3.0: The return value changed from None to bool.

Hint

The interrupt modes GPIO_MODE_INTERRUPT_RISE and GPIO_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,
) bool

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,
) List[int]

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,
) bool

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_pinTrue to use an external IR LED on GPIO pin flipperzero.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.

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',
file=None,
flush=False,
) None

The standard Python print function.

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.

Attention

This function prints to the internal log buffer. Check out the Flipper Zero docs on how to reveal them in the CLI interface.