Ejemplo n.º 1
0
    def displaysettup(self):
        """Setting up the st7789 Display"""
        
        if self.type == "mini":
            cs_pin = digitalio.DigitalInOut(board.CE0)
            dc_pin = digitalio.DigitalInOut(board.D25)
            backlight = digitalio.DigitalInOut(board.D22)
            reset_pin = None
            BAUDRATE = 24000000

        if self.type == "gamepad":
            cs_pin = digitalio.DigitalInOut(board.CE0)
            dc_pin = digitalio.DigitalInOut(board.D25)
            reset_pin = digitalio.DigitalInOut(board.D24)
            backlight = digitalio.DigitalInOut(board.D26)
            BAUDRATE = 24000000
      
        # Create the ST7789 display, depending on size:
        if self.size == '240x240':
            disp = st7789.ST7789(
                board.SPI(),
                cs=cs_pin,
                dc=dc_pin,
                rst=reset_pin,
                baudrate=BAUDRATE,
                height=240,
                y_offset=80,
                rotation=180
            )

        elif self.size == '240x135':
            # Create the ST7789 display:
            disp = st7789.ST7789(
                board.SPI(), 
                cs=cs_pin, 
                dc=dc_pin, 
                rst=reset_pin, 
                baudrate=BAUDRATE,
                width=135,
                height=240, 
                x_offset=53, 
                y_offset=40,
                )

        # Turn on the backlight
        backlight.switch_to_output()
        backlight.value = True

        return disp
Ejemplo n.º 2
0
class Screen:
    # Create the ST7789 display:
    Disp = st7789.ST7789(
        SPI,
        rotation=0,
        width=240,
        height=240,
        y_offset=80,
        baudrate=BAUDRATE,
        cs=digitalio.DigitalInOut(CS_PIN),
        dc=digitalio.DigitalInOut(DC_PIN))
    currentVC = None

    @staticmethod
    def size():
        return Size(Screen.Disp.width, Screen.Disp.height)

    @staticmethod
    def setup():
        print("Setup Screen")
        Screen.runloop()

    @staticmethod
    def runloop():
        print("Start Runloop")
        while True:
            if Screen.currentVC is not None:
                framebuffer = Screen.currentVC.redraw()
                framebuffer = framebuffer.resize((Screen.size().width, Screen.size().height))
                Screen.Disp.image(framebuffer.convert("RGBA"))
            time.sleep(1.0 / FPS)

    @staticmethod
    def addViewController(VC):
        Screen.currentVC = VC
Ejemplo n.º 3
0
    def __init__(self):
        self.reset_pin = digitalio.DigitalInOut(board.D27)
        self.cs_pin = digitalio.DigitalInOut(board.CE0)
        self.dc_pin = digitalio.DigitalInOut(board.D25)
        self.BAUDRATE = 24000000
        self.spi = board.SPI()
        self.disp = st7789.ST7789(self.spi,
                                  height=240,
                                  y_offset=80,
                                  rotation=180,
                                  cs=self.cs_pin,
                                  dc=self.dc_pin,
                                  rst=self.reset_pin,
                                  baudrate=self.BAUDRATE)
        self.image = Image.new("RGB", (240, 240))
        self.draw = ImageDraw.Draw(self.image)
        # fonts_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'fonts')
        self.font_small = ImageFont.truetype(
            "/usr/share/fonts/truetype/open-sans/OpenSans-Light.ttf", 14)
        self.font_middle = ImageFont.truetype(
            "/usr/share/fonts/truetype/open-sans/OpenSans-Light.ttf", 24)
        self.font_big = ImageFont.truetype(
            "/usr/share/fonts/truetype/open-sans/OpenSans-Light.ttf", 40)

        self.pages = list()
        self.page_black = None
        self.current_page = 0
        self.screen_enabled = True
        self.page_change = False
