setup new board, upload py file

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
willie68
Posts: 3
Joined: Thu Jun 16, 2022 9:08 am

setup new board, upload py file

Post by willie68 » Thu Jun 16, 2022 9:26 am

Hi,
i'm just reading several month now and always find good information for my problems.
But now i just browsed thru all the information here, but i didn't find any solution.
First let me describe the background.
I'm working on a good implementation of the TPS (https://www.elektronik-labor.de/Lernpak ... /TPS0.html, sry site only availble in german, an english introduction you can find here: https://www.elektronik-labor.de/Literatur/MyCo.html) on the RPI Pico booard. I already written many other implementations, like the Arduino Uno/Nano, ATTiny, ESP8266, ESP32, Microbit, caliope...
TPS/myco is a simple 4-Bit interpreter, with the possibility of programming them via 2 buttons. The TPS is often used for smaller automation purposes. Especially for beginners and people with little programming knowledge. There is also a small introduction to this on my page: https://wkla.no-ip.biz/ArduinoWiki/doku ... arduinosps
As I said, the users have little to no knowledge of controller programming, and therefore little experience of how to set up the RPI Pico with micropython.
I am now looking for a way to automatethe installtion, e.g. with a small program or script, on the one hand to install the MicroPython image on the RPI Pico, and also the TPS interpreter.
Preferably without further installation of other components. Operating system is 99% Windows.
So the individual operations would be:
- Start board with BOTSEL, script searches for drive
- script copies mycropython image
- restart
- script searches for new COM port
- script copies main.py
- restart
Is there already something ready for this task?

hippy
Posts: 130
Joined: Sat Feb 20, 2021 2:46 pm
Location: UK

Re: setup new board, upload py file

Post by hippy » Thu Jun 16, 2022 11:39 am

willie68 wrote:
Thu Jun 16, 2022 9:26 am
So the individual operations would be:
- Start board with BOTSEL, script searches for drive
- script copies mycropython image
- restart
- script searches for new COM port
- script copies main.py
- restart
Is there already something ready for this task?
You can download the MicroPython source code, place your 'main.py' in the 'modules' directory of the 'rp2' port, rebuild MicroPython and you will end up with a 'firmware.uf2' which can be loaded with your 'main.py' pre-installed. With a little more effort you can make that 'tps.py' and have it auto-run at start-up, create 'pico-tps.uf2' rather than 'formware.uf2'.

That will reduce the issue to how to get the '.uf2' on to the board when it is connected.

willie68
Posts: 3
Joined: Thu Jun 16, 2022 9:08 am

Re: setup new board, upload py file

Post by willie68 » Fri Jun 17, 2022 11:13 am

Hi,
thanks for the hint.
Today i try this approach and had success.
Now i can build my own uf2 firmware file with my embedded py file.

I do this on Windows with a little help from Docker Desktop. Here are my steps for other to reproduce:

First install, if not already done, docker desktop

Than start a ubuntu image with an interactive shell

Code: Select all

docker run -it -v [your mount path on your windows maschine, eg c:\temp\ubuntu]:/var/host ubuntu /bin/bash
In this shell we have to install some packages for the build process

Code: Select all

apt-get install git
apt-get install gcc-arm-none-eabi libstdc++-arm-none-eabi-newlib libnewlib-arm-none-eabi
apt-get install build-essential
apt-get install cmake
apt-get install python3
Now we can clone the micropython repo

Code: Select all

cd /var/host
git clone https://github.com/micropython/micropython.git
git submodule update --init lib/mbedtls
After that we have to build mpy-cross

Code: Select all

cd micropython
make -C mpy-cross
cd ..
Now in windows we can copy from the host maschine our *.py file to

Code: Select all

ports/rp2/modules.
Our last step is to build the firmware

Code: Select all

cd ports/rp2
make submodules
make clean
make
After that you can copy from build-PICO the firmware.uf2 file to the desired firmware file.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: setup new board, upload py file

Post by jimmo » Mon Jun 20, 2022 5:03 am

In general, rather than putting your code in the modules directory, you should define your own board definition. This allows you to write a manifest file which you can use to reference whichever files you want to be included in your firmware.

(It's more initial work, but the idea is that your board definition can be maintained outside of the main repository).

Post Reply