def __init__(self, spi=None, cs=None, dc=None, ts_cs=None, sd_cs=None): displayio.release_displays() if spi is None: spi = board.SPI() if cs is None: cs = board.D9 if dc is None: dc = board.D10 if ts_cs is None: ts_cs = board.D6 if sd_cs is None: sd_cs = board.D5 ts_cs = digitalio.DigitalInOut(ts_cs) self._display_bus = displayio.FourWire(spi, command=dc, chip_select=cs) self._sdcard = None try: self._sdcard = sdcardio.SDCard(spi, sd_cs) vfs = storage.VfsFat(self._sdcard) storage.mount(vfs, "/sd") except OSError as error: print("No SD card found:", error) try: # the screen might not be ready from cold boot time.sleep(0.8) self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs) except RuntimeError: # wait and try once more time.sleep(1.0) self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs)
def __init__(self, spi=None, cs=None, dc=None, i2c=None): displayio.release_displays() if spi is None: spi = board.SPI() if cs is None: cs = board.D9 if dc is None: dc = board.D10 if i2c is None: i2c = board.I2C() ts_cs = digitalio.DigitalInOut(board.D6) self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs) display_bus = displayio.FourWire(spi, command=dc, chip_select=cs) self.display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240) self.neopixel = neopixel.NeoPixel(board.D11, 1) self.keyboard = BBQ10Keyboard(i2c) sd_cs = board.D5 self._sdcard = None try: self._sdcard = sdcardio.SDCard(spi, sd_cs) vfs = storage.VfsFat(self._sdcard) storage.mount(vfs, "/sd") except OSError as error: print("No SD card found:", error)
def __init__(self, spi, display, touchscreen=None, audio_device=1, debug=False): self._display = display self._audio_device = audio_device self.touchscreen = touchscreen self._debug = debug if spi is not None: # Attempt to Init STMPE610 if self.touchscreen is None: if debug: print("Attempting to initialize STMPE610...") try: chip_select = DigitalInOut(board.CE1) self.touchscreen = Adafruit_STMPE610_SPI(spi, chip_select) except (RuntimeError, AttributeError, NameError): if debug: print("None Found") # Attempt to Init FocalTouch if self.touchscreen is None: if debug: print("Attempting to initialize Focal Touch...") try: i2c = board.I2C() self.touchscreen = adafruit_focaltouch.Adafruit_FocalTouch( i2c) except Exception: # pylint: disable=broad-except if debug: print("None Found") self.set_backlight(1.0) # turn on backlight gc.collect()
pixel[0] = 0xEF0000 # setup the display displayio.release_displays() display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) display = adafruit_ili9341.ILI9341( display_bus, width=_WIDTH, height=_HEIGHT, rotation=_ROTATION, ) # resistive touchscreen touch = Adafruit_STMPE610_SPI( spi, digitalio.DigitalInOut(touch_cs), ) # --- driver interface --- _XRANGE = abs(_LX - _RX) _YRAGNE = abs(_TY - _BY) print((_LX > _RX, _XRANGE), (_TY > _BY, _YRAGNE)) _FLIPX = -1 if _LX > _RX else 1 _FLIPY = -1 if _TY > _BY else 1 _prev_coord: tuple[int, int] | None = None
import busio import board import digitalio from adafruit_stmpe610 import Adafruit_STMPE610_SPI spi = busio.SPI(board.SCK, board.MOSI, board.MISO) cs = digitalio.DigitalInOut(board.D6) st = Adafruit_STMPE610_SPI(spi, cs) print("Go Ahead - Touch the Screen - Make My Day!") while True: if not st.buffer_empty: print(st.read_data())
def __init__( self, *, url=None, headers=None, json_path=None, regexp_path=None, default_bg=0x000000, status_neopixel=None, text_font=None, text_position=None, text_color=0x808080, text_wrap=False, text_maxlen=0, text_transform=None, json_transform=None, image_json_path=None, image_resize=None, image_position=None, image_dim_json_path=None, caption_text=None, caption_font=None, caption_position=None, caption_color=0x808080, image_url_path=None, success_callback=None, external_spi=None, debug=False, display=None, touchscreen=None ): self._debug = debug self._debug_start = time.monotonic() self.display = display spi = None if self.display is None: if external_spi: # If SPI Object Passed spi = external_spi else: # Else: Make ESP32 connection spi = board.SPI() display_bus = displayio.FourWire( spi, command=board.D25, chip_select=board.CE0 ) self.display = adafruit_ili9341.ILI9341( display_bus, width=320, height=240, backlight_pin=board.D18 ) if self.display is None: raise RuntimeError("Display not found or provided") self.set_backlight(1.0) # turn on backlight self._url = url self._headers = headers if json_path: if isinstance(json_path[0], (list, tuple)): self._json_path = json_path else: self._json_path = (json_path,) else: self._json_path = None self._regexp_path = regexp_path self._success_callback = success_callback if status_neopixel: import neopixel # pylint: disable=import-outside-toplevel self.neopix = neopixel.NeoPixel(status_neopixel, 1, brightness=0.2) else: self.neopix = None self.neo_status(0) self.audio_device = 1 try: os.stat(LOCALFILE) self._uselocal = True except OSError: self._uselocal = False self._debug_print("Init display") self.splash = displayio.Group(max_size=15) self._debug_print("Init background") self._bg_group = displayio.Group(max_size=1) self._bg_file = None self._default_bg = default_bg self.splash.append(self._bg_group) # show thank you and bootup file if available for bootscreen in ("thankyou.bmp", "pyportal_startup.bmp"): try: os.stat(bootscreen) self.display.show(self.splash) self.set_backlight(0) self.set_background(bootscreen) self.set_backlight(1) except OSError: pass # they removed it, skip! try: self.play_file("pyportal_startup.wav") except OSError: pass # they deleted the file, no biggie! self._debug_print("My IP address is", self.get_ip_address()) # set the default background self.set_background(self._default_bg) self.display.show(self.splash) self._qr_group = None # Tracks whether we've hidden the background when we showed the QR code. self._qr_only = False self._debug_print("Init caption") self._caption = None if caption_font: self._caption_font = bitmap_font.load_font(caption_font) self.set_caption(caption_text, caption_position, caption_color) if text_font: if isinstance(text_position[0], (list, tuple)): num = len(text_position) if not text_wrap: text_wrap = [0] * num if not text_maxlen: text_maxlen = [0] * num if not text_transform: text_transform = [None] * num else: num = 1 text_position = (text_position,) text_color = (text_color,) text_wrap = (text_wrap,) text_maxlen = (text_maxlen,) text_transform = (text_transform,) self._text = [None] * num self._text_color = [None] * num self._text_position = [None] * num self._text_wrap = [None] * num self._text_maxlen = [None] * num self._text_transform = [None] * num self._text_font = bitmap_font.load_font(text_font) self._debug_print("Loading font glyphs") # self._text_font.load_glyphs(b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' # b'0123456789:/-_,. ') gc.collect() for i in range(num): self._debug_print("Init text area", i) self._text[i] = None self._text_color[i] = text_color[i] self._text_position[i] = text_position[i] self._text_wrap[i] = text_wrap[i] self._text_maxlen[i] = text_maxlen[i] self._text_transform[i] = text_transform[i] else: self._text_font = None self._text = None # Add any JSON translators self._json_transform = [] if json_transform: if callable(json_transform): self._json_transform.append(json_transform) else: self._json_transform.extend(filter(callable, json_transform)) self._image_json_path = image_json_path self._image_url_path = image_url_path self._image_resize = image_resize self._image_position = image_position self._image_dim_json_path = image_dim_json_path if image_json_path or image_url_path: self._debug_print("Init image path") if not self._image_position: self._image_position = (0, 0) # default to top corner if not self._image_resize: self._image_resize = ( self.display.width, self.display.height, ) # default to full screen self._debug_print("Init touchscreen") self.touchscreen = touchscreen if spi is not None: # Attempt to Init STMPE610 if self.touchscreen is None: self._debug_print("Attempting to initialize STMPE610...") try: chip_select = digitalio.DigitalInOut(board.CE1) self.touchscreen = Adafruit_STMPE610_SPI(spi, chip_select) except (RuntimeError, AttributeError): self._debug_print("None Found") # Attempt to Init FocalTouch if self.touchscreen is None: self._debug_print("Attempting to initialize Focal Touch...") try: i2c = board.I2C() self.touchscreen = adafruit_focaltouch.Adafruit_FocalTouch(i2c) except Exception: # pylint: disable=broad-except self._debug_print("None Found") self.set_backlight(1.0) # turn on backlight gc.collect()