Ejemplo n.º 1
0
 def check_connection(self):
     """ Check connection to node and lcd """
     if self.node.connected:
         if not self._lcd:
             if self.type == 'i2c':
                 # PCF I2C Backpack
                 # [lcd_Addr, enable, Rw, Rs, d4, d5, d6, d7, backlighPin, pol]
                 pins = [0x27, 2, 1, 0, 4, 5, 6, 7, 3, 0]
                 # TODO: Add other backback support
                 self._lcd = Lcd_I2C(pins, [self.columns, self.rows],
                                     connection=self.node.connection)
             else:
                 # GPIO Connection
                 # [rs, enable, d4, d5, d6, d7]
                 pins = [
                     self.config.get('rs_pin', 7),
                     self.config.get('enable_pin', 8),
                     self.config.get('pin_1', 9),
                     self.config.get('pin_2', 10),
                     self.config.get('pin_3', 11),
                     self.config.get('pin_4', 12)
                 ]
                 self._lcd = Lcd(pins, [self.columns, self.rows],
                                 connection=connection)
     else:
         self._lcd = None
Ejemplo n.º 2
0
def hello():
    connection = SerialManager(sleep_after_connect=2)

    cols, rows = 16, 2

    if I2C:
        pins = [0x27, 2, 1, 0, 4, 5, 6, 7, 3, 0]  # "ebay" version
        lcd = Lcd_I2C(pins, [cols, rows], connection=connection)
        lcd.setBacklight(0)
    else:
        pins = [7, 8, 9, 10, 11, 12]
        lcd = Lcd(pins, [cols, rows], connection=connection)

    lcd.setCursor(0, 0)
    lcd.printString('hello')
Ejemplo n.º 3
0
def hello():
    connection = SerialManager(sleep_after_connect=2)

    cols, rows = 16, 2

    if I2C:
        pins = [0x27, 2, 1, 0, 4, 5, 6, 7, 3, 0]  # "ebay" version
        lcd = Lcd_I2C(pins, [cols, rows], connection=connection)
        lcd.setBacklight(0)
    else:
        pins = [7, 8, 9, 10, 11, 12]
        lcd = Lcd(pins, [cols, rows], connection=connection)

    lcd.setCursor(0, 0)
    lcd.printString('hello')
Ejemplo n.º 4
0
class NanpyCharDisplay(CharDisplay):
    """ Nanpy Character Display
        Display messages on a LCD connected to i2c
    """
    """ Properties """
    @property
    def address(self):
        """ Unique id or key """
        return self.config.get('address', 0x27)

    @property
    def type(self):
        """ Returns if using i2c or gpio for connection """
        return self.config.get('type', 'i2c').lower()

    """ Methods """

    def init(self):
        """ Connect to the Parent Device """
        self._state = None
        self._lcd = None
        return True

    def check_connection(self):
        """ Check connection to node and lcd """
        if self.node.connected:
            if not self._lcd:
                if self.type == 'i2c':
                    # PCF I2C Backpack
                    # [lcd_Addr, enable, Rw, Rs, d4, d5, d6, d7, backlighPin, pol]
                    pins = [0x27, 2, 1, 0, 4, 5, 6, 7, 3, 0]
                    # TODO: Add other backback support
                    self._lcd = Lcd_I2C(pins, [self.columns, self.rows],
                                        connection=self.node.connection)
                else:
                    # GPIO Connection
                    # [rs, enable, d4, d5, d6, d7]
                    pins = [
                        self.config.get('rs_pin', 7),
                        self.config.get('enable_pin', 8),
                        self.config.get('pin_1', 9),
                        self.config.get('pin_2', 10),
                        self.config.get('pin_3', 11),
                        self.config.get('pin_4', 12)
                    ]
                    self._lcd = Lcd(pins, [self.columns, self.rows],
                                    connection=connection)
        else:
            self._lcd = None

    def update(self):
        """ Control LCD display nanpy"""
        if self.node.connected:
            try:
                self.check_connection()
                super().update()
            except (SerialManagerError, SocketManagerError, BrokenPipeError,
                    ConnectionResetError, OSError, socket.timeout) as e:
                if self.node.connected:
                    Logger.log_formatted(
                        LOG_LEVEL["warning"],
                        f'{self.node.key} -> Broken Connection', 'Timeout',
                        'notice')
                    self.node.reset_connection()
                self._lcd = None
        return None

    """ Actions """

    def clear(self, data=None):
        """ Clear the display screen """
        self._lcd.clear()
        Logger.log(LOG_LEVEL["debug"], 'Cleared the LCD Screen')

    def show(self, data={}):
        """ Show a message on the display """
        if not isinstance(data, dict):
            data = {'message': data}

        self._lcd.setCursor(0, 0)
        self._lcd.printString(data.get('message', ''))

    def turn_on_backlight(self):
        """ Turn the backlight on """
        self._lcd.setBacklight(0)

    def turn_off_backlight(self):
        """ Turn the backlight on """
        self._lcd.setBacklight(1)
Ejemplo n.º 5
0
#!/usr/bin/env python

from nanpy.lcd import Lcd


if __name__ == '__main__':

    pins = [7, 8, 9, 10, 11, 12]
    cols, rows = 16, 2
    lcd = Lcd(pins, [cols, rows])
    
    smiley = [
        0b00000,
        0b10001,
        0b00000,
        0b00000,
        0b10001,
        0b01110,
        0b00000,
        0b00000
    ]

    lcd.createChar(0,smiley)
    lcd.setCursor(0,0)
    lcd.write(0)
Ejemplo n.º 6
0
#!/usr/bin/env python

import time

from nanpy import SerialManager
from nanpy.lcd import Lcd


if __name__ == '__main__':

    connection = SerialManager(sleep_after_connect=2)

    cols, rows = 16, 2

    pins = [7, 8, 9, 10, 11, 12]
    lcd = Lcd(pins, [cols, rows], connection=connection)

    while True:

        lcd.setCursor(0, 0);

        for char in range(10):
            lcd.printString(char)
            time.sleep(0.5)

        lcd.setCursor(16, 1)
        lcd.autoscroll()

        for char in range(10):
            lcd.printString(char)
            time.sleep(0.5)
Ejemplo n.º 7
0
#!/usr/bin/env python

import time

from nanpy import SerialManager
from nanpy.lcd import Lcd

if __name__ == '__main__':

    connection = SerialManager(sleep_after_connect=2)

    cols, rows = 16, 2

    pins = [7, 8, 9, 10, 11, 12]
    lcd = Lcd(pins, [cols, rows], connection=connection)

    while True:

        lcd.setCursor(0, 0)

        for char in range(10):
            lcd.printString(char)
            time.sleep(0.5)

        lcd.setCursor(16, 1)
        lcd.autoscroll()

        for char in range(10):
            lcd.printString(char)
            time.sleep(0.5)