There's quite the difference between how we program an Arduino board with the Arduino IDE, using the Arduino programming language (based on C++), and how we program it using MicroPython. When uploading what we call a sketch to a board, we first compile the sketch we write, then upload it to the board, replacing the old sketch with a new.
To use MicroPython, we first need to install it on the board. Then, we can load a
script.py
, like the following blink example:
1import time
2from machine import Pin
3
4led = Pin(6, Pin.OUT)
5
6whileTrue:
7 led.on()
8 time.sleep_ms(250)
9 led.off()
10 time.sleep_ms(250)
As MicroPython is already running on the board, we don't need to compile and upload the code, we only need to provide the instructions (which is done via serial communication).
When installing MicroPython on a board, it can only run MicroPython scripts, until we "uninstall" it. To put the board back in "normal mode" we need to reset the bootloader, which is a unique process for each board. These instructions are available in the
compatible boards
section in this article. Basically, you have to put the board in bootloader mode and upload any .ino sketch.
Arduino Lab for MicroPython
Arduino Lab for MicroPython Editor
The
Arduino Lab for MicroPython
is a lightweight editor designed for simple interaction between your computer and board. With it, you can select your port, load scripts, and use the REPL shell and more.
OpenMV
is a platform that supports programming Arduino boards using a fork of MicroPython. Through the OpenMV editor, we can install this fork, and upload scripts directly to the board. There's also a number of examples available directly in the editor.
OpenMV is a great platform for computer vision and machine learning projects.
The OpenMV editor.
OpenMV Examples
Further down this article, you can find a lot of useful code examples that will help you to get started.
To reset the bootloader, you will need to short to connect a jumper wire between the REC and GND pin, and press the reset button. More detailed instructions are available in the
Nano RP2040 Connect technical reference
.
GIGA R1
The Portenta H7
If you need help getting started with MicroPython on the
Portenta H7
board, you can check out the tutorial below:
As MicroPython is an implementation of the Python® language, you can also run a lot of Python® scripts directly on the board. For example, running this Python® script on your computer also works when running it on your board.
1value1 =2
2value2 =5
3
4print(value1 + value2)
This means it's time to learn the
Python®
language, which there is a lot of resources for. We recommend taking a look at the following resources to better understand the Python® language:
Note that many examples in the MicroPython Docs will not work directly with Arduino boards, but will provide an understanding of how Python® can run on your board.
API
Below you will find some useful examples that can be used by any Arduino board. For more specific features, such as on-board sensors, connectivity and communication, please refer to the individual guides: