Skip to content

Commit ed6c4e0

Browse files
committed
Document ESP32 support.
1 parent 6d022c9 commit ed6c4e0

File tree

3 files changed

+96
-25
lines changed

3 files changed

+96
-25
lines changed

README.md

Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
# A touch GUI for the official MicroPython display
22

3-
v0.21 29th Oct 2020 Add `Scale` and `Pad` widgets.
3+
v0.21 29th Oct 2020 Add `Scale` and `Pad` widgets.
44
V0.20 21st Oct 2020 Refactor as a Python package. The refactor is a breaking
55
change: applications must adapt `import` statements. There is now no need to
66
cross compile on a Pyboard 1.1. Unused widgets no longer consume RAM. The
7-
structure also facilitates adding new widgets.
8-
9-
Supports Jim Mussared's fast text rendering.
10-
7+
structure also facilitates adding new widgets. Supports Jim Mussared's fast
8+
text rendering.
119
V0.12 21st Sep 2020 Updated for (and requires) uasyncio V3.
1210

13-
Provides a simple touch driven event based GUI interface for the Pyboard when
14-
used with the official LCD160CR colour display. It is based on the official
15-
driver and uses `uasyncio` for scheduling. The V1.1 display enables a Pyboard D
16-
to be plugged in. The GUI has been tested in this configuration.
11+
Provides a simple touch driven event based GUI interface for the the official
12+
LCD160CR colour display. It is based on the official driver and uses `uasyncio`
13+
for scheduling. It has been tested on:
14+
* Pyboard 1.0 and 1.1
15+
* Pyboard D
16+
* ESP32
17+
It should be easy to port to platforms having both I2C and SPI interfaces,
18+
given sufficient RAM. The V1.1 display enables a Pyboard D to be plugged in to
19+
the rear. The GUI has been tested in this configuration.
1720

