MicroPython on the GIGA R1

Get started with MicroPython on the GIGA R1.

Please note: MicroPython documentation for all boards has moved to MicroPython Docs Page. Please refer to that page for the most up to date documentation.

MicroPython is an implementation of Python in a micro format. It can be installed on the GIGA R1, where instead of compiling and uploading sketches, the board has a built-in interpreter that converts Python code to machine code in runtime.

This makes it possible to load various scripts instantly on the board, without the need of compiling the code, which is a great advantage of MicroPython.

In this article, we will guide you through the installation steps, as well as some cool tips and tricks to get creative with MicroPython on the GIGA R1.

Hardware & Software Needed

To follow along with this guide, you will need an Arduino GIGA R1 WiFi

You will need the following software/tools installed:

*The installation for

dfu-util
varies between operation systems. For installation using brew.sh simply use
brew install dfu-util
.

Installation

Note: a new tool has been added that makes it a lot easier to install MicroPython on your board. Visit the MicroPython installation page for more information.

Following the steps below will install MicroPython on the M7 core.

1. Download the GIGAR1_MP_FW.dfu firmware (latest firmware is always available at the MicroPython with Arduino page).

2. Download the dfu-util tool, or install via Brew (or other package managers). Make sure it is in your PATH.

1$ brew install dfu-util

3. Double tap the reset button on the GIGA R1 board. The green LED should now be pulsing. This means it is in bootloader mode.

4. Open a terminal, and navigate to the directory of your

GIGAR1_MP_FW.dfu
file. Run the following command:

1$ dfu-util -w -a 0 -d 2341:0366 -D GIGAR1_MP_FW.dfu

At the end of the process, you will see the following message on success:

1Done parsing DfuSe file

5. Reset the board by clicking the reset button (just once). You should now be able to view and access some of the GIGA R1 boards onboard storage as a mass storage device in your file manager.

GIGA R1 mass storage.
GIGA R1 mass storage.

Congratulations! You have now installed MicroPython on the GIGA R1 board.

Please note that after this installation is complete, your board will no longer be detected as an Arduino device. In order to go back to using the Arduino programming environment, you need to reset the board. This is simply done by double tapping the reset button.

Programming Your Board

To program your GIGA R1 with MicroPython, you will need an editor with support for MicroPython (such as Arduino Lab for MicroPython or Thonny).

The editors listed above are great for getting things to work quickly. One important aspect is that in the editor, you will need to connect to your board, as this will make it possible to load scripts.

As the MicroPython installation has a built-in interpreter, in the editor, you can just write a script and click on the Run Script button, and if it compiles, it will load almost instantly. You can make sure it works by running something simple, such as:

1print("Hello world!")

If it is printed in the REPL, it means it works, and you're ready to take on bigger challenges!

To find out examples and more fundamental knowledge, please visit the MicroPython with Arduino documentation. Here you will find an introduction to this environment and useful examples to get started.

It is important to note that different Arduino boards have different implementations. This is mainly due to what microcontroller the board is based on. For example, to access digital pin 2, on the GIGA R1, you will need to use

'PA3'
(with the quotation marks). See more in GIGA R1 Pin Map

File System (Mass Storage)

The MicroPython installation exposes the mass storage device on your board, which can be edited directly from your computer. This allows you to install modules, edit the boot & main script as well as adding the possibility of switching between scripts.

Boot & Main Scripts

GIGA R1's boot.py and main.py
GIGA R1's boot.py and main.py

You will notice that in the mass storage device, there's two

.py
files:
boot.py
and
main.py
.

  • boot.py
    - when device loads, this script is executed. Typically you do not edit this script.
  • main.py
    - this script executes right after
    boot.py
    . You can consider this your classic Arduino sketch, that runs as soon your board is powered. If you want a specific program to run on your board, save it to
    main.py
    .

Adding Modules

It is possible to add modules, drivers or scripts directly to your board. It is also as simple as dragging and dropping it into the mass storage, and

import
it in your script.

Execute Scripts

A really cool thing with this implementation is that you can pack the mass storage with many different scripts, and load them when needed.

This can be done using only a simple line of code:

1exec(open("script.py").read())

This allows you to create a number of scripts and store it on the mass storage, and execute them from the board itself (e.g. a button).

Pin Map

In the table below, you will find the matching between the STM32H7 and Arduino. When writing MicroPython code, you need to use the pin designations listen in the STM32H7 column.

STM32H7Arduino
PB7D0
PA9D1
PA3D2
PA2D3
PJ8D4
PA7D5
PD13D6
PB4D7
PB8D8
PB9D9
PK1D10
PJ10D11
PJ11D12
PH6D13
PG14D14
PC7D15
PH13D16
PI9D17
PD5D18
PD6D19
PB11D20
PH4D21
PJ12D22
PG13D23
PG12D24
PJ0D25
PJ14D26
PJ1D27
PJ15D28
PJ2D29
PK3D30
PJ3D31
PK4D32
PJ4D33
PK5D34
PJ5D35
PK6D36
PJ6D37
PJ7D38
PI14D39
PE6D40
PK7D41
PI15D42
PI10D43
PG10D44
PI13D45
PH15D46
PB2D47
PK0D48
PE4D49
PI11D50
PE5D51
PK2D52
PG7D53
PI5D54
PH8D55
PA6D56
PJ9D57
PI7D58
PI6D59
PI4D60
PH14D61
PG11D62
PH11D63
PH10D64
PH9D65
PA1D66
PD4D67
PC6D68
PI0D69
PI1D70
PI2D71
PI3D72
PC1D73
PB12D74
PD3D75
PC4A0
PC5A1
PB0A2
PB1A3
PC3A4
PC2A5
PC0A6
PA0A7
PA4A12
PA5A13

Conclusion

In this article, we have learned how to install MicroPython on the GIGA R1, using the

dfu-util
tool. We have also gone through some useful tips and tricks that can help you develop and run MicroPython code on your board.

For more information, visit the MicroPython with Arduino documentation.

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.