Ejemplo n.º 1
0
    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: Optional[SPI] = None,
     cs: Optional[Pin] = None,
     dc: Optional[Pin] = None,
     ts_cs: Optional[Pin] = None,
     sd_cs: Optional[Pin] = None,
 ):
     super().__init__(spi, cs, dc, ts_cs, sd_cs)
     self.display = adafruit_ili9341.ILI9341(self._display_bus,
                                             width=320,
                                             height=240)
    def __init__(
        self,
        spi=None,
        cs=None,
        dc=None,
        i2c=None,
        ts_cs=None,
        sd_cs=None,
        neopixel_pin=None,
    ):
        super().__init__(spi, cs, dc, ts_cs, sd_cs)

        if i2c is None:
            i2c = board.I2C()
        if neopixel_pin is None:
            neopixel_pin = board.D11

        self.display = adafruit_ili9341.ILI9341(self._display_bus,
                                                width=320,
                                                height=240)
        self.neopixel = neopixel.NeoPixel(neopixel_pin, 1)
        self.keyboard = BBQ10Keyboard(i2c)
    def __init__(self,
                 *,
                 default_bg=None,
                 display=None,
                 spi=None,
                 debug=False):
        if display is None:
            if DISPLAY_ARG_REQUIRED:
                raise RuntimeError(
                    "Display must be provided on platforms without board.")
            display_bus = displayio.FourWire(spi,
                                             command=board.D25,
                                             chip_select=board.CE0)
            display = adafruit_ili9341.ILI9341(display_bus,
                                               width=320,
                                               height=240,
                                               backlight_pin=board.D18)

        if display is None:
            raise RuntimeError("Display not found or provided")

        super().__init__(display, default_bg=default_bg, debug=debug)
        # Tracks whether we've hidden the background when we showed the QR code.
        self._qr_only = False
Ejemplo n.º 5
0
import board, digitalio, displayio
import storage, os
import neopixel
import adafruit_sdcard
import adafruit_ili9341
from bbq10keyboard import BBQ10Keyboard

spi = board.SPI()
i2c = board.I2C()

# setup display
displayio.release_displays()
tft_cs = board.D9
tft_dc = board.D10
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)

# setup keyboard
kbd = BBQ10Keyboard(i2c)

# setup microSD
sd_cs = board.D5
sdcard = adafruit_sdcard.SDCard(spi, digitalio.DigitalInOut(sd_cs))
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, '/sd')

# setup NeoPixels
pix0 = neopixel.NeoPixel(board.NEOPIXEL, 1)
pix0[0] = 0x000080

pix1 = neopixel.NeoPixel(board.D11, 1)
Ejemplo n.º 6
0
tft_dc = board.IO3
touch_cs = board.IO38
neo_pin = board.IO7

# --- driver objects ---

