odroid_go:micropython:01_micropython_setup_loboris

Getting started with MicroPython

Follow this guide to code with MicroPython.

To work with MicroPython, of course, it is needed to install Python and Espressif's esptool.py package on your host PC.

esptool.py is an Espressif's open source utility to communicate with the ROM bootloader in Espressif ESP8266 and ESP32 chips.
By using this tool, you can push any binary into any address of the chip.

Please refer to this official Github webpage to get further information: https://github.com/espressif/esptool/.

For work with it properly, you need to proceed with Ubuntu bash.

Click Start with mouse right button and open Windows PowerShell (Admin).
Enter the following command and reboot.

host
PS C:\WINDOWS\system32> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux


Open Microsoft Store and search Ubuntu 18.04, install it then execute.

It installs Ubuntu subsystem on your Windows system automatically.

Then proceed with the guide for Linux using Ubuntu bash (Installing Python packages and more).

Open a terminal window and enter the following commands.

host
joshua@joshua-desktop:~$ sudo apt update
joshua@joshua-desktop:~$ sudo apt install python python3 python-pip python3-pip
joshua@joshua-desktop:~$ sudo -H pip install esptool

Download a latest CrashOverride's Loboris MicroPython fork firmware names MicroPython.fw. CrashOverride has packed up Loboris' fork to write MicroPython easily using ODROID-GO launcher.
Make sure your ODROID-GO has launcher 181001 or above. If you don't, please install the latest launcher links here.

Insert your SD card to the computer and copy MicroPython.fw to its /odroid/firmware directory. If it doesn't exist, please download skeleton files for SD card and make it in ready.
After that eject from the computer and insert it to your ODROID-GO.

Turn on your ODROID-GO with keeping pressing button B then you're going to enter the launcher.
Select MicroPython.fw using Dpad and Press A - start to install.

After flashing a MicroPython firmware, now you can enter its Python REPL environment.
REPL is an abbreviation for Read Eval Print Loop. This means it evaluates and results instantly when you enter a command, like a shell program such as Bash, Zsh, …

rshell(Remote Shell for MicroPython) is a utility to interact with a MicroPython board over a serial connection.
This provides some additional features to communicate conveniently.
Github: https://github.com/dhylands/rshell

Alternatively, there's another tool ampy(Adafuit MicroPython Tool) to interact with a MicroPython board.
It kinda looks like a standard but it provides only core features. So we recommend to use rshell instead.
Github: https://github.com/adafruit/ampy

We'll guide you to install rshell in this step.

First, install rshell via pip.

host
joshua@joshua-desktop:~$ sudo -H pip3 install rshell

Connect ODROID-GO to your PC with a micro USB cable.
Assume that ODROID-GO is shown as /dev/ttyUSB0. In Windows, it may be shown as something like COM3.

Open with rshell for ODROID-GO.
Then the shell switches its looks that is different from before.

host
joshua@joshua-desktop:~$ rshell --buffer-size 32 -a -p /dev/ttyUSB0
Connecting to /dev/ttyUSB0 ...
Welcome to rshell. Use Control-D to exit.
/home/joshua/Development/odroid-go-micropython> 

Enter repl command to use Python REPL.

host
/home/joshua/Development/odroid-go-micropython> repl
Entering REPL. Use Control-X to exit.
repl_serial_to_stdout dev = <rshell.main.DeviceSerial object at 0x7f417a6c2f60>
>
MicroPython ESP32_LoBo_v3.2.20 - 2018-06-28 on ESP32&psRAM board with ESP32
Type "help()" for more information.
>>> 
>>> 

You can exit pressing Ctrl+X from REPL, Ctrl+D from rshell.

You can do Python coding on REPL prompt.

Let's define 2 variables and add them.

host
>>> a = 10
>>> b = 20
>>> print(a + b)
30

MicroPython provides help() function to show a basic instruction shows how to code with MicroPython board using REPL prompt.
Enter help() to see that.

host
>>> help()
Welcome to LoBo MicroPython for the ESP32
 
For online documentation please visit the Wiki pages:
https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki
 
Based on official MicroPython, this port brings many new features:
 
 - support for two cores and 4MB SPIRAM (psRAM)
 - improved 'network' module
 - greatly improved thread support
 - support for 3 different internal file systems on top of ESP32 VFS
 - ESP32 native support for SD Card
 - built-in FTP & Telnet servers
 - support for OTA updates
 - many new and improved hardware access modules implemented in C
 and many more...
 
