From bf898d323ca1cad2147c04b1c46b362d0f851156 Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Wed, 18 Nov 2020 10:41:15 +0000 Subject: [PATCH] Add notes and setup file for ESP8266. --- README.md | 53 ++++++++++++++++++++++++++++++++++++++- drivers/ssd1351/README.md | 2 +- esp8266_setup.py | 34 +++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 esp8266_setup.py diff --git a/README.md b/README.md index 87f99da..7cc8648 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,8 @@ wiring details, pin names and hardware issues. 3.6 [Scale class](./README.md#36-scale-class) Linear display with wide dynamic range. 3.7 [Class Textbox](./README.md#37-class-textbox) Scrolling text display. 4. [Device drivers](./README.md#4-device-drivers) Device driver compatibility - requirements (these are minimal). + requirements (these are minimal). + 5. [ESP8266](./README.md#5-esp8266) This can work. # 1. Introduction @@ -179,6 +180,8 @@ MicroPython target and the electrical connections between display and target. * `esp32_setup.py` As written supports an ESP32 connected to a 128x128 SSD1351 display. After editing to match the display and wiring, it should be copied to the target as `/pyboard/color_setup.py`. + * `esp8266_setup.py` Similar for [ESP8266](./README.md#5-esp8266). Usage is + somewhat experimental. The `gui/core` directory contains the GUI core and its principal dependencies: @@ -797,3 +800,51 @@ Drivers for displays using I2C may need to use depending on the chip requirements. ###### [Contents](./README.md#contents) + +# 5. ESP8266 + +Some personal observations on successful use with an ESP8266. + +I chose an [Adafruit 128x128 OLED display](https://www.adafruit.com/product/1431) +to represent the biggest display I thought the ESP8266 might support. I +reasoned that, if this can be made to work, smaller or monochrome displays +would be no problem. + +The ESP8266 is a minimal platform with typically 36.6KiB of free RAM. The +framebuffer for a 128*128 OLED requires 16KiB of contiguous RAM (the display +hardware uses 16 bit color but my driver uses an 8 bit buffer to conserve RAM). + +A further issue is that, by default, ESP8266 firmware does not support complex +numbers. This rules out the plot module and the `Dial` widget. It is possible +to turn on complex support in the build, but I haven't tried this. + +I set out to run the `scale.py` and `textbox.py` demos as these use `uasyncio` +to create dynamic content, and the widgets themselves are relatively complex. + +I froze a subset of the `drivers` and the `gui` directories. A subset minimises +the size of the firmware build and eliminates modules which won't compile due +to the complex number issue. The directory structure in my frozen modules +directory matched that of the source: the directory had `gui` and `drivers` +subdirectories with their subdirectories intact (where they had necessary +contents). + +In the following description, `__init__.py` was always left in place. +From `drivers` I removed everything except `ssd1351/ssd1351_generic.py`. +From `gui/fonts` I removed fonts except for `arial10`. +From `gui/demos` I removed all but `scale.py` and `tbox.py`. +From `gui/core` I removed all but `colors.py`,`writer.py` and `nanogui.py`. + +I deleted unused directories such as `drivers/sharp` etc. + +I erased flash, built and installed the new firmware. Finally I copied +`esp8266_setup.py` to `/pyboard/color_setup.py`. This could have been frozen +but I wanted to be able to change pins if required. + +Both demos worked perfectly. + +I modified the demos to regularly report free RAM. `scale.py` reported 10480 +bytes, `tbox.py` reported 10512 bytes, sometimes more, as the demo progressed. +In conclusion I think that applications of moderate complexity should be +feasible. + +###### [Contents](./README.md#contents) diff --git a/drivers/ssd1351/README.md b/drivers/ssd1351/README.md index e764022..b7bae96 100644 --- a/drivers/ssd1351/README.md +++ b/drivers/ssd1351/README.md @@ -2,7 +2,7 @@ There are three versions. * `ssd1351.py` This is optimised for STM (e.g. Pyboard) platforms. - * `ssd1351_generic.py` Cross-platform version. + * `ssd1351_generic.py` Cross-platform version. Tested on ESP32 and ESP8266. * `ssd1351_16bit.py` Cross-platform. Uses 16 bit RGB565 color. To conserve RAM the first two use 8 bit (rrrgggbb) color. This works well with diff --git a/esp8266_setup.py b/esp8266_setup.py new file mode 100644 index 0000000..d40960a --- /dev/null +++ b/esp8266_setup.py @@ -0,0 +1,34 @@ +# esp8266_setup.py Copy to target as color_setup.py + +# Released under the MIT License (MIT). See LICENSE. +# Copyright (c) 2020 Peter Hinch + +# As written, supports: +# Adafruit 1.5" 128*128 OLED display: https://www.adafruit.com/product/1431 +# Adafruit 1.27" 128*96 display https://www.adafruit.com/product/1673 +# Edit the driver import for other displays. + +# WIRING (Adafruit pin nos and names). +# Pyb SSD +# 3v3 Vin (10) +# Gnd Gnd (11) +# IO0 DC (3 DC) +# IO16 CS (5 OC OLEDCS) +# IO2 Rst (4 R RESET) +# IO14 CLK (2 CL SCK) Hardware SPI1 +# IO13 DATA (1 SI MOSI) + +from machine import SPI, Pin +import gc +from drivers.ssd1351.ssd1351_generic import SSD1351 as SSD + +height = 128 # Ensure height is correct (96/128) + +pdc = Pin(0, Pin.OUT, value=0) # Arbitrary pins +pcs = Pin(16, Pin.OUT, value=1) +prst = Pin(2, Pin.OUT, value=1) +# Hardware SPI on native pins for performance +spi = SPI(1, baudrate=10_000_000, polarity=0, phase=0) + +gc.collect() +ssd = SSD(spi, pcs, pdc, prst, height=height)