1821
It is targeted at hardware control and display applications. GUI objects are
1922
drawn using graphics primitives rather than by rendering bitmap images. This
@@ -68,7 +71,6 @@ The Plot module: Cartesian and polar graphs.
6871
1.1 [Pre installation](./README.md#11-pre-installation)
6972
1.2 [Library Documentation](./README.md#12-library-documentation)
7073
1.3 [Installation](./README.md#13-installation)
71-
     1.3.1 [ESP32](./README.md#131-esp32)
7274
1.4 [Dependencies and Python files](./README.md#14-dependencies-and-python-files)
7375
1.5 [A performance boost](./README.md#15-a-performance-boost)
7476
2. [Concepts](./README.md#2-concepts)
@@ -109,6 +111,7 @@ The Plot module: Cartesian and polar graphs.
109111
8.2 [Internal fonts: Class IFont](./README.md#82-internal-fonts-class-ifont)
110112
9. [Issues](./README.md#9-issues) A problem encountered with old LCD160CR firmware
111113
10. [Application design note](./README.md#10-application-design-note) Touch application design
114+
11. [ESP32](./README.md#11-esp32) Use with non-Pyboard targets
112115

113116
# 1. Pre requisites
114117

@@ -154,15 +157,8 @@ directory containing `gui` with:
154157
> rsync gui /sd/gui
155158
```
156159

157-
### 1.3.1 ESP32
158-
159-
The library can be installed on ESP32. The file `lcd_local_esp.py` should be
160-
copied to `/pyboard/lcd_local.py` after making any edits to support your
161-
physical connection and maximum font size.
162-
163-
[Fast mode](./README.md#15-a-performance-boost) will fail because the example
164-
is compiled for STM architecture. Options are to recompile for `xtensawin` or
165-
to disable fast mode by deleting `gui/framebuf_utils/framebuf_utils.mpy`.
160+
For use with non-Pyboard targets, including ESP32, see
161+
[ESP32](./README.md#11-esp32).
166162

167163
## 1.4 Dependencies and Python files
168164

@@ -1214,3 +1210,73 @@ to run the callback on press or use a control such as a listbox.
12141210

12151211
The general point, where screens change, is to consider how continuing touch
12161212
will affect the new screen.
1213+
1214+
# 11. ESP32
1215+
1216+
The official display may be connected to non-Pyboard targets via I2C and SPI
1217+
interfaces. Both interfaces are required. The display has an AP2210 LDO voltage
1218+
regulator so it may be powered from 5V or 3.3V. Connections may be made via
1219+
the downward facing pins or the black connector at the end of the PCB. In my
1220+
testing the SPI connections on that connector did not work, however the power
1221+
and I2C connections were OK.
1222+
1223+
The downward facing pins are as follows. The table is arranged such that the
1224+
black connector is at the top. The view is looking at the display surface.
1225+
1226+
Pin names are those on a mating Pyboard 1.x. Only signals with an entry in the
1227+
`Link` column require connection to the target.
1228+
1229+
| Pin | Signal | Link | Signal | Link | Pin |
1230+
|:---:|:-------:|:----:|:------:|:----:|:---:|
1231+
| Y1 | UART Rx | | Vin | 5V | Vin |
1232+
| Y2 | UART Tx | | NC | | 3V3 |
1233+
| Y3 | LCD CS1 | | Gnd | Gnd | Gnd |
1234+
| Y4 | LCD RST | PWR | Rst | | Rst |
1235+
| Y5 | SS\ | | LCD BL | | Y12 |
1236+
| Y6 | SCK | SPI | T-IRQ | | Y11 |
1237+
| Y7 | MISO | | SDA | I2C | Y10 |
1238+
| Y8 | MOSI | SPI | SCL | I2C | Y9 |
1239+
1240+
The `PWR` signal enables power to the display and should be assigned to an
1241+
arbitrary I/O pin. The display board has no I2C pullups. If the target does not
1242+
have them, pullups to 3.3V on `SDA` and `SCL` are essential. Values are not
1243+
critical - 1.5KΩ to 4.7KΩ are typical.
1244+
1245+
This code from `lcd_local_esp.py` works on the reference board:
1246+
```python
1247+
from gui.core import lcd160cr
1248+
from gui.core.lcd160_gui import Screen, LCD160CR_G
1249+
1250+
from machine import Pin, I2C, SPI
1251+
1252+
def setup():
1253+
pwr = Pin(25, Pin.OUT)
1254+
# Hardware SPI on native pins for performance
1255+
spi = SPI(1, 10_000_000, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
1256+
i2c = I2C(1, scl=Pin(32), sda=Pin(33), freq=1_000_000)
1257+
lcd = LCD160CR_G(pwr=pwr, spi=spi, i2c=i2c) # Set connection
1258+
lcd.set_orient(lcd160cr.LANDSCAPE) # and orientation
1259+
Screen.setup(lcd)
1260+
```
1261+
I experienced problems specifying different pins for I2C. The
1262+
[manual](http://docs.micropython.org/en/latest/esp32/quickref.html#hardware-i2c-bus)
1263+
indicates that pins 18 and 19 can be used, but I experienced timeout errors
1264+
with these pins.
1265+
1266+
To install the library on ESP32 the file `lcd_local_esp.py` should be copied to
1267+
`/pyboard/lcd_local.py` after making any edits to support your physical
1268+
connection and maximum font size.
1269+
1270+
The supplied [framebuf_utils.mpy](./README.md#15-a-performance-boost) will
1271+
produce a harmless warning message because the supplied example is compiled for
1272+
STM architecture. To enable fast text rendering it is necessary to recompile
1273+
for `xtensawin`.
1274+
1275+
### Debug notes
1276+
1277+
If changing the pins or migrating to a different target the following errors
1278+
can occur.
1279+
* ENOENT or timeout exception: I2C problem. Check pullups.
1280+
* Blank display: check the pwr pin.
1281+
* The GUI works but lacks text on buttons. Meters and sliders show
1282+
corruption: this is an SPI problem.

gui/core/lcd160_gui.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55

66
import framebuf
77
from uctypes import bytearray_at, addressof
8+
fast_mode = False
89
try:
910
from gui.framebuf_utils.framebuf_utils import render
1011
fast_mode = True
1112
print('Using fast mode')
13+
except ValueError:
14+
print('Ignoring framebuf_utils.mpy: compiled for incorrect architecture.')
1215
except ImportError:
13-
fast_mode = False
16+
pass
17+
1418
import uasyncio as asyncio
1519
import gc
1620
from gui.core.lcd160cr import LCD160CR

lcd_local_esp.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# Released under the MIT License (MIT). See LICENSE.
55
# Copyright (c) 2018-2020 Peter Hinch
66

7-
8-
# Copy to lcd_local.py on the target
9-
107
# This file is intended for definition of the local hardware.
118

9+
# Copy to lcd_local.py on the target.
10+
# This file has been tested on the ESP32 reference board.
11+
1212
# Arguments for LCD160CR_G are as per official LCD160CR driver with the
1313
# addition of a 'bufsize' kwarg. If provided it should be equal to
1414
# height * max_width * 2 for the largest font in use.
@@ -21,8 +21,9 @@
2121

2222
def setup():
2323
pwr = Pin(25, Pin.OUT)
24-
spi = SPI(2, baudrate=8000000, sck=Pin(18), mosi=Pin(23))
25-
i2c = i2c = I2C(-1, scl=Pin(32), sda=Pin(33))
24+
# Hardware SPI on native pins for performance
25+
spi = SPI(1, 10_000_000, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
26+
i2c = I2C(1, scl=Pin(32), sda=Pin(33), freq=1_000_000)
2627
lcd = LCD160CR_G(pwr=pwr, spi=spi, i2c=i2c) # Set connection
2728
lcd.set_orient(lcd160cr.LANDSCAPE) # and orientation
2829
Screen.setup(lcd)

0 commit comments

Comments
 (0)