Skip to content

Instantly share code, notes, and snippets.

@russhughes
Created April 15, 2021 16:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save russhughes/13005ba77898d97a03b211c6c4f5b0c3 to your computer and use it in GitHub Desktop.
Save russhughes/13005ba77898d97a03b211c6c4f5b0c3 to your computer and use it in GitHub Desktop.
Customize MicroPython VFAT Image

Software Installation

Deploying MicroPython

The TurtlePlotBot software was developed and tested using MicroPython version 1.12. The micropython directory contains two firmware .bin files that contain MicroPython as well as the TurtlePlotBot modules and other required modules. The turtleplotbot-4m.bin file is for devices with 4MB of flash and the turtleplotbot-8m.bin is for devices with 8MB of flash.

Two compressed VFAT drive images that are preloaded with Hershey .fnt files and other TurtlePlotBot programs are also included in the micropython directory. The vfat-4m.zip file is for use with 4MB flash devices and the vfat-8m.zip file is for use with 8MB flash devices. You must unzip each file before flashing it.

See the Getting started with MicroPython on the ESP32 chapter of the MicroPython Documentation for detailed information on obtaining and installing the esptool program used tpo flash your device.

Erase the Esp32 Flash

The first time you install MicroPython on a device you need to erase the flash.

$ esptool.py --port /dev/ttyUSB0 erase_flash

Example output from the esptool.py erase_flash command:

esptool.py v2.8
>>> Serial port /dev/ttyUSB0
Connecting........___
Detecting chip type... ESP32
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 26MHz
MAC: 24:6f:28:xx:yy:zz
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 18.4s
Hard resetting via RTS pin...

Flash MicroPython on 4MB devices

If you have a ESP32 device with a 4MB flash chip use this command to flash your device. This will flash your device with MicroPython 1.11 and several required libraries.

esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000  turtleplotbot-4m.bin

Flash MicroPython on 8MB devices

If you have a ESP32 device with a 8MB flash chip use this command to flash your device. This will flash your device with MicroPython 1.11 and several required libraries.

esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 turtleplotbot-8m.bin

Flash a VFAT image on a 4MB device

If you have a ESP32 device with a 4MB flash chip use this command to flash your device. This will flash a preloaded vfat virtual drive image to your your device.

esptool.py write_flash 0x200000 micropython/vfat-4m.img

Flash a VFAT image on a 8MB device

If you have a ESP32 device with a 8MB flash chip use this command to flash your device. This will flash a preloaded vfat virtual drive image to your your device.

esptool.py write_flash 0x200000 micropython/vfat-8m.img

Congratulations

Your TurtlePlotBot is now programed and ready run. Press the RST button and the "DrawBot Menu" should appear.

See the menu module documentation for more information on the DrawBot Menu and how to use it.

See the turtleplot module reference documentation for more information on the Turtle Graphics python methods available.

See the Example Programs page for some example programs.

The tftui page has information and example programs on using the LCD screen.

Customizing the VFAT image

The VFAT images can be customize by loop mounting them on a linux system. Here are the commands I used to create the images on a Centos 7.7 system. A newly flashed device must boot once to create the drive image before it can be read off the device.

# Backup the existing 2MB image from a 4MB device
$ esptool.py read_flash 0x200000 0x200000 vfat.img

# OR Backup the existing 6MB image from a 8MB device
$ esptool.py read_flash 0x200000 0x600000 vfat.img

# OR use one of the provided images
# Loop Mount the image

$ sudo losetup /dev/loop0 vfat.img
$ sudo mkdir /mnt/img
$ sudo mount /dev/loop0 /mnt/img

# Add files to the image

$ sudo mkdir /mnt/img/fonts
$ sudo cp fonts/*.fnt /mnt/img/fonts
$ sudo mkdir /mnt/img/programs
$ sudo cp programs/*.py /mnt/img/programs/
$ sudo mv /mnt/img/programs/boot.py /mnt/img/
$ sudo mv /mnt/img/programs/main.py /mnt/img/

# Unmount the image

$ sudo umount /mnt/img
$ sudo losetup -D

Flash the VFAT image

$ esptool.py write_flash 0x200000 vfat.img

MicroPython program to show free drive space

import uos
fs_stat = uos.statvfs('/')
fs_size = fs_stat[0] * fs_stat[2]
fs_free = fs_stat[0] * fs_stat[3]
print("File System Size {:,} - Free Space {:,}".format(fs_size, fs_free))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment