From befcfd08ba3f168771509a40ab1171dbdac05ef4 Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Thu, 6 May 2021 18:06:06 +0100 Subject: [PATCH] Add aclock_large demo --- README.md | 6 ++-- color_setup/ssd1351_esp32.py | 41 +++++++++++++++++++++++++++ gui/demos/aclock.py | 3 +- gui/demos/aclock_large.py | 54 ++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 color_setup/ssd1351_esp32.py create mode 100644 gui/demos/aclock_large.py diff --git a/README.md b/README.md index 280cbfa..10c107d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # MicroPython nano-gui A lightweight and minimal MicroPython GUI library for display drivers based on -the `FrameBuffer` class. Various display technologies are supported, including -small color and monochrome OLED's, color TFT's, ePaper and Sharp units. The GUI -is cross-platform. +the `FrameBuffer` class. It is portable between a range of MicroPython hosts +and display devices. Various display technologies are supported, including +small color and monochrome OLED's, color TFT's, ePaper and Sharp units. These images, most from OLED displays, fail to reproduce the quality of these displays. OLEDs are visually impressive displays with bright colors, wide diff --git a/color_setup/ssd1351_esp32.py b/color_setup/ssd1351_esp32.py new file mode 100644 index 0000000..c2ceae7 --- /dev/null +++ b/color_setup/ssd1351_esp32.py @@ -0,0 +1,41 @@ +# ssd1351_esp32.py Customise for your hardware config + +# 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. + +# Demo of initialisation procedure designed to minimise risk of memory fail +# when instantiating the frame buffer. The aim is to do this as early as +# possible before importing other modules. + +# WIRING (Adafruit pin nos and names). +# ESP SSD +# 3v3 Vin (10) +# Gnd Gnd (11) +# IO27 DC (3 DC) +# IO25 CS (5 OC OLEDCS) +# IO26 Rst (4 R RESET) +# IO14 CLK (2 CL SCK) Hardware SPI1 +# IO13 DATA (1 SI MOSI) + +import machine +import gc + +# *** Choose your color display driver here *** +# Driver supporting non-STM platforms +from drivers.ssd1351.ssd1351_generic import SSD1351 as SSD + +#height = 96 # 1.27 inch 96*128 (rows*cols) display +height = 128 # 1.5 inch 128*128 display + +pdc = Pin(27, Pin.OUT, value=0) # Arbitrary pins +pcs = Pin(25, Pin.OUT, value=1) +prst = Pin(26, Pin.OUT, value=1) +# Datasheet says 20MHz but I couldn't make that work even on a PCB +spi = SPI(1, 10_000_000, sck=Pin(14), mosi=Pin(13), miso=Pin(12)) +gc.collect() # Precaution before instantiating framebuf +ssd = SSD(spi, pcs, pdc, prst, height) # Create a display instance diff --git a/gui/demos/aclock.py b/gui/demos/aclock.py index 517dcd9..ba4f349 100644 --- a/gui/demos/aclock.py +++ b/gui/demos/aclock.py @@ -1,4 +1,5 @@ -# aclock.py Test/demo program for Adafruit ssd1351-based OLED displays +# aclock.py Test/demo program for nanogui +# Orinally for ssd1351-based OLED displays but runs on most displays # 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 diff --git a/gui/demos/aclock_large.py b/gui/demos/aclock_large.py new file mode 100644 index 0000000..27de71a --- /dev/null +++ b/gui/demos/aclock_large.py @@ -0,0 +1,54 @@ +# aclock_large.py Test/demo program for displays of 240x240 pixels or larger + +# Released under the MIT License (MIT). See LICENSE. +# Copyright (c) 2018-2021 Peter Hinch + +# Initialise hardware and framebuf before importing modules. +from color_setup import ssd # Create a display instance +from gui.core.nanogui import refresh +refresh(ssd, True) # Initialise and clear display. + +# Now import other modules +from gui.widgets.label import Label +from gui.widgets.dial import Dial, Pointer +import cmath +import utime +from gui.core.writer import CWriter + +# Font for CWriter +import gui.fonts.freesans20 as font +from gui.core.colors import * + +def aclock(): + uv = lambda phi : cmath.rect(1, phi) # Return a unit vector of phase phi + pi = cmath.pi + days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', + 'Sunday') + months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', + 'Aug', 'Sept', 'Oct', 'Nov', 'Dec') + # Instantiate CWriter + CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it + wri = CWriter(ssd, font, GREEN, BLACK, verbose=False) + wri.set_clip(True, True, False) + + # Instantiate displayable objects + dial = Dial(wri, 2, 2, height = 150, ticks = 12, bdcolor=None, label=240, pip=False) # Border in fg color + lbltim = Label(wri, 200, 2, 35) + hrs = Pointer(dial) + mins = Pointer(dial) + secs = Pointer(dial) + + hstart = 0 + 0.7j # Pointer lengths and position at top + mstart = 0 + 0.92j + sstart = 0 + 0.92j + while True: + t = utime.localtime() + hrs.value(hstart * uv(-t[3]*pi/6 - t[4]*pi/360), YELLOW) + mins.value(mstart * uv(-t[4] * pi/30), YELLOW) + secs.value(sstart * uv(-t[5] * pi/30), RED) + lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5])) + dial.text('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0])) + refresh(ssd) + utime.sleep(1) + +aclock()