Adding my own main.py to a Circuitpython build

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Chumpatized
 
Posts: 1
Joined: Wed Jun 29, 2022 11:51 am

Adding my own main.py to a Circuitpython build

Post by Chumpatized »

I am trying to add my main.py script to my Circuitpython build (Pico) so that I can just flash the .uf2 file without having to copy the code and libraries over each time.

I have successfully managed to compile Circuitpython following this guide (https://learn.adafruit.com/building-circuitpython) on WSL and also have my working main.py. I have tried searching for answers but no luck (although I have found how to add modules https://learn.adafruit.com/building-cir ... en-modules).

How do I go about baking my main.py (or boot.py) in to the Circuitpython build I create?

Thanks for any help you can give.

User avatar
eherrada
 
Posts: 161
Joined: Thu Jan 04, 2018 4:59 pm

Re: Adding my own main.py to a Circuitpython build

Post by eherrada »

Hey! So this is doable but unfortunately the RP2040 does not support it (although other boards do). In your case, I would suggest writing a shell script that copies everything over, you could maybe make a directory that has all the contents you want in CIRCUITPY and then just copy the entire thing over all at once.

However, you can do this on other boards. I'll add the instructions in case someone comes across this with the same question:
* Manually set up the board with the circuitpython verison you want, all the code put in, and all the libraries
* put your board into the bootloader mode, it'll show up as [BOARD]BOOT (FEATHERBOOT, MAGTAGBOOT, etc.)
* Copy current.uf2 off the board and save it on your computer
* Plug the next board in and put it in bootloader mode
* Put current.uf2 on that board, and it'll copy the whole filesystem over

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: Adding my own main.py to a Circuitpython build

Post by neradoc »

Making a custom Circuitpython build with its own main.py file is possible, this is where the default files are created:
https://github.com/adafruit/circuitpyth ... .c#L73-L85
You could also add your own frozen module, and then call it from the default code.py so that it remains small, while the full python code you want to add is baked-in and remains normal python code (rather than write it as strings in the C code).

But if you just want to make a UF2 file that you can deploy to identical boards, you can use picotool, though you will have to compile it.
The board must be in bootloader mode.

Code: Select all

picotool save --all my_full_board.uf2
More info: https://github.com/raspberrypi/picotool#save

Note that CURRENT.UF2 does not actually contain the CIRCUITPY drive:

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”