Exemplo n.º 1
0
 def __init__(
     self,
     address: int = 0x5E,
     i2c: Optional[I2C] = None,
     spi: Optional[SPI] = None,
     cs: Optional[Pin] = None,
     dc: Optional[Pin] = None,
 ):
     displayio.release_displays()
     if i2c is None:
         i2c = board.I2C()
     if spi is None:
         spi = board.SPI()
     if cs is None:
         cs = board.D5
     if dc is None:
         dc = board.D6
     self._ss = Seesaw(i2c, address)
     self._ss.pin_mode_bulk(self._button_mask, self._ss.INPUT_PULLUP)
     self._ss.pin_mode(8, self._ss.OUTPUT)
     self._ss.digital_write(8, True)  # Reset the Display via Seesaw
     self._backlight = PWMOut(self._ss, 5)
     self._backlight.duty_cycle = 0
     display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
     self.display = ST7735R(display_bus,
                            width=160,
                            height=80,
                            colstart=24,
                            rotation=270,
                            bgr=True)
Exemplo n.º 2
0
def display_text(text, color):
    # Release any resources currently in use for the displays
    displayio.release_displays()

    spi = board.SPI()
    tft_cs = board.D3
    tft_dc = board.D4

    display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D7)

    display = ST7735R(display_bus, width=128, height=128, colstart=2, rowstart=1, rotation=270)

    # Make the display context
    splash = displayio.Group(max_size=10)
    display.show(splash)

    # Choose the color of the screen background
    color_bitmap = displayio.Bitmap(128, 128, 1)
    color_palette = displayio.Palette(1)
    color_palette[0] = color

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

    # Draw label
    text_area = label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=30, y=64)
    splash.append(text_area)
 def __init__(self, address=0x5E, i2c=None, spi=None):
     if i2c is None:
         i2c = board.I2C()
     if spi is None:
         spi = board.SPI()
     self._ss = Seesaw(i2c, address)
     self._backlight = PWMOut(self._ss, 5)
     self._backlight.duty_cycle = 0
     displayio.release_displays()
     while not spi.try_lock():
         pass
     spi.configure(baudrate=24000000)
     spi.unlock()
     self._ss.pin_mode(8, self._ss.OUTPUT)
     self._ss.digital_write(8, True)  # Reset the Display via Seesaw
     display_bus = displayio.FourWire(spi,
                                      command=board.D6,
                                      chip_select=board.D5)
     self.display = ST7735R(display_bus,
                            width=160,
                            height=80,
                            colstart=24,
                            rotation=270,
                            bgr=True)
     self._ss.pin_mode_bulk(self._button_mask, self._ss.INPUT_PULLUP)
Exemplo n.º 4
0
def Screen(tests, num_test_bytes, write_tests_to_nvm, reset):
    try:
        import board, pimoroni_physical_feather_pins, displayio
        from adafruit_st7735r import ST7735R
        #region Screen setup
        """
        This region of code is used to setup the envirowing screen with displayio
        """

        spi = board.SPI()  # define which spi bus the screen is on
        spi.try_lock()  # try to get control of the spi bus
        spi.configure(
            baudrate=100000000)  # tell the spi bus how fast it's going to run
        # baudrate doesn't need to be this high in practice, it's just nice to have a quick screen refresh in this case
        spi.unlock()  # unlocks the spi bus so displayio can control it
        tft_dc = pimoroni_physical_feather_pins.pin19(
        )  # define which pin the command line is on
        tft_cs = pimoroni_physical_feather_pins.pin20(
        )  # define which pin the chip select line is on

        displayio.release_displays(
        )  # release any displays that may exist from previous code run
        display_bus = displayio.FourWire(spi,
                                         command=tft_dc,
                                         chip_select=tft_cs,
                                         reset=pimoroni_physical_feather_pins.
                                         pin21())  # define the display bus

        display = ST7735R(
            display_bus,
            width=160,
            height=80,
            colstart=26,
            rowstart=1,
            rotation=270,
            invert=True
        )  # define the display (these values are specific to the envirowing's screen)

        #endregion Screen setup
        if display:
            tests["Screen"]["Passed"] = True
            print("Passed with", display)
        else:
            tests["Screen"]["Passed"] = False
            print("Failed")
    except Exception as e:
        tests["Screen"]["Passed"] = False
        print("Failed with ", e)
    finally:
        tests["Screen"]["Test Run"] = True
        write_tests_to_nvm(tests, num_test_bytes)
        reset()
