|
| 1 | +# color_setup.py Customise for your hardware config |
| 2 | + |
| 3 | +# Released under the MIT License (MIT). See LICENSE. |
| 4 | +# Copyright (c) 2020 Peter Hinch |
| 5 | + |
| 6 | +# As written, supports: |
| 7 | +# ili9341 240x320 displays on Sunton ESP32-2432S028, also known as CYD |
| 8 | +# See https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display/ for more details |
| 9 | +# Edit the driver import for other displays. |
| 10 | + |
| 11 | +# Demo of initialisation procedure designed to minimise risk of memory fail |
| 12 | +# when instantiating the frame buffer. The aim is to do this as early as |
| 13 | +# possible before importing other modules. |
| 14 | + |
| 15 | +# WIRING |
| 16 | +# ESP SSD |
| 17 | +# 3v3 Vin |
| 18 | +# Gnd Gnd |
| 19 | +# IO02 DC |
| 20 | +# IO15 CS |
| 21 | +# IO15 Rst |
| 22 | +# IO14 CLK Hardware SPI1 |
| 23 | +# IO13 DATA (AKA SI MOSI) |
| 24 | + |
| 25 | +from machine import Pin, PWM, SPI |
| 26 | +import gc |
| 27 | + |
| 28 | +# *** Choose your color display driver here *** |
| 29 | +# ili9341 specific driver |
| 30 | +from drivers.ili93xx.ili9341 import ILI9341 as SSD |
| 31 | + |
| 32 | +PIN_sck = 14 |
| 33 | +PIN_mosi = 13 |
| 34 | +# miso - doesn't need to be explictly set |
| 35 | +PIN_dc = 2 |
| 36 | +PIN_cs = 15 |
| 37 | +PIN_rst = 15 |
| 38 | + |
| 39 | + |
| 40 | +pdc = Pin(PIN_dc, Pin.OUT, value=0) # Arbitrary pins |
| 41 | +pcs = Pin(PIN_cs, Pin.OUT, value=1) |
| 42 | +prst = Pin(PIN_rst, Pin.OUT, value=1) |
| 43 | + |
| 44 | +# Kept as ssd to maintain compatability |
| 45 | +gc.collect() # Precaution before instantiating framebuf |
| 46 | +#spi = SPI(1, 40_000_000, sck=Pin(PIN_sck), mosi=Pin(PIN_mosi)) # default miso. 40Mhz out of spec but seems to work fine |
| 47 | +spi = SPI(1, 10_000_000, sck=Pin(PIN_sck), mosi=Pin(PIN_mosi)) # default miso |
| 48 | + |
| 49 | + |
| 50 | +# NOTE on CYD1 clock is upside down. |
| 51 | +# With power usb bottom right from front, clock is bottom right hand and upside down |
| 52 | +# setting usd to True will correct this |
| 53 | +# For more information see https://github.com/peterhinch/micropython-nano-gui/blob/master/DRIVERS.md#32-drivers-for-ili9341 |
| 54 | +# TODO for CYD2 probably need to pass in height=320, width=240 (i.e. transposed compared with default and CYD1) |
| 55 | +usd = False # Default |
| 56 | +usd = True |
| 57 | + |
| 58 | +ssd = SSD(spi, dc=pdc, cs=pcs, rst=prst, usd=usd) |
| 59 | + |
| 60 | +# on CYD need to turn on backlight to see anything |
| 61 | +backlight_percentage = 50 |
| 62 | +backlight = Pin(21, Pin.OUT) |
| 63 | +backlight_pwm = PWM(backlight) |
| 64 | +#backlight.on() # PWM preferred instead of on/off |
| 65 | +#backlight_pwm.duty(1023) # 100% |
| 66 | +#backlight_pwm.duty(512) # 50% |
| 67 | +# TODO ensure backlight_percentage is 0-100 |
| 68 | +backlight_pwm.duty(int(backlight_percentage * 10.23)) # 1023 / 100 |
0 commit comments