In this tutorial you can see how to create a custom micropython module and install it to your raspberry pi pico (RP2040) using Thonny

Coding the Custom Module

Let’s create a simple module with two functions and name the file as simple.py

def oof1():
	print("oof")

def multiply(a,b):
	return a*b

lets create the main file in which we will call the simple module. Name the file as main.py and place in the same directory as simple.py

import simple

simple.oof1()

mul = simple.multiply(22,24)
print(mul)

Installing the Custom Module

In thonny menu bar go to View -> Files. A side bar will appear in thonny window.

Navigate to your directory in which you have saved the simple.py and main.py files. Right click on the simple.py file and click “Upload to /”

after clicking the “Upload to /” button the module should be uploaded to the Pi Pico and should show the file under the Raspberry Pi Pico sidebar

Now you have successfully installed the custom module to your pi pico.

Testing the Custom Module

We can import the module using the following code.

import simple

and if we call the function from the module we should see the output

If you execute the main.py file you will see the following output

Cool ! now you have successfully installed and tested custom micropython module

If you like our content, please consider buying us a coffee.
Thank you for your support!