MicroPython for ESP32 Development Workshop
MicroPython for ESP32 Development Workshop
Agus Kurniawan
1st Edition, 2017
Copyright 2017 Agus Kurniawan
Preface
This book was written to help anyone want to get started with MicroPython development for ESP32 boards. It describes the basic elements of MicroPython development.
Agus Kurniawan
Depok, August 2017
1. Preparing Development Environment
1.1 MicroPython Boards for ESP32
MicroPython is a lean and efficient implementation of the Python programming language that includes a small subset of the Python standard library and is optimised to run on microcontrollers and in constrained environments. This book will focus on MicroPython for ESP32 chip.
The following is a sample of ESP32 Module.
We can deploy MicroPython on ESP32 boards. For instance, you can deploy on these boards:
- Espressif ESP32 Development Board, https://www.adafruit.com/product/3269
- SparkFun ESP32 Thing, https://www.sparkfun.com/products/13907
- Watterott ESP-WROOM-32-Breakout, http://www.watterott.com/de/ESP-WROOM32-Breakout
- NodeMCU-32S Lua WiFi IOT Development board, http://www.aliexpress.com
- Adafruit HUZZAH32 ESP32 Feather Board, https://www.adafruit.com/product/3405
You can find other development board based on ESP32.
NodeMCU-32S Lua WiFi IOT Development board:
SparkFun ESP32 Thing.
Watterott ESP-WROOM-32-Breakout.
1.2 Electronics Components
We need electronic components to build our testing, for instance, Resistor, LED, sensor devices and etc. I recommend you can buy electronic component kit. We can use electronics kit from Arduino to be developed on MicroPython board. The following is a list of electronics kit which can be used in our case.
1.2.1 Arduino Starter Kit
Store website: http://arduino.cc/en/Main/ArduinoStarterKit
1.2.2 Fritzing
Store website: http://shop.fritzing.org/ .
You can buy Fritzing Starter Kit with Arduino UNO or Fritzing Starter Kit with Arduino Mega.
1.2.3 Cooking-Hacks: Arduino Starter Kit
Store website: http://www.cooking-hacks.com/index.php/shop/arduino/starter-kits/arduino-starter-kit.html
1.2.4 Arduino Sidekick Basic kit v2
Store website: http://www.seeedstudio.com/depot/Sidekick-Basic-Kit-for-Arduino-V2-p-1858.html
You also can find this kit on this online store.
http://www.exp-tech.de/seeed-studio-sidekick-basic-kit-for-arduino-v2
1.2.5 Grove - Starter Kit for Arduino
Another option, you can buy this kit on Seeedstudio, http://www.seeedstudio.com/depot/Grove-Starter-Kit-for-Arduino-p-1855.html .
1.2.6 DFRobot - Arduino Kit for Beginner v3
DFRobot provides Arduino kit too. You can buy it on the following website.
http://www.dfrobot.com/index.php?route=product/product&path=35_49&product_id=345
1.3 Development Tools
To develop app with MicroPython target, we can use any editor. You can learn how to install it on chapter 2.
1.4 Testing
For testing, I used SparkFun ESP32 Thing boards for MicroPython on Windows, Linux and Mac.
I also used Arduino Sidekick Basic kit for electronic components and some sensor and actuator devices.
2. Setting Up MicroPython
This chapter explains how to work on setting up MicroPython board.
2.1 Getting Started
In this chapter, we learn how to get started with MicroPython board. We try to reflash the latest MicroPython firmware and then test some basic scripts. For testing, I use SparkFun ESP32 Thing as sample for MicroPython board.
2.2 Connecting MicroPython Boards to Computer
Firstly, you connect MicroPython board to PC via USB/microUSB cable. After connected, you may get lighting on blue LED, for instance for, SparkFun ESp32 Thing board.
If you are working on Windows platform, open Device Manager, you should see ESP32 board detected on Ports (COM & LPT). If you don't see your ESP32 board on Windows, you should install a windows driver for your ESP32 board.
For Mac, you can check it on Terminal. Type this command.
ls /dev/tty.usb*
For Linux, you can use ls /dev/tty* .
Then, you see a list of driver.
For sample, you can see my board that is recognized as /dev/tty.usbserial-DN02MX9H .
2.3 Flashing The Latest MicroPython Firmware
In this section, we try to flash the latest MicroPython firmware. You can get the latest MicroPython firmware https://micropython.org/download#esp32. Download *.bin file.
In this scenario, I try to flash MicroPython firmware on Windows, OSX and Linux.
We can use esptool.py tool from https://github.com/espressif/esptool to deploy MicroPython firmware to ESP32 boards. This tool also is recommended for Windows platform. You can install it via pip.
$ pip install esptool
You can download the latest MicroPython for ESP32 on https://micropython.org/download#esp32. It's daily build firmware. Firstly, we clear the existing firmware on ESP32 board. Then, we flash MicroPython.