Skip to content

Adding Your Own Code

One of the best features of the Sidekick is its ability to run your own custom MicroPython code. This guide will show you how to create your own simple app.

The custom_code Folder

While you can modify any part of the Sidekick's software, the easiest way to add your own functionality is by creating a new file in the custom_code/ directory of the project's root folder.

File Naming Convention

The Sidekick's menu system will automatically detect any file in the custom_code/ directory that follows this naming convention:

custom_code_YourAppName.py

The YourAppName part of the filename will be used as the display name for your app in the "Code Loader" menu.

For example, a file named custom_code_MyFirstApp.py will appear in the menu as MyFirstApp.

Custom Code Tutorial Series

We have created a series of tutorials to guide you through the process of writing your own custom code for the Sidekick. We recommend starting with the first lesson and working your way through the series.

Click here to start the Custom Code Series!

The run(env) Function

Your custom app file must contain a function called run(env).

This function is called by the menu system when the user selects your app. It is passed a single argument, env, which is a Python dictionary containing references to the initialized hardware objects.

Available Hardware in env

  • oled: The OLED display object. You can use this to draw text, shapes, and images.
  • ok_button: The OK button object (a machine.Pin instance).
  • menu_button: The Menu button object (a machine.Pin instance).
  • upside_down: A boolean that tells you if the device is in upside-down mode.

Running Your Code

  1. Upload Your Code: After creating your file, you'll need to upload it to the Sidekick. You can do this by running pixi run upload again.
  2. Navigate to the App Launcher: From the main menu, select Code Loader.
  3. Select Your App: Scroll to your app's name (HelloWorld in our example) and press the OK button to launch it.