Exemplo n.º 5
0
def Screen(backlight_control=True, baudrate=100000000, spi=None):
    """__init__
    :param bool backlight_control: determines whether this class should handle the screen's backlight (default True)
    (this is useful to set to False if you want to control the brightness with pwm in your own code)
    :param int baudrate: sets the baudrate for the spi connection to the display (default 100000000)
    (baudrate doesn't need to be this high for the display to function, it's just nice to have a quick screen refresh by default)
    This class is used to setup the envirowing screen with displayio and return a display object
    """

    import board
    import pimoroni_physical_feather_pins
    import displayio
    from adafruit_st7735r import ST7735R

    # if not supplied an spi object, make our own
    if not spi:
        spi = board.SPI()  # define which spi bus the screen is on

    spi.try_lock()  # try to get control of the spi bus
    spi.configure(
        baudrate=baudrate)  # tell the spi bus how fast it's going to run
    spi.unlock()  # unlocks the spi bus so displayio can control it

    displayio.release_displays(
    )  # release any displays that may exist from previous code run

    if backlight_control:
        display_bus = displayio.FourWire(
            spi,
            command=pimoroni_physical_feather_pins.pin19(),
            chip_select=pimoroni_physical_feather_pins.pin20(),
            reset=pimoroni_physical_feather_pins.pin21(
            ))  # define the display bus
    else:
        display_bus = displayio.FourWire(
            spi,
            command=pimoroni_physical_feather_pins.pin19(),
            chip_select=pimoroni_physical_feather_pins.pin20(
            ))  # define the display bus

    display = ST7735R(
        display_bus,
        width=160,
        height=80,
        colstart=26,
        rowstart=1,
        rotation=270,
        invert=True
    )  # define the display (these values are specific to the envirowing's screen)

    return display
Exemplo n.º 6
0
    def __init__(self, backlight_control=True, baudrate=100000000):
        spi = board.SPI()
        spi.try_lock()
        spi.configure(baudrate=baudrate)
        spi.unlock()

        displayio.release_displays()

        dev = os.uname().sysname
        if dev == 'samd51':
            print('Configuring for Feather M4 Express')
            cmd = board.D5
            cs = board.D6
            rst = board.D9
        elif dev == 'nrf52840':
            print('Configuring for Feather nRF52840')
            cmd = board.D2
            cs = board.D3
            rst = board.D4
        else:
            raise Exception('Unknown board ' + dev)

        if backlight_control:
            display_bus = displayio.FourWire(spi,
                                             command=cmd,
                                             chip_select=cs,
                                             reset=rst,
                                             baudrate=baudrate)
            self.pwm = None
        else:
            display_bus = displayio.FourWire(spi,
                                             command=cmd,
                                             chip_select=cs,
                                             baudrate=baudrate)
            self.pwm = pulseio.PWMOut(board.D4)
            self.pwm.duty_cycle = 2**15

        self.display = ST7735R(display_bus,
                               width=160,
                               height=80,
                               colstart=26,
                               rowstart=1,
                               rotation=270,
                               invert=True)  #bgr=True
        self.init()
Exemplo n.º 7
0
def setup_display():
    displayio.release_displays()

    spi = board.SPI()
    tft_cs = board.A5
    tft_dc = board.A3

    displayio.release_displays()
    display_bus = displayio.FourWire(spi,
                                     command=tft_dc,
                                     chip_select=tft_cs,
                                     reset=board.A4)

    return ST7735R(display_bus,
                   width=128,
                   height=128,
                   colstart=2,
                   rowstart=1,
                   rotation=180)
