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 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')
#!/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)