# turn the pixel on as a reminder if the trace is not cut
pixel = neopixel.NeoPixel(neo_pin, 1, auto_write=True)
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)
Ejemplo n.º 7
0
# SD card
sd_cs = digitalio.DigitalInOut(board.D5)
sdcard = adafruit_sdcard.SDCard(spi, sd_cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

# Display
# Release any resources currently in use for the displays
displayio.release_displays()

# TFT settings
tft_cs = board.D9
tft_dc = board.D10
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = adafruit_ili9341.ILI9341(display_bus,
                                   width=240,
                                   height=320,
                                   rotation=90)

# Touch
st_cs_pin = digitalio.DigitalInOut(board.D6)
st = adafruit_stmpe610.Adafruit_STMPE610_SPI(spi, st_cs_pin)

# For registering just one touch
touched = 0

# Groups under main display group
tab_number_group = displayio.Group(x=0, y=0)
row1_group = displayio.Group(x=0, y=0)
row2_group = displayio.Group(x=0, y=108)
row3_group = displayio.Group(x=0, y=214)
lines_group = displayio.Group(x=0, y=0)
Ejemplo n.º 8
0
pen_switch = digitalio.DigitalInOut(PEN_SWITCH)
pen_switch.switch_to_input(pull=digitalio.Pull.UP)

# set up display
displayio.release_displays()

spi = board.SPI()
tft_cs = board.D9
tft_dc = board.D10
tft_rst = board.D6
display_bus = displayio.FourWire(spi,
                                 command=tft_dc,
                                 chip_select=tft_cs,
                                 reset=tft_rst)
display = adafruit_ili9341.ILI9341(display_bus,
                                   width=DISPLAY_WIDTH,
                                   height=DISPLAY_HEIGHT)

# add base UI element
splash = displayio.Group(scale=SKETCH_SCALE)
display.show(splash)

# add sketch
sketch_bitmap = displayio.Bitmap(SKETCH_WIDTH, SKETCH_HEIGHT, 2)
sketch_palette = displayio.Palette(2)
sketch_palette[0] = BACKGROUND_COLOR
sketch_palette[1] = DRAW_COLOR
sketch = displayio.TileGrid(sketch_bitmap,
                            pixel_shader=sketch_palette,
                            x=0,
                            y=0)
Ejemplo n.º 9
0
# Tell displayio to clean up after any previous usage
displayio.release_displays()

# Define ILI9341 screen as an SPI-interfaced display
tft_cs = board.GP17
tft_dc = board.GP21
tft_res = board.GP20
spi_mosi = board.GP19
spi_clk = board.GP18
spi_miso = board.GP16

spi = busio.SPI(clock=spi_clk, MOSI=spi_mosi, MISO=spi_miso)

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = adafruit_ili9341.ILI9341(display_bus, width=WIDTH, height=HEIGHT)

# Initially, just show a bright green background to prove the display is working
splash = displayio.Group(max_size=10)
display.show(splash)

color_bitmap = displayio.Bitmap(320, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x00FF00  # Bright Green

bg_sprite = displayio.TileGrid(color_bitmap,
                               pixel_shader=color_palette,
                               x=0,
                               y=0)

splash.append(bg_sprite)
Ejemplo n.º 10
0
    def __init__(self, spi_clock, spi_mosi, spi_miso, i2c_scl, i2c_sda,
                 dsp_command, dsp_chip_select, dsp_reset, i2s_clock, i2s_word,
                 i2s_data, uart_tx, uart_rx):
        # Turn on the Pico's on-board LED
        print("Setting up power blinky")
        self.setupPowerBlinky()
        time.sleep(1)
        print("Done power blinky")

        try:
            # Create your bus objects
            self.spi = busio.SPI(clock=spi_clock, MOSI=spi_mosi, MISO=spi_miso)
            self.display_bus = displayio.FourWire(self.spi,
                                                  command=dsp_command,
                                                  chip_select=dsp_chip_select,
                                                  reset=dsp_reset)
            self.main_screen = adafruit_ili9341.ILI9341(self.display_bus,
                                                        width=self.WIDTH,
                                                        height=self.HEIGHT)

            self.i2c = busio.I2C(scl=i2c_scl, sda=i2c_sda)
            self.uart = busio.UART(tx=uart_tx,
                                   rx=uart_rx,
                                   baudrate=9600,
                                   timeout=10)

            if sounds_enabled:
                self.i2s = audiobusio.I2SOut(bit_clock=i2s_clock,
                                             word_select=i2s_word,
                                             data=i2s_data)

            self.colours = Colours()

            # Create objects for display
            self.setupBlinkies()
            self.setupButtons()

            if touch_screen_enabled:
                try:
                    self.touch_screen = adafruit_stmpe610.Adafruit_STMPE610_I2C(
                        self.i2c, address=0x41)

                except Exception as err:
                    self.led.value = False
                    print("No touch screen could be enabled")

            self.okuda_font = bitmap_font.load_font("fonts/okuda.pcf")
            #self.okuda_font = bitmap_font.load_font("fonts/font5x8.bin")
            #self.okuda_font.load_glyphs(b'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 %.')

            # Define sensor devices
            self.thermal_camera = ThermalCamera(width=self.WIDTH,
                                                height=self.HEIGHT,
                                                i2c=self.i2c,
                                                display_bus=self.display_bus,
                                                display=self.main_screen,
                                                reverse=False,
                                                font=self.okuda_font)
            self.bme680 = adafruit_bme680.Adafruit_BME680_I2C(self.i2c,
                                                              address=0x77)
            self.bme680.seaLevelhPa = self.SEA_LEVEL_NORMAL
            self.veml = adafruit_veml6075.VEML6075(self.i2c,
                                                   integration_time=100)
            self.gps = adafruit_gps.GPS(self.uart, debug=False)
            self.matrix = Matrix(i2c=self.i2c)

            self.loadSounds()
            self.setupGPS()
            self.setupLCARS()

        except Exception as err:
            print("Error in PicoPicorder.init()")
            self.blinkError(err)
            time.sleep(2)
Ejemplo n.º 11
0
 def __init__(self, spi=None, cs=None, dc=None, ts_cs=None, sd_cs=None):
     super().__init__(spi, cs, dc, ts_cs, sd_cs)
     self.display = adafruit_ili9341.ILI9341(self._display_bus,
                                             width=320,
                                             height=240)
    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()