Ejemplo n.º 4
0
    def __init__(self, refresh_rate=600, width=240, height=240):
        self.get_stats_interval_sec = refresh_rate
        self.width = width
        self.height = height

        self.logger = logging.getLogger(__name__)
        self.logger.propagate = False
        self.logger.addHandler(journal.JournaldLogHandler())
        self.logger.setLevel(logging.INFO)

        cs_pin = digitalio.DigitalInOut(board.CE0)
        dc_pin = digitalio.DigitalInOut(board.D25)
        reset_pin = None
        BAUDRATE = 64000000

        self.display = st7789.ST7789(board.SPI(),
                                     cs=cs_pin,
                                     dc=dc_pin,
                                     rst=reset_pin,
                                     baudrate=BAUDRATE,
                                     width=width,
                                     height=height,
                                     y_offset=80,
                                     rotation=180)

        backlight = digitalio.DigitalInOut(board.D22)
        backlight.switch_to_output()
        backlight.value = True
        self.buttonA = digitalio.DigitalInOut(board.D23)
        self.buttonB = digitalio.DigitalInOut(board.D24)
        self.buttonA.switch_to_input()
        self.buttonB.switch_to_input()
        self._button_hold_time = 2.0

        self.image = Image.new("RGB", (width, height))
        self.draw = ImageDraw.Draw(self.image)
        self.draw.rectangle((0, 0, width, height), outline=0, fill=(0, 0, 0))
        self.display.image(self.image)  #, rotation)
        self.dejavu = ImageFont.truetype(
            "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 24)
        self.roboto = ImageFont.truetype(
            "/usr/share/fonts/truetype/roboto/unhinted/Roboto-Black.ttf", 24)

        self.blue = "#007bff"
        self.indigo = "#6610f2"
        self.purple = "#6f42c1"
        self.pink = "#e83e8c"
        self.red = "#dc3545"
        self.orange = "#fd7e14"
        self.yellow = "#ffc107"
        self.green = "#28a745"
        self.teal = "#20c997"
        self.cyan = "#17a2b8"
        self.gray = "#6c757d"
        self.gray_dark = "#343a40"

        self.stats = CovidStats()

        loop = asyncio.get_event_loop()
        loop.create_task(self.update_loop())
Ejemplo n.º 5
0
    def __init__(self, conf_path=util.CONF, env_path=util.ENV):
        with open(conf_path) as cf:
            self.conf = json.load(cf)

        with open(env_path) as ef:
            self.env = json.load(ef)

        self.lock = asyncio.Lock()
        self.i2s_lock = asyncio.Lock()
        self.mic_int = False
        self.event_loop = asyncio.get_running_loop()

        self.button = Button(self.conf['button'])
        self._double_press_threshold = .5
        self.cam = None

        spi = board.SPI()
        cs_pin = digitalio.DigitalInOut(
            getattr(board, f'D{self.conf["screen"]["cs"]}'))
        dc_pin = digitalio.DigitalInOut(
            getattr(board, f'D{self.conf["screen"]["dc"]}'))
        reset_pin = digitalio.DigitalInOut(
            getattr(board, f'D{self.conf["screen"]["rst"]}'))
        self.screen = st7789.ST7789(
            spi,
            rotation=90,
            width=135,
            height=240,
            x_offset=53,
            y_offset=40,
            cs=cs_pin,
            dc=dc_pin,
            rst=reset_pin,
            baudrate=24000000,
        )

        try:  # the try-catch is for testing the server without servo driver connected
            self.servokit = ServoKit(channels=16,
                                     freq=self.conf['servo']['freq'])
            self.screen_backlight = self.servokit.servo[
                self.conf['servo']['backlight']['channel']]
            self.screen_backlight.set_pulse_width_range(
                0, 1000000 // self.conf['servo']['freq'])
            self.screen_backlight.fraction = 0

            self.speaker_power = self.servokit.servo[self.conf['servo']
                                                     ['speaker']['channel']]
            self.speaker_power.set_pulse_width_range(
                0, 1000000 // self.conf['servo']['freq'])
            self.speaker_power.fraction = 0

            self.servo_update_rate = self.conf['servo']['update_rate']
            self.reset_servos()
            self._head.angle = self.rarm.fraction = self.larm.fraction = 0
            time.sleep(.5)
            self.relax_lift()
            self.relax_head()
        except Exception as e:
            print(e)
Ejemplo n.º 6
0
    def __init__(self, refresh_rate=0.5, data_points=61):
        self._disp = st7789.ST7789(board.SPI(),
                                   baudrate=64000000,
                                   cs=digitalio.DigitalInOut(board.D4),
                                   dc=digitalio.DigitalInOut(board.D5),
                                   rst=digitalio.DigitalInOut(board.D6),
                                   width=135,
                                   height=240,
                                   x_offset=53,
                                   y_offset=40)

        self._height = self._disp.width  # we swap height/width to rotate it to landscape!
        self._width = self._disp.height
        self._image = Image.new('RGB', (self._width, self._height))
        self._rotation = 90
        self._draw = ImageDraw.Draw(self._image)
        self._draw.rectangle((0, 0, self._width, self._height),
                             outline=0,
                             fill=0)
        self._disp.image(self._image, self._rotation)
        #self._font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 24)

        x_time = [x * refresh_rate for x in range(data_points)]
        x_time.reverse()

        self._y_data = [[
            deque([None] * data_points, maxlen=data_points)
            for _ in Ui.PLOT_CONFIG['line_config']
        ]]
        plt.style.use('dark_background')
        fig, self._ax = plt.subplots(figsize=(self._disp.width / 100,
                                              self._disp.height / 100))
        self._ax.xaxis.set_ticklabels([])
        self._ax.grid(True, linestyle=':')
        self._ax.set_xlim(min(x_time), max(x_time))
        self._ax.invert_xaxis()
        if 'title' in Ui.PLOT_CONFIG:
            self._ax.set_title(Ui.PLOT_CONFIG['title'], position=(0.5, 0.8))
        if 'ylim' in Ui.PLOT_CONFIG:
            self._ax.set_ylim(Ui.PLOT_CONFIG['ylim'])

        self._plot_lines = []
        for index, line_config in enumerate(Ui.PLOT_CONFIG['line_config']):
            line, = self._ax.plot(x_time, self._y_data[index])
            if 'color' in line_config:
                line.set_color(line_config['color'])
            if 'width' in line_config:
                line.set_linewidth(line_config['width'])
            if 'style' in line_config:
                line.set_linestyle(line_config['style'])
            self._plot_lines.append(line)

        self._t_poll = None
        self._running = False
        self._refresh_rate = refresh_rate

        atexit.register(self._cleanup)
Ejemplo n.º 7
0
    def setup(self, setupDisplay):
        if setupDisplay:
            import board
            from digitalio import DigitalInOut, Direction
            import adafruit_rgb_display.st7789 as st7789

            print("Setting up Adafruit st7789 driver...")
            # Create the display
            cs_pin = DigitalInOut(board.CE0)
            dc_pin = DigitalInOut(board.D25)
            reset_pin = DigitalInOut(board.D24)
            BAUDRATE = 24000000

            spi = board.SPI()
            self.display = st7789.ST7789(spi,
                                         width=self.width,
                                         height=self.height,
                                         y_offset=80,
                                         rotation=self.rotation,
                                         cs=cs_pin,
                                         dc=dc_pin,
                                         rst=reset_pin,
                                         baudrate=BAUDRATE)
            # Get the Adafruit 1.3" TFT Bonnet Buttons
            # Input pins:
            button_A = DigitalInOut(board.D5)
            button_A.direction = Direction.INPUT

            button_B = DigitalInOut(board.D6)
            button_B.direction = Direction.INPUT

            button_L = DigitalInOut(board.D27)
            button_L.direction = Direction.INPUT

            button_R = DigitalInOut(board.D23)
            button_R.direction = Direction.INPUT

            button_U = DigitalInOut(board.D17)
            button_U.direction = Direction.INPUT

            button_D = DigitalInOut(board.D22)
            button_D.direction = Direction.INPUT

            button_C = DigitalInOut(board.D4)
            button_C.direction = Direction.INPUT

            self.buttons['A'] = button_A
            self.buttons['B'] = button_B
            self.buttons['LEFT'] = button_L
            self.buttons['RIGHT'] = button_R
            self.buttons['UP'] = button_U
            self.buttons['DOWN'] = button_D
            self.buttons['STICK'] = button_C
        else:
            print("Not using Adafruit Driver.")
Ejemplo n.º 8
0
    def __init__(self, cwd):
        # Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4):
        cs_pin = digitalio.DigitalInOut(board.CE0)
        dc_pin = digitalio.DigitalInOut(board.D1)
        reset_pin = None

        # Config for display baudrate (default max is 24mhz):
        BAUDRATE = 64000000

        # Setup SPI bus using hardware SPI:
        spi = board.SPI()

        # Create the ST7789 display:
        self.disp = st7789.ST7789(
            spi,
            cs=cs_pin,
            dc=dc_pin,
            rst=reset_pin,
            baudrate=BAUDRATE,
            width=135,
            height=240,
            x_offset=53,
            y_offset=40,
        )

        # Create blank image for drawing.
        # Make sure to create image with mode '1' for 1-bit color.
        self.width = self.disp.width - 1
        self.height = self.disp.height - 1

        padding = 0
        self.top = padding
        self.bottom = self.height - padding
        self.image = Image.new("RGB", (self.height, self.width))

        # Get drawing object to draw on image.
        self.draw = ImageDraw.Draw(self.image)

        # Draw a black filled box to clear the image.
        #self.draw.rectangle((0, 0, self.height, self.width), outline=0, fill=0)

        # Font
        self.font_size = 30
        self.font = ImageFont.truetype(
            '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', self.font_size)
        self.splash_font_size = 40
        self.splash_font = ImageFont.truetype(
            '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf',
            self.splash_font_size)

        # Splash
        self.splash_show()
Ejemplo n.º 9
0
 def __init__(self):
     self._backlight_pin.switch_to_output()
     self._backlight_pin.value = True
     self._disp = st7789.ST7789(
         spi,
         cs=self._cs_pin,
         dc=self._dc_pin,
         rst=self._reset_pin,
         baudrate=self._BAUDRATE,
         width=self.
         height,  # we swap height/width to rotate it to landscape!
         height=self.width,
         x_offset=53,
         y_offset=40,
     )
Ejemplo n.º 10
0
    def __init__(self,
                 background="black",
                 foreground="white",
                 rotation=270,
                 padding=-2,
                 width=135,
                 height=240,
                 x_offset=53,
                 y_offset=40,
                 baudrate=64000000,
                 ttfont='dejavu/DejaVuSans.ttf',
                 fontsize=24):
        # Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4):
        cs_pin = digitalio.DigitalInOut(board.CE0)
        dc_pin = digitalio.DigitalInOut(board.D25)
        reset_pin = None

        # Setup SPI bus using hardware SPI:
        spi = board.SPI()

        # Create the ST7789 display:
        self.__disp = st7789.ST7789(spi,
                                    cs=cs_pin,
                                    dc=dc_pin,
                                    rst=reset_pin,
                                    baudrate=baudrate,
                                    width=width,
                                    height=height,
                                    x_offset=x_offset,
                                    y_offset=y_offset)

        # Create blank image for drawing.
        # Make sure to create image with mode 'RGB' for full color.
        self.__height = self.__disp.width  # we swap height/width to rotate it to landscape!
        self.__width = self.__disp.height
        self.__image = Image.new('RGB', (self.__width, self.__height))
        self.__rotation = rotation
        self.__padding = padding
        self.__background = background
        self.__foreground = foreground

        # Get drawing object to draw on image.
        self.__draw = ImageDraw.Draw(self.__image)
        self.clear()
        self.backlight(False)

        self.setFont(fontsize, ttfont)
Ejemplo n.º 11
0
    def __init__(self, conf_path=util.CONF, env_path=util.ENV):
        with open(conf_path) as cf:
            self.conf = json.load(cf)

        with open(env_path) as ef:
            self.env = json.load(ef)

        self.lock = asyncio.Lock()
        self.event_loop = asyncio.get_running_loop()

        self.button = Button(self.conf['button'])
        self.buzzer = TonalBuzzer(self.conf['buzzer'])

        self.servokit = ServoKit(channels=16, freq=self.conf['servo']['freq'])

        self.screen_backlight = self.servokit.servo[self.conf['servo']
                                                    ['backlight']['channel']]
        self.screen_backlight.set_pulse_width_range(
            0, 100000 // self.conf['servo']['freq'])
        self.screen_backlight.fraction = 0
        spi = board.SPI()
        cs_pin = digitalio.DigitalInOut(
            getattr(board, f'D{self.conf["screen"]["cs"]}'))
        dc_pin = digitalio.DigitalInOut(
            getattr(board, f'D{self.conf["screen"]["dc"]}'))
        reset_pin = digitalio.DigitalInOut(
            getattr(board, f'D{self.conf["screen"]["rst"]}'))
        self.screen = st7789.ST7789(
            spi,
            rotation=90,
            width=135,
            height=240,
            x_offset=53,
            y_offset=40,
            cs=cs_pin,
            dc=dc_pin,
            rst=reset_pin,
            baudrate=24000000,
        )
        self.servo_update_rate = self.conf['servo']['update_rate']
        self._double_press_max_interval = .5
        self.reset_servos()
        self._head.angle = self.rarm.fraction = self.larm.fraction = 0
        time.sleep(.5)
        self.relax_lift()
        self.relax_head()
        self.cam = None
Ejemplo n.º 12
0
    def __init__(self):

        # Create the ST7789 display:
        self.disp = st7789.ST7789(
            board.SPI(),  # Setup SPI bus using hardware SPI
            cs=digitalio.DigitalInOut(
                board.CE0
            ),  # Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4)
            dc=digitalio.DigitalInOut(board.D25),
            rst=None,
            baudrate=
            64000000,  # Config for display baudrate (default max is 24mhz)
            width=135,
            height=240,
            x_offset=53,
            y_offset=40,
        )

        # Create blank image for drawing.
        # Make sure to create image with mode 'RGB' for full color.
        self.height = self.disp.width  # we swap height/width to rotate it to landscape!
        self.width = self.disp.height
        self.image = Image.new("RGB", (self.width, self.height))
        self.rotation = 90

        # Text helping things
        self.padding = -2
        self.top = self.padding
        self.bottom = self.height - self.padding
        # Move left to right keeping track of the current x position for drawing shapes.
        self.x = 0
        self.y = self.top
        # Alternatively load a TTF font.  Make sure the .ttf font file is in the
        # same directory as the python script!
        # Some other nice fonts to try: http://www.dafont.com/bitmap.php
        self.font = ImageFont.truetype(
            "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 18)

        # Get drawing object to draw on image.
        self.draw = ImageDraw.Draw(self.image)

        self.blank()
        self.commit()

        self.backlight = Backlight()
        self.backlight.on()
Ejemplo n.º 13
0
    def __init__(self, width: int, height: int):
        super().__init__()
        cs_pin = digitalio.DigitalInOut(board.CE0)
        dc_pin = digitalio.DigitalInOut(board.D25)
        self.backlight_pin = digitalio.DigitalInOut(board.D22)
        self.backlight_pin.switch_to_output()

        BAUDRATE = 64000000
        self.display = st7789.ST7789(
            board.SPI(),
            cs=cs_pin,
            dc=dc_pin,
            baudrate=BAUDRATE,
            width=width,
            height=height,
            x_offset=0,
            y_offset=80,  # needed for 240x240 display
        )
Ejemplo n.º 14
0
    def _initDisplay(self):
        """
        Set up the display board.

        """
        # Create the ST7789 display object
        self._disp = st7789.ST7789(
            board.SPI(),
            cs=digitalio.DigitalInOut(board.CE0),
            dc=digitalio.DigitalInOut(board.D25),
            rst=None,
            baudrate=64000000,
            width=240,
            height=240,
            x_offset=0,
            y_offset=80,
        )

        # for convenience
        self._width = self._disp.height
        self._height = self._disp.width

        self._image = Image.new("RGB", (self._width, self._height))
        self._draw = ImageDraw.Draw(self._image)

        self.clearScreen()
        padding = -2
        self._yTop = padding
        bottom = self._height - padding

        self._font = ImageFont.truetype(
            "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 24)
        self._fontHeight = self._font.getsize("X")[1]

        self._setupGPIO()

        # Turn on the backlight
        self._backlight = digitalio.DigitalInOut(board.D22)
        self._backlight.switch_to_output()
        self._backlight.value = True
Ejemplo n.º 15
0
def displaysettup():
    """Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4)"""
    cs_pin = digitalio.DigitalInOut(board.CE0)
    dc_pin = digitalio.DigitalInOut(board.D25)
    reset_pin = None

    # Config for display baudrate (default max is 24mhz):
    BAUDRATE = 64000000

    # Setup SPI bus using hardware SPI:
    spi = board.SPI()

    # Create the ST7789 display:
    disp = st7789.ST7789(spi,
                         cs=cs_pin,
                         dc=dc_pin,
                         rst=reset_pin,
                         baudrate=BAUDRATE,
                         width=135,
                         height=240,
                         x_offset=53,
                         y_offset=40)
    return disp
Ejemplo n.º 16
0
def init_LCD():
    # Configuration for CS and DC pins
    cs_pin = digitalio.DigitalInOut(board.CE0)
    dc_pin = digitalio.DigitalInOut(board.D25)
    reset_pin = digitalio.DigitalInOut(board.D24)

    # Config for display baudrate (default max is 24mhz):
    BAUDRATE = 24000000

    # Setup SPI bus using hardware SPI:
    spi = board.SPI()

    # Create the display:
    return st7789.ST7789(
        spi,
        height=240,
        y_offset=80,
        rotation=180,
        cs=cs_pin,
        dc=dc_pin,
        rst=reset_pin,
        bauadrate=BAUDRATE
    )
Ejemplo n.º 17
0
 def __init__(self, user_interface):
     self.user_interface = user_interface
     self.cs_pin = DigitalInOut(board.CE0)
     self.dc_pin = DigitalInOut(board.D25)
     self.reset_pin = DigitalInOut(board.D24)
     self.baudrate = 24000000
     self.spi = board.SPI()
     self.display = st7789.ST7789(self.spi,
                                  height=240,
                                  y_offset=80,
                                  rotation=180,
                                  cs=self.cs_pin,
                                  dc=self.dc_pin,
                                  rst=self.reset_pin,
                                  baudrate=self.baudrate)
     self.button_A = DigitalInOut(board.D5)
     self.button_A.direction = Direction.INPUT
     self.button_B = DigitalInOut(board.D6)
     self.button_B.direction = Direction.INPUT
     self.button_Left = DigitalInOut(board.D27)
     self.button_Left.direction = Direction.INPUT
     self.button_Right = DigitalInOut(board.D23)
     self.button_Right.direction = Direction.INPUT
     self.button_Up = DigitalInOut(board.D17)
     self.button_Up.direction = Direction.INPUT
     self.button_Down = DigitalInOut(board.D22)
     self.button_Down.direction = Direction.INPUT
     self.button_Select = DigitalInOut(board.D4)
     self.button_Select.direction = Direction.INPUT
     self.backlight = DigitalInOut(board.D26)
     self.backlight.switch_to_output()
     self.backlight.value = True
     self.USB_last_time = time.time()
     self.USB_refresh_time = 5.0
     self.USB_previous = False
     self.USB_found = False
     self.screen = screen(self, self.user_interface)
Ejemplo n.º 18
0
#    board.SPI(),
#    cs=cs_pin,
#    dc=dc_pin,
#    baudrate=BAUDRATE,
#    width=135,
#    height=240,
#    x_offset=53,
#    y_offset=40,
#    rotation=270,
#)

# full height adafruit screen 1.3" (240x240), two buttons
disp = st7789.ST7789(spi,
                     cs=cs_pin,
                     dc=dc_pin,
                     baudrate=BAUDRATE,
                     height=240,
                     y_offset=80,
                     rotation=180)

# don't write to display concurrently with thread
display_lock = threading.Lock()

# Create image and drawing object
if disp.rotation % 180 == 90:
    height = disp.width  # we swap height/width to rotate it to landscape!
    width = disp.height
else:
    width = disp.width  # we swap height/width to rotate it to landscape!
    height = disp.height
image = Image.new("RGBA", (width, height))
Ejemplo n.º 19
0
value_api_url = "https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"

# Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4):
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.CE1)
reset_pin = None

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()

# Create the ST7789 display:
disp = st7789.ST7789(spi, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE,
                     rotation=90, width=280, height=290, x_offset=30, y_offset=30)

# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
height = disp.width   # we swap height/width to rotate it to landscape!
width = disp.height
image = Image.new('RGB', (width, height, rotation))

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)

# Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), fill=(255, 255, 255))
disp.image(image, rotation)
# Draw some shapes.
# First define some constants to allow easy resizing of shapes.
Ejemplo n.º 20
0
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = None

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()

# Create the ST7789 display:
disp = st7789.ST7789(spi,
                     cs=cs_pin,
                     dc=dc_pin,
                     rst=reset_pin,
                     baudrate=BAUDRATE,
                     width=290,
                     height=290,
                     x_offset=50,
                     y_offset=50)

# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
height = disp.width  # we swap height/width to rotate it to landscape!
width = disp.height
image = Image.new('RGB', (width, height))
rotation = 90

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
Ejemplo n.º 21
0
spi = board.SPI()

# pylint: disable=line-too-long
# Create the display:
# disp = st7789.ST7789(spi, rotation=90,                            # 2.0" ST7789
disp = st7789.ST7789(spi, height=240, y_offset=80, rotation=180,  # 1.3", 1.54" ST7789
# disp = st7789.ST7789(spi, rotation=90, width=135, height=240, x_offset=53, y_offset=40, # 1.14" ST7789
# disp = hx8357.HX8357(spi, rotation=180,                           # 3.5" HX8357
# disp = st7735.ST7735R(spi, rotation=90,                           # 1.8" ST7735R
# disp = st7735.ST7735R(spi, rotation=270, height=128, x_offset=2, y_offset=3,   # 1.44" ST7735R
# disp = st7735.ST7735R(spi, rotation=90, bgr=True,                 # 0.96" MiniTFT ST7735R
# disp = ssd1351.SSD1351(spi, rotation=180,                         # 1.5" SSD1351
# disp = ssd1351.SSD1351(spi, height=96, y_offset=32, rotation=180, # 1.27" SSD1351
# disp = ssd1331.SSD1331(spi, rotation=180,                         # 0.96" SSD1331
disp = ili9341.ILI9341(
    spi,
    rotation=90,  # 2.2", 2.4", 2.8", 3.2" ILI9341
    cs=cs_pin,
    dc=dc_pin,
    rst=reset_pin,
    baudrate=BAUDRATE,
)
# pylint: enable=line-too-long

# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
if disp.rotation % 180 == 90:
    height = disp.width  # we swap height/width to rotate it to landscape!
    width = disp.height
else:
    width = disp.width  # we swap height/width to rotate it to landscape!
    height = disp.height
Ejemplo n.º 22
0
# The gateway address and host address are expected to be in the environment
GATEWAY = os.environ['GATEWAY']
IPADDR = os.environ['IPADDR']

# Commands to check LAN, WAN, etc.
LAN_COMMAND = 'curl -sS https://' + GATEWAY + ' 2>/dev/null | wc -l'
WAN_COMMAND = 'curl -sS https://google.com 2>/dev/null | wc -l'
UPTIME_COMMAND = "uptime | awk '{printf \"up %s avg %.2f\", $3, $(NF-2)}'"

# Setup the display:
BAUDRATE = 24000000
spi = board.SPI()
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = digitalio.DigitalInOut(board.D24)
disp = st7789.ST7789(spi, rotation=90, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE)

# Create an 'RGB' drawing canvas
if disp.rotation % 180 == 90:
  # Swap height/width when rotating to landscape!
  height = disp.width
  width = disp.height
else:
  width = disp.width
  height = disp.height
original = Image.new('RGB', (width, height))
draw = ImageDraw.Draw(original)

# Draw a white filled box to clear the image.
draw.rectangle((0, 0, width, height), outline=0, fill="#FFFFFF")
disp.image(original)
Ejemplo n.º 23
0
value_api_url = "https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"

# Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4):
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = None

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 16000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()

# Create the ST7789 display:
disp = st7789.ST7789(spi, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE,
                     width=320, height=480, invert=True, x_offset=0, y_offset=0)

# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
height = disp.width   # we swap height/width to rotate it to landscape!
width = disp.height
image = Image.new('RGB', (width, height))
rotation = 90
setRotation(2)
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)

# Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), fill=(255,255,255))
disp.image(image, rotation)
# Draw some shapes.
Ejemplo n.º 24
0
    def _SetupDisplaySt7789(self, clv_OutputDisplay):
        rtn = True
        # ----------------------------------------------------------------------
        # Create the ST7789 display (this is 240x240 version):
        # ----------------------------------------------------------------------
        cs_pin = digitalio.DigitalInOut(board.CE0)
        dc_pin = digitalio.DigitalInOut(board.D25)
        reset_pin = None

        BAUDRATE = 64000000  # Default max is 24Mhz
        try:
            spi = board.SPI()  # Setup SPI bus using hardware SPI
        except Exception as e:
            logfile.Console("OLED display st7789 cannot be initialized: %s" %
                            e)
            rtn = False
        else:
            # ------------------------------------------------------------------
            # Now initialize the display
            # ------------------------------------------------------------------
            self.st7789 = st7789.ST7789(
                spi,
                cs=cs_pin,
                dc=dc_pin,
                rst=reset_pin,
                baudrate=BAUDRATE,
                width=240,
                height=240,
                x_offset=0,
                y_offset=80,
            )

            # ------------------------------------------------------------------
            # As copied from https://learn.adafruit.com
            # For testing
            # ------------------------------------------------------------------
            self.backlight = digitalio.DigitalInOut(board.D22)
            self.backlight.switch_to_output()
            self.backlight.value = True

            assert (clv_OutputDisplay in ('st7789', 'st7789b'))
            if clv_OutputDisplay == 'st7789':
                self.buttonA = digitalio.DigitalInOut(board.D23)
                self.buttonB = digitalio.DigitalInOut(board.D24)

            elif clv_OutputDisplay == 'st7789b':  # Add Waveshare 1.3 LCD
                self.buttonA = digitalio.DigitalInOut(board.D20)
                self.buttonB = digitalio.DigitalInOut(board.D16)
                # --------------------------------------------------------------
                # The Waveshare is missing the reset circuit from the Adafruit
                # display, the reset_pin needs to be defined.
                # --------------------------------------------------------------
                cs_pin = digitalio.DigitalInOut(board.CE0)
                dc_pin = digitalio.DigitalInOut(board.D25)
                reset_pin = digitalio.DigitalInOut(board.D27)

            self.buttonA.switch_to_input(digitalio.Pull.UP)
            self.buttonB.switch_to_input(digitalio.Pull.UP)

            self.ButtonDefaultValue = self.buttonA.value
            # ------------------------------------------------------------------
            # Startup image is in directory of the .py [or embedded in .exe]
            # ------------------------------------------------------------------
            dirname = os.path.dirname(__file__)
            FortiusAnt_jpg = os.path.join(dirname, "FortiusAnt.jpg")
            self.faImage = Image.open(FortiusAnt_jpg)

            # ------------------------------------------------------------------
            # Scale the image to the smaller screen dimension:
            # ------------------------------------------------------------------
            image_ratio = self.faImage.width / self.faImage.height
            screen_ratio = self.st7789.width / self.st7789.height
            if screen_ratio < image_ratio:
                scaled_width = self.faImage.width * self.st7789.height // self.faImage.height
                scaled_height = self.st7789.height
            else:
                scaled_width = self.st7789.width
                scaled_height = self.faImage.height * self.st7789.width // self.faImage.width
            self.faImage = self.faImage.resize((scaled_width, scaled_height),
                                               Image.BICUBIC)

            # ------------------------------------------------------------------
            # Crop and center the image:
            # ------------------------------------------------------------------
            x_jpg = scaled_width // 2 - self.st7789.width // 2
            y_jpg = scaled_height // 2 - self.st7789.height // 2
            self.faImage = self.faImage.crop(
                (x_jpg, y_jpg, x_jpg + self.st7789.width,
                 y_jpg + self.st7789.height))

            #-------------------------------------------------------------------
            # Load a TTF font - other good fonts available from: http://www.dafont.com/bitmap.php
            #-------------------------------------------------------------------
            self.fontS = ImageFont.truetype(
                "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 22)
            self.fontLb = ImageFont.truetype(
                "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 36)

            # ------------------------------------------------------------------
            # Display image, for at least three seconds
            # ------------------------------------------------------------------
            self._ShowImage()
            time.sleep(3)

            #-------------------------------------------------------------------
            # Part 2: display control text
            # Create blank image for drawing with mode 'RGB' for full color
            # Get drawing object to draw on image
            #-------------------------------------------------------------------
            self.image = Image.new("RGB",
                                   (self.st7789.width, self.st7789.height))
            self.draw = ImageDraw.Draw(self.image)

        return rtn
Ejemplo n.º 25
0
import webcolors

# The display uses a communication protocol called SPI.
# SPI will not be covered in depth in this course. 
# you can read more https://www.circuitbasics.com/basics-of-the-spi-communication-protocol/
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = None
BAUDRATE = 64000000  # the rate  the screen talks to the pi
# Create the ST7789 display:
display = st7789.ST7789(
    board.SPI(),
    cs=cs_pin,
    dc=dc_pin,
    rst=reset_pin,
    baudrate=BAUDRATE,
    width=135,
    height=240,
    x_offset=53,
    y_offset=40,
)


# these setup the code for our buttons and the backlight and tell the pi to treat the GPIO pins as digitalIO vs analogIO
backlight = digitalio.DigitalInOut(board.D22)
backlight.switch_to_output()
backlight.value = True
buttonA = digitalio.DigitalInOut(board.D23)
buttonB = digitalio.DigitalInOut(board.D24)
buttonA.switch_to_input()
buttonB.switch_to_input()
# Configuratoin for CS and DC pins (these are FeatherWing defaults on M0/M4):
cs_pin = digitalio.DigitalInOut(board.D5)
dc_pin = digitalio.DigitalInOut(board.D6)
reset_pin = digitalio.DigitalInOut(board.D9)

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()

# Create the ST7789 display:
display = st7789.ST7789(spi,
                        cs=cs_pin,
                        dc=dc_pin,
                        rst=reset_pin,
                        baudrate=BAUDRATE)

# Main loop:
while True:
    # Fill the screen red, green, blue, then black:
    for color in ((255, 0, 0), (0, 255, 0), (0, 0, 255)):
        display.fill(color565(color))
    # Clear the display
    display.fill(0)
    # Draw a red pixel in the center.
    display.pixel(display.width // 2, display.height // 2, color565(255, 0, 0))
    # Pause 2 seconds.
    time.sleep(2)
    # Clear the screen a random color
Ejemplo n.º 27
0
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = None

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 64000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()

# Create the ST7789 display:
disp = st7789.ST7789(spi,
                     cs=cs_pin,
                     dc=dc_pin,
                     rst=reset_pin,
                     baudrate=BAUDRATE,
                     width=135,
                     height=240,
                     x_offset=53,
                     y_offset=40)

# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
height = disp.width  # we swap height/width to rotate it to landscape!
width = disp.height
image = Image.new('RGB', (width, height))
rotation = 90

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
Ejemplo n.º 28
0
# Configuration for CS and DC pins (these are FeatherWing defaults on M0/M4):
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = None

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 16000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()

# Create the ST7789 display:
disp = st7789.ST7789(spi,
                     cs=cs_pin,
                     dc=dc_pin,
                     rst=reset_pin,
                     baudrate=BAUDRATE,
                     width=480,
                     height=320)

# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
height = disp.width  # we swap height/width to rotate it to landscape!
width = disp.height
image = Image.new('RGB', (width, height))
rotation = 90
setRotation = 2

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
# Configuratoin for CS and DC pins (these are FeatherWing defaults on M0/M4):
cs_pin = digitalio.DigitalInOut(board.D5)
dc_pin = digitalio.DigitalInOut(board.D6)
reset_pin = digitalio.DigitalInOut(board.D9)

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()

# Create the ST7789 display: adjust x / y offsets depending on rotation and your screen (often by 80)
display = st7789.ST7789(spi,
                        cs=cs_pin,
                        dc=dc_pin,
                        rst=reset_pin,
                        x_offset=0,
                        y_offset=0,
                        rotation=0,
                        baudrate=BAUDRATE)

# Main loop:
while True:
    # Fill the screen red, green, blue, then black:
    for color in ((255, 0, 0), (0, 255, 0), (0, 0, 255)):
        display.fill(color565(color))
    # Clear the display
    display.fill(0)
    # Draw a red pixel in the center.
    display.pixel(display.width // 2, display.height // 2, color565(255, 0, 0))
    # Pause 2 seconds.
    time.sleep(2)
Ejemplo n.º 30
0
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = None

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()

# Create the ST7789 display:
disp = st7789.ST7789(spi,
                     cs=cs_pin,
                     dc=dc_pin,
                     rst=reset_pin,
                     baudrate=BAUDRATE,
                     width=318,
                     height=478,
                     x_offset=20,
                     y_offset=20)

# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
height = disp.width  # we swap height/width to rotate it to landscape!
width = disp.height
image = Image.new('RGB', (width, height))
rotation = 90

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)