Control commands:
  CTRL-A        -- on a blank line, enter raw REPL mode
  CTRL-B        -- on a blank line, enter normal REPL mode
  CTRL-C        -- interrupt a running program
  CTRL-D        -- on a blank line, do a soft reset of the board
  CTRL-E        -- on a blank line, enter paste mode
 
For further help on a specific object, type help(obj)
For a list of available modules, type help('modules')

We've made a module for ODROID-GO, and it would help you to do code with ODROID-GO.
Such as showing a message at the LCD, notifying a button event, playing a tone sound from its speaker.

Clone this repository to any directory.

host
joshua@joshua-desktop:~$ sudo apt install git
joshua@joshua-desktop:~$ git clone https://github.com/hardkernel/ODROID-GO-MicroPython -b loboris

And to test, create a python script names boot.py in the same directory where downloaded MicroPython module locates.
The script file named as boot.py will run at the first time when a MicroPython board booted.

It imports odroid_go.py module and defines a function shows “Hello, ODROID-GO!” on the screen.

from odroid_go import GO
 
print("\033[1;32mGO: ODROID-GO module loaded\033[1;m")
print("\033[1;32mGO: Enter \"hello()\" to see a message on the screen.\033[1;m")
 
 
def hello():
    GO.lcd.clear()
    GO.lcd.font(GO.lcd.FONT_DejaVu24, color=GO.lcd.GREEN)
    GO.lcd.text(GO.lcd.CENTER, GO.lcd.CENTER, "Hello, ODROID-GO!")

Open rshell again and transfer all of the files using rsync.
In rshell, the file system on the MicroPython board is mounted as /flash directory.

host
joshua@joshua-desktop:~$ rshell --buffer-size 32 -a -p /dev/ttyUSB0
Connecting to /dev/ttyUSB0 ...
Welcome to rshell. Use Control-D to exit.
/home/joshua/Development/odroid-go-micropython>

In the rshell, move to working directory using cd command.

Sync your working directory including ODROID-GO module with /flash directory.

host
/home/joshua/Development/odroid-go-micropython> rsync -m . /flash
Adding /flash/odroid_go
Adding /flash/odroid_go/utils
Adding /flash/odroid_go/utils/lcd
Adding /flash/odroid_go/utils/lcd/__init__.py
Adding /flash/odroid_go/utils/lcd/lcd.py
Adding /flash/odroid_go/utils/speaker
Adding /flash/odroid_go/utils/speaker/speaker.py
Adding /flash/odroid_go/utils/speaker/__init__.py
Adding /flash/odroid_go/utils/battery
Adding /flash/odroid_go/utils/battery/__init__.py
Adding /flash/odroid_go/utils/battery/battery.py
Adding /flash/odroid_go/utils/go_consts.py
Adding /flash/odroid_go/utils/button
Adding /flash/odroid_go/utils/button/button.py
Adding /flash/odroid_go/utils/button/__init__.py
Adding /flash/odroid_go/utils/__init__.py
Adding /flash/odroid_go/__init__.py
Adding /flash/odroid_go/odroid_go.py
Adding /flash/odroid_go/examples
Adding /flash/odroid_go/examples/README.md
Adding /flash/odroid_go/examples/led
Adding /flash/odroid_go/examples/led/led.py
Adding /flash/odroid_go/examples/speaker
Adding /flash/odroid_go/examples/speaker/speaker.py
Adding /flash/odroid_go/examples/battery
Adding /flash/odroid_go/examples/battery/battery.py
Adding /flash/odroid_go/examples/led_pwm
Adding /flash/odroid_go/examples/led_pwm/led_pwm.py
Adding /flash/odroid_go/examples/button
Adding /flash/odroid_go/examples/button/button.py
Adding /flash/odroid_go/examples/hello_world
Adding /flash/odroid_go/examples/hello_world/hello_world.py
Adding /flash/README.md
/home/joshua/Development/odroid-go-micropython/boot.py is newer than /flash/boot.py - copying

Enter to REPL prompt.

host
/home/joshua/Development/odroid-go-micropython> repl
Entering REPL. Use Control-X to exit.
repl_serial_to_stdout dev = <rshell.main.DeviceSerial object at 0x7f417a6c2f60>
>
MicroPython ESP32_LoBo_v3.2.20 - 2018-06-28 on ESP32&psRAM board with ESP32
Type "help()" for more information.
>>> 
>>> 

Restart the board. boot.py will be read when it starts.
And call hello() function.

host
>>> hello()

Now you can see the message on the screen.

Now you're ready to write your source code.
To learn how to write source code, please refer to this guide: Hello World.

  • odroid_go/micropython/01_micropython_setup_loboris.txt
  • Last modified: 2019/06/03 14:50
  • by joshua