What is Micropython?
Why on Arduino Due?
Arduino Due is the first 32bit microcontroller introduced in 2013. It has powerful SAM3X8E chip which runs at 84 Mhz, 96KB of RAM, 512KB of flash memory and tons of extra I/O peripherals like CAN bus and dedicated DACs. This makes Due perfect for running micropython.
[NOTE: The Micropython port on Arduino Due is still in BETA, so not all peripherals are currently supported. Go to Github repo for the current status of the project]
This is a step by step guide on how to flash & run micropython on Arduino Due.
Step 1: Downloading necessary programs and libraries
- You'll need ARM gcc toolchain to compile source code. Goto this link to download & install toolchain for your windows version.
- You'll also need 'make' utility. You can also install it from MinGW project which is a collection of GNU utils for windows.
Alternatives: I highly recommend using cygwin because it's easy to setup, all your files stays in single folder and you can use this script as CLI package manager.
- You'll also need Arduino IDE installed on you're PC.
- PuTTY is required for serial communication
- A clone of my Git-repo.
Step 2: Installing drivers and setting up tools
- Plug Due's 'Prorgramming port' to the PC.
- Hold Erase button for a second and release.
- Windows should automatically install drivers and recognize device as 'Arduino Programming port'.
- Now we need to setup Bossac tool. You'll need to add the full path in Windows environment variable list. The executable is in micropython/atmel-sam3x/tools folder.
Step 3: Compiling micropython
- Open command prompt/cygwin and cd into your micropython/atmel-sam3x folder.
- Then type : make
It will compile the source code and create a bin file in /build folder.
Step 3: Flashing Micropython on the Arduino Due
- Plug USB to PC and to Arduino Due's 'Programming port'
- Once detected, go to control panel > Hardware and sound > device manager > ports and note the COM port number. In my case it is COM8
- In the same folder (atmel-sam3x) type: make upload port=(your COM Port)
Flashing takes about 20-30 seconds to complete. After successful flashing the board will reboot itself.
Step 4: More driver installation
- Now disconnect the board and plug it again but with 'Native port'.
- Automatic driver installation will eventually fail.
- In the device manager under ports section you'll see:
- Right click on CDC Virtual Com > Update driver software > browse computer > select the micropython/atmel-sam3x/drivers folder. After installation you'll see the following but with different COM port.
Step 5: Profit
- Open PuTTY and click on Serial button and type your COM port enter speed 115200 and hit open.
- You'll see a blank screen, just hit Ctrl + D and Voila!
- type : help() to see what features board currently supports.
Type the following LED blink program in REPL:
>>>from machine import LED, time >>>while True: >>> LED.toggle() >>> time.sleep_ms(500)