Skip to content

Programming in Python

Lucien Murray-Pitts edited this page Oct 7, 2025 · 2 revisions

You can also program the board directly from Pyton!

How to connect to the board to use it with Python

You can connect to the board using the SpotPear OpenBlocks page, and then unlock the Python editor and type your own code here. You will need to place at a minimum the "When spotpear begin".

{FF437BC9-CB8A-4A79-9A86-15A3722515B2}

You can also use any serial terminal program, some examples are TeraTerm and so on. Set it to use 115200, 8, N, 1 and then you can connect and just start typing your code.

Saving a program to run at startup

You can use the terminal to the board to use file tools to "open" main.py, and write to it. After closing the file if you reboot it will run main.py

SpotPear Python Specific Functions

Here we describe all the features we wrote to let you explore the SpotPear board. Everything will need you to import spotpear before you use them such as "from spotpear import *"

Time Related

set_timer( N, time_in_ms, function_to_call_when_timer_expires )

Run one of 5 timers in the background, N=1..5, and it will wait time_in_ms and then it will call function_to_call_when_timer_expires function.

from spotpear import *

def callback_timer_done:
    print("Timer finished!")

set_timer( 1, 1000, callback_timer_done )

sleep( NN_ms )

Sleep for NN_ms.

Display Related

init_display()

Initialize the display, and set the backdrop to blue.

clear_screen( color=0x003a57 )

Clear the screen and set the background color, which is optional.

set_screen_background_color( color )

Change the screen background color.

Others

draw_pixel( x=0, y=0, _color=0xff0000 ) draw_rectangle(x=10, y=10, width=20, height=20, _color=0x00ff00) draw_line(x1=10, y1=10, x2=50, y2=50, _color=0x0000ff, width=2) draw_circle(x=10, y=10, radius=10, _color=0xff0000) display_text_at_position(label_text="Hello World!", x=10, y=10, color=0xffffff, size=14) parse_matrix(input_str) draw_grid(grid, border, square_color, screen_width, screen_height):

LED/PIN/BUTTON Control

set_led( boolean )

Set the LED 1=on, 0=off

set_pin( pin_number, boolean )

Set the pin_number to 1=on, 0=off. pin_number is 1..4 which selects GPIO1, 6, 21, or 20 on the ESP32-C3.

get_button( button_number )

Returns the state of the button 1, or 2 on the board.

Clone this wiki locally