diff --git a/gui/demos/aclock.py b/gui/demos/aclock.py index af42159..ed4390f 100644 --- a/gui/demos/aclock.py +++ b/gui/demos/aclock.py @@ -38,7 +38,7 @@ async def aclock(dial, lbldate, lbltim): return 'nd' if n in (3, 23): return 'rd' - return th + return 'th' days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun') months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', diff --git a/hardware_setup.py b/hardware_setup.py index df02c1b..c031844 100644 --- a/hardware_setup.py +++ b/hardware_setup.py @@ -1,54 +1,122 @@ -# ili9341_pico.py Customise for your hardware config +# color_setup.py Customise for your hardware config # Released under the MIT License (MIT). See LICENSE. -# Copyright (c) 2021 Peter Hinch +# Copyright (c) 2021 Peter Hinch, Ihor Nehrutsa -# As written, supports: -# ili9341 240x320 displays on Pi Pico -# Edit the driver import for other displays. +# Supports: +# TTGO T-Display 1.14" 135*240(Pixel) based on ST7789V +# http://www.lilygo.cn/claprod_view.aspx?TypeId=62&Id=1274 +# http://www.lilygo.cn/prod_view.aspx?TypeId=50044&Id=1126 +# https://github.com/Xinyuan-LilyGO/TTGO-T-Display +# https://github.com/Xinyuan-LilyGO/TTGO-T-Display/blob/master/image/pinmap.jpg +# https://github.com/Xinyuan-LilyGO/TTGO-T-Display/blob/master/schematic/ESP32-TFT(6-26).pdf + +# WIRING (TTGO T-Display pin numbers and names). +# Pinout of TFT Driver +# ST7789 ESP32 +# TFT_MISO N/A +TFT_MOSI = 19 # (SDA on schematic pdf) SPI interface output/input pin. +TFT_SCLK = 18 # This pin is used to be serial interface clock. +TFT_CS = 5 # Chip selection pin, low enable, high disable. +TFT_DC = 16 # Display data/command selection pin in 4-line serial interface. +TFT_RST = 23 # This signal will reset the device,Signal is active low. +TFT_BL = 4 # (LEDK on schematic pdf) Display backlight control pin + +ADC_IN = 34 # Measuring battery or USB voltage, see comment below +ADC_EN = 14 # (PWR_EN on schematic pdf) is the ADC detection enable port + +BUTTON1 = 35 # right of the USB connector +BUTTON2 = 0 # left of the USB connector + +# ESP32 pins, free for use in user applications +#I2C_SDA = 21 # hardware ID 0 +#I2C_SCL = 22 + +#UART2TXD = 17 + +#GPIO2 = 2 +#GPIO15 = 15 +#GPIO13 = 13 +#GPIO12 = 12 + +#GPIO37 = 37 +#GPIO38 = 38 +#UART1TXD = 4 +#UART1RXD = 5 +#GPIO18 = 18 +#GPIO19 = 19 +#GPIO17 = 17 + +#DAC1 = 25 +#DAC2 = 26 + +# Input only pins +#GPIO36 = 36 # input only +#GPIO39 = 39 # input only # 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 -# Pico Display -# GPIO Pin -# 3v3 36 Vin -# IO6 9 CLK Hardware SPI0 -# IO7 10 DATA (AKA SI MOSI) -# IO8 11 DC -# IO9 12 Rst -# Gnd 13 Gnd -# IO10 14 CS - -# Pushbuttons are wired between the pin and Gnd -# Pico pin Meaning -# 16 Operate current control -# 17 Decrease value of current control -# 18 Select previous control -# 19 Select next control -# 20 Increase value of current control - -from machine import Pin, SPI, freq +from machine import Pin, SPI, ADC, freq import gc -from drivers.ili93xx.ili9341 import ILI9341 as SSD -freq(250_000_000) # RP2 overclock -# Create and export an SSD instance -pdc = Pin(8, Pin.OUT, value=0) # Arbitrary pins -prst = Pin(9, Pin.OUT, value=1) -pcs = Pin(10, Pin.OUT, value=1) -spi = SPI(0, baudrate=30_000_000) +from drivers.st7789.st7789_4bit import * +SSD = ST7789 + +pdc = Pin(TFT_DC, Pin.OUT, value=0) # Arbitrary pins +pcs = Pin(TFT_CS, Pin.OUT, value=1) +prst = Pin(TFT_RST, Pin.OUT, value=1) +pbl = Pin(TFT_BL, Pin.OUT, value=1) + gc.collect() # Precaution before instantiating framebuf -ssd = SSD(spi, pcs, pdc, prst, usd=True) +# Conservative low baudrate. Can go to 62.5MHz. +spi = SPI(1, 30_000_000, sck=Pin(TFT_SCLK), mosi=Pin(TFT_MOSI)) +freq(160_000_000) + +''' TTGO + v +----------------+ + 40 | | | + ^ | +------+ | pin 36 + | | | | | + | | | | | +240 | | | | | + | | | | | + | | | | | + v | +------+ | + 40 | | | Reset button + ^ +----------------+ + >----<------>----< + 52 135 xx + BUTTON2 BUTTON1 +''' +# Right way up landscape: defined as top left adjacent to pin 36 +ssd = SSD(spi, height=135, width=240, dc=pdc, cs=pcs, rst=prst, disp_mode=LANDSCAPE, display=TDISPLAY) +# Normal portrait display: consistent with TTGO logo at top +# ssd = SSD(spi, height=240, width=135, dc=pdc, cs=pcs, rst=prst, disp_mode=PORTRAIT, display=TDISPLAY) from gui.core.ugui import Display # Create and export a Display instance # Define control buttons -nxt = Pin(19, Pin.IN, Pin.PULL_UP) # Move to next control -sel = Pin(16, Pin.IN, Pin.PULL_UP) # Operate current control -prev = Pin(18, Pin.IN, Pin.PULL_UP) # Move to previous control -increase = Pin(20, Pin.IN, Pin.PULL_UP) # Increase control's value -decrease = Pin(17, Pin.IN, Pin.PULL_UP) # Decrease control's value +nxt = Pin(32, Pin.IN, Pin.PULL_UP) # Move to next control +sel = Pin(36, Pin.IN, Pin.PULL_UP) # Operate current control +prev = Pin(38, Pin.IN, Pin.PULL_UP) # Move to previous control +increase = Pin(37, Pin.IN, Pin.PULL_UP) # Increase control's value +decrease = Pin(39, Pin.IN, Pin.PULL_UP) # Decrease control's value display = Display(ssd, nxt, sel, prev, increase, decrease) + +# optional +# b1 = Pin(BUTTON1, Pin.IN) +# b2 = Pin(BUTTON2, Pin.IN) +# adc_en = Pin(ADC_EN, Pin.OUT, value=1) +# adc_in = ADC(Pin(ADC_IN)) +# adc_en.value(0) +''' +Set ADC_EN to "1" and read voltage in BAT_ADC, +if this voltage more than 4.3 V device have powered from USB. +If less then 4.3 V - device have power from battery. +To save battery you can set ADC_EN to "0" and in this case the USB converter +will be power off and do not use your battery. +When you need to measure battery voltage first set ADC_EN to "1", +measure voltage and then set ADC_EN back to "0" for save battery. +''' diff --git a/setup_examples/st7735r144_pyb.py b/setup_examples/st7735r144_pyb.py index 5e4bd58..5e0a8d7 100644 --- a/setup_examples/st7735r144_pyb.py +++ b/setup_examples/st7735r144_pyb.py @@ -49,9 +49,9 @@ from gui.core.ugui import Display # Define control buttons nxt = Pin(Pin.board.X5, Pin.IN, Pin.PULL_UP) # Move to next control sel = Pin(Pin.board.X1, Pin.IN, Pin.PULL_UP) # Operate current control -prev = Pin(Pin.board.X4, Pin.IN, Pin.PULL_UP) # Move to previous control +prev = Pin(Pin.board.X3, Pin.IN, Pin.PULL_UP) # Move to previous control increase = Pin(Pin.board.X2, Pin.IN, Pin.PULL_UP) # Increase control's value -decrease = Pin(Pin.board.X3, Pin.IN, Pin.PULL_UP) # Decrease control's value +decrease = Pin(Pin.board.X4, Pin.IN, Pin.PULL_UP) # Decrease control's value display = Display(ssd, nxt, sel, prev, increase, decrease) diff --git a/setup_examples/st7789_ttgo.py b/setup_examples/st7789_ttgo.py index aed8024..c031844 100644 --- a/setup_examples/st7789_ttgo.py +++ b/setup_examples/st7789_ttgo.py @@ -98,11 +98,11 @@ ssd = SSD(spi, height=135, width=240, dc=pdc, cs=pcs, rst=prst, disp_mode=LANDSC from gui.core.ugui import Display # Create and export a Display instance # Define control buttons -nxt = Pin(36, Pin.IN, Pin.PULL_UP) # Move to next control -sel = Pin(37, Pin.IN, Pin.PULL_UP) # Operate current control +nxt = Pin(32, Pin.IN, Pin.PULL_UP) # Move to next control +sel = Pin(36, Pin.IN, Pin.PULL_UP) # Operate current control prev = Pin(38, Pin.IN, Pin.PULL_UP) # Move to previous control -increase = Pin(39, Pin.IN, Pin.PULL_UP) # Increase control's value -decrease = Pin(32, Pin.IN, Pin.PULL_UP) # Decrease control's value +increase = Pin(37, Pin.IN, Pin.PULL_UP) # Increase control's value +decrease = Pin(39, Pin.IN, Pin.PULL_UP) # Decrease control's value display = Display(ssd, nxt, sel, prev, increase, decrease) # optional