Exemplo n.º 8
0
def display_results(tests):
    import board, pimoroni_physical_feather_pins, displayio
    from adafruit_st7735r import ST7735R
    #region Screen setup
    """
    This region of code is used to setup the envirowing screen with displayio
    """

    spi = board.SPI() # define which spi bus the screen is on
    spi.try_lock() # try to get control of the spi bus
    spi.configure(baudrate=100000000) # tell the spi bus how fast it's going to run
    # baudrate doesn't need to be this high in practice, it's just nice to have a quick screen refresh in this case
    spi.unlock() # unlocks the spi bus so displayio can control it
    tft_dc = pimoroni_physical_feather_pins.pin19() # define which pin the command line is on
    tft_cs = pimoroni_physical_feather_pins.pin20() # define which pin the chip select line is on

    displayio.release_displays() # release any displays that may exist from previous code run
    display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=pimoroni_physical_feather_pins.pin21()) # define the display bus

    display = ST7735R(display_bus, width=160, height=80, colstart=26, rowstart=1, rotation=270, invert=True) # define the display (these values are specific to the envirowing's screen)
    
    #endregion Screen setup

    failed = []
    for test in tests.keys():
        if test not in ("Finished", "Read"):
            if not tests[test]["Passed"]:
                failed.append(test)
    
    if not failed:
        print("All Tests Passed!")
    else:
        print("These tests failed:")
        print(", ".join(failed))
    tests["Read"] = True
    write_tests_to_nvm(tests, num_test_bytes)
    while True:
        pass
Exemplo n.º 9
0
upRight = servo.Servo(pwm3) #alternative name servo3
upLeft = servo.Servo(pwm4) #alternative name servo4

# setting up sonar to use pin out D3 and D4
sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.D3, echo_pin=board.D4)

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

# setting up LCD board
spi = board.SPI()
tft_cs = board.D11
tft_dc = board.D9
# setting up the LCD board so the code knows the size of the screen
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D7)
display = ST7735R(display_bus, width=128, height=128)

# Make the display context
splash = displayio.Group(max_size=20)
my_label = label.Label(terminalio.FONT, text="My Label Text", color=0xFFFFFF, x = 40, y = 40)
splash.append(my_label)
display.show(splash)

# setting up text to display on LCD
text = "Hello world"
text_area = label.Label(terminalio.FONT, text=text)
text_area.x = 30
text_area.y = 60
display.show(text_area)

def dance1():
# pylint: disable=attribute-defined-outside-init

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

ss = TFTShield18()

spi = board.SPI()
tft_cs = board.D10
tft_dc = board.D8

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)

ss.tft_reset()
display = ST7735R(
    display_bus, width=160, height=128, rotation=90, bgr=True, auto_refresh=False
)

ss.set_backlight(True)


class OV7670_GrandCentral(OV7670):
    def __init__(self):
        with digitalio.DigitalInOut(board.D39) as shutdown:
            shutdown.switch_to_output(True)
            time.sleep(0.001)
            bus = busio.I2C(board.D24, board.D25)
        self._bus = bus
        OV7670.__init__(
            self,
            bus,
This test will initialize the display using displayio
and draw a solid red background
"""

import board
import displayio
from adafruit_st7735r import ST7735R

spi = board.SPI()
tft_cs = board.D5
tft_dc = board.D6

displayio.release_displays()
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=board.D9)

display = ST7735R(display_bus, width=128, height=160, bgr=True)

# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)

color_bitmap = displayio.Bitmap(128, 160, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFF0000

try:
    bg_sprite = displayio.TileGrid(color_bitmap,
                                   pixel_shader=color_palette,
                                   position=(0, 0))
except TypeError:
    bg_sprite = displayio.TileGrid(color_bitmap,
Exemplo n.º 12
0
D_BLACK = 0x000000
D_WHITE = 0xFFFFFF

# setup ST7735 display 1.8in TFT http://www.adafruit.com/products/358 ###############
# see https://github.com/adafruit/Adafruit_CircuitPython_ST7735R/blob/master/examples/st7735r_128x160_simpletest.py
spi = board.SPI()
tft_cs = board.D10
tft_dc = board.D7

displayio.release_displays()
display_bus = displayio.FourWire(spi,
                                 command=tft_dc,
                                 chip_select=tft_cs,
                                 reset=board.D9)

display = ST7735R(display_bus, width=160, height=128, rotation=90, bgr=True)

# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)

left_circle = Circle(40, 30, 15, fill=D_RED)
splash.append(left_circle)
right_circle = Circle(120, 30, 15, fill=D_RED)
splash.append(right_circle)

text = ""
text_group1 = displayio.Group(max_size=2, scale=2, x=0, y=88)
line1_textbox = label.Label(terminalio.FONT,
                            text=text,
                            color=D_YELLOW,
Exemplo n.º 13
0
    def __init__(self):
        self.reset_pin = 8
        self.i2c = board.I2C()
        self.ss = Seesaw(self.i2c, 0x5E)
        self.ss.pin_mode(self.reset_pin, self.ss.OUTPUT)

        self.spi = board.SPI()
        self.tft_cs = board.D5
        self.tft_dc = board.D6
        self._auto_show = True

        displayio.release_displays()
        self.display_bus = displayio.FourWire(self.spi,
                                              command=self.tft_dc,
                                              chip_select=self.tft_cs)

        self.ss.digital_write(self.reset_pin, True)
        self.display = ST7735R(self.display_bus,
                               width=160,
                               height=80,
                               colstart=24,
                               rotation=270,
                               bgr=True)

        self.nbr_rows = 5
        self.row_height = int(self.display.height / self.nbr_rows)
        self.row_vpos = [
            int(i * self.row_height) for i in range(self.nbr_rows)
        ]
        self.row_bkgnd_color = [
            0x808080, 0xFF0000, 0x000040, 0x0000FF, 0xAA0088
        ]
        self.row_text_color = [
            0xFFFFFF, 0xFFFF00, 0xFF0000, 0xFFFF00, 0xFAFAFA
        ]
        self.row_text = ['r1', 'r2', 'r3', 'r4', 'r5']
        # -----------------------------------------------------------------------------------
        # Button handler
        # -----------------------------------------------------------------------------------
        self.btn_mat = []
        self.btn_mat.append([1 << BUTTON_RIGHT, 0, 0, False, 'right'])
        self.btn_mat.append([1 << BUTTON_DOWN, 0, 0, False, 'down'])
        self.btn_mat.append([1 << BUTTON_LEFT, 0, 0, False, 'left'])
        self.btn_mat.append([1 << BUTTON_UP, 0, 0, False, 'up'])
        self.btn_mat.append([1 << BUTTON_SEL, 0, 0, False, 'select'])
        self.btn_mat.append([1 << BUTTON_A, 0, 0, False, 'A'])
        self.btn_mat.append([1 << BUTTON_B, 0, 0, False, 'B'])
        # print(btn_mat)
        self.btn_mask = 0
        for mask_indx in range(len(self.btn_mat)):
            self.btn_mask = self.btn_mask | self.btn_mat[mask_indx][0]
            # print(btn_mask)
        self.ss.pin_mode_bulk(self.btn_mask, self.ss.INPUT_PULLUP)

        self.state_dict = {
            'idle': 0,
            'pressed': 1,
            'pressed_deb': 2,
            'released': 3,
            'released_deb': 4
        }

        self.btn_repeat_time = 1.0
        self.btn_deb_time = 0.1
Exemplo n.º 14
0
    tft_cs = board.D2  # ItsyBitsy M4 Express
    tft_dc = board.D3
    lcd_rst = board.D4
    # battery voltage measurements need a jumper from batt to A1
    vbat_voltage = AnalogIn(board.A1)

# Setup the bus, display object, and font for the display
displayio.release_displays()
if DISPLAY == "0.96 LCD":
    display_bus = displayio.FourWire(spi,
                                     command=tft_dc,
                                     chip_select=tft_cs,
                                     reset=lcd_rst)
    display = ST7735R(display_bus,
                      rotation=TEXT_ROTATION,
                      width=160,
                      height=80,
                      colstart=24,
                      bgr=True)
    font = bitmap_font.load_font("mandalor80.bdf")  # 80 pixel tall bitmap font
elif DISPLAY == "0.96 OLED":
    display_bus = displayio.FourWire(spi,
                                     command=tft_dc,
                                     chip_select=tft_cs,
                                     reset=lcd_rst)
    display = SSD1331(display_bus, rotation=TEXT_ROTATION, width=96, height=64)
    font = bitmap_font.load_font("mandalor64.bdf")  # 64 pixel tall bitmap font
elif DISPLAY == "0.96 Mono OLED":
    TEXT_COLOR = 0xFFFFFF  # it's monochrome, you can only do white
    display_bus = displayio.FourWire(spi,
                                     command=tft_dc,
                                     chip_select=tft_cs,
Exemplo n.º 15
0
tft_cs = pimoroni_physical_feather_pins.pin20(
)  # define which pin the chip select line is on

displayio.release_displays(
)  # release any displays that may exist from previous code run
display_bus = displayio.FourWire(
    spi,
    command=tft_dc,
    chip_select=tft_cs,
    reset=pimoroni_physical_feather_pins.pin21())  # define the display bus

display = ST7735R(
    display_bus,
    width=160,
    height=80,
    colstart=26,
    rowstart=1,
    rotation=270,
    invert=True
)  # define the display (these values are specific to the envirowing's screen)

print("Screen successfully set up!")

#endregion Screen setup

i2c = board.I2C()
print("I2C Initialised!")

#region BME280 testing

bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76)
Exemplo n.º 16
0
reset_pin = 8
i2c = board.I2C()
ss = Seesaw(i2c, 0x5E)
ss.pin_mode(reset_pin, ss.OUTPUT)

spi = board.SPI()
tft_cs = board.D5
tft_dc = board.D6

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)

ss.digital_write(reset_pin, True)
display = ST7735R(display_bus,
                  width=160,
                  height=80,
                  colstart=24,
                  rotation=270,
                  bgr=True)

# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)

color_bitmap = displayio.Bitmap(160, 80, 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)
Exemplo n.º 17
0
from adafruit_st7735r import ST7735R
from TryMoves import Move

# Releases all previous displays
displayio.release_displays()

# LCD Initialization

spi = board.SPI()
tft_cs = board.A2
tft_dc = board.A4
display_bus = displayio.FourWire(spi,
                                 command=tft_dc,
                                 chip_select=tft_cs,
                                 reset=board.A3)
display = ST7735R(display_bus, width=128, height=128, colstart=2, rowstart=1)

# Bluetooth UART
uart = busio.UART(board.TX, board.RX, baudrate=9600)
'''
Function that reads the bluetooth bluefruit input buffer, clears it, and then sets the bluetooth_input variable
'''


def readBluetooth():
    global bluetooth_input
    data = uart.read(8)
    print(data)
    data = str(data)
    if data is not None:
        # decodes the data if it's a valid input
Exemplo n.º 18
0
# Release any resources currently in use for the displays
displayio.release_displays()

spi = board.SPI()
tft_cs = board.D3
tft_dc = board.D4

display_bus = displayio.FourWire(spi,
                                 command=tft_dc,
                                 chip_select=tft_cs,
                                 reset=board.D7)

display = ST7735R(display_bus,
                  width=128,
                  height=128,
                  colstart=2,
                  rowstart=1,
                  rotation=270)

# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)

color_bitmap = displayio.Bitmap(128, 128, 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)
Exemplo n.º 19
0
import displayio
import digitalio
from adafruit_st7735r import ST7735R
from adafruit_rgb_display import color565
import adafruit_rgb_display.st7735 as st7735

tft_cs = board.A2  #digitalio.DigitalInOut(board.A2)
tft_dc = board.A3  #digitalio.DigitalInOut(board.A3)
tft_rc = board.A4  #digitalio.DigitalInOut(board.A4)

spi = board.SPI()
displayio.release_displays()
dbus = displayio.FourWire(spi,
                          command=tft_dc,
                          chip_select=tft_cs,
                          reset=tft_rc)
display = ST7735R(dbus,
                  width=128,
                  height=160,
                  colstart=0,
                  rowstart=0,
                  bgr=True)
f = open("/img.bmp", "rb")
odb = displayio.OnDiskBitmap(f)
face = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter())
splash = displayio.Group(max_size=10)
splash.append(face)
display.show(splash)
while True:
    pass
Exemplo n.º 20
0
PIN_DC = board.GP10
PIN_RST = board.GP11

WIDTH = 160
HEIGHT = 128

spi = busio.SPI(clock=PIN_CLK, MOSI=PIN_TX)  #, MISO=PIN_RX)

display_bus = displayio.FourWire(spi,
                                 command=PIN_DC,
                                 chip_select=PIN_CS,
                                 reset=PIN_RST)

display = ST7735R(display_bus,
                  width=WIDTH,
                  height=HEIGHT,
                  rotation=270,
                  bgr=True)

# Make the display context
splash = displayio.Group()
display.show(splash)

color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
color_palette = displayio.Palette(1)
# write some text in each font color, rgb, cmyk
color_palette[0] = 0xBBBBBB  # light grey

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