def init(self): Logger.log( LOG_LEVEL["info"], 'LCD Display Worker...\t\t\t\033[1;32m Initializing\033[0;0m'. format(**self.config)) # prepare sensor on specified pin self.i2c = busio.I2C(board.SCL, board.SDA) if (self.model): if (self.model.lower() == 'rgb'): self.lcd = character_lcd.Character_LCD_RGB_I2C( self.i2c, self.columns, self.rows, self.address) elif (self.model.lower() == 'pcf'): self.lcd = character_lcd.Character_LCD_I2C( self.i2c, self.columns, self.rows, address=self.address, usingPCF=True) else: self.lcd = character_lcd.Character_LCD_I2C( self.i2c, self.columns, self.rows, self.address) else: self.lcd = character_lcd.Character_LCD_I2C(self.i2c, self.columns, self.rows, self.address) self.lcd.backlight = True self.lcd.clear() self.lcd.message = "MudPi\nGarden Online" time.sleep(2) self.lcd.clear() return
def lcd_init(): lcd_columns = 20 lcd_rows = 4 i2c = busio.I2C(board.SCL, board.SDA) lcd = character_lcd.Character_LCD_I2C(i2c, lcd_columns, lcd_rows) lcd.backlight = True return lcd
def init(self): """ Connect to the display over I2C """ super().init() # Prepare the display i2c connection self.i2c = busio.I2C(board.SCL, board.SDA) if (self.model == 'rgb'): self.lcd = character_lcd.Character_LCD_RGB_I2C( self.i2c, self.columns, self.rows, self.address) elif (self.model == 'pcf'): self.lcd = character_lcd.Character_LCD_I2C(self.i2c, self.columns, self.rows, address=self.address, usingPCF=True) else: self.lcd = character_lcd.Character_LCD_I2C(self.i2c, self.columns, self.rows, self.address) self.turn_on_backlight() self.clear()
def __init__(self): """ Set up hardware connection Sets up connections to the following bus devices over the i2c bus: - Sets up a TCA9548a to handle the high traffic load on the bus - Sets up a 8x8 reed_matrix mapped trough 4 MCP23017 - Sets up a 9x9 led_matrix with the interface LedWrapper which uses a HT16k33 and 1 MCP23017 """ i2c = busio.I2C(board.SCL, board.SDA) tca = adafruit_tca9548a.TCA9548A(i2c, address=0x71) self._perform_safe = SafeDecorator.perform_safe_factory( lambda: setattr(tca.i2c, '_locked', False)) self._lcd = self._perform_safe(lambda: character_lcd.Character_LCD_I2C( tca[6], 16, 2, address=0x27)) self._perform_safe(setattr)(self._lcd, "backlight", True) mcp = [ self._perform_safe(lambda i: MCP23017(tca[i], address=0x20))(i) for i in range(4) ] # Initialize reed matrix for file in range(8): for rank in range(8): pin_id = file if rank % 2 == 0 else 15 - file self._board_reed[file][rank] = self._perform_safe( mcp[rank // 2].get_pin)(pin_id) self._perform_safe(setattr)(self._board_reed[file][rank], "direction", digitalio.Direction.INPUT) self._perform_safe(setattr)(self._board_reed[file][rank], "pull", digitalio.Pull.UP) led_input_mcp = MCP23017(tca[5], address=0x20) # Map output buttons self._buttons = [] for pinId in range(8, 13): self._buttons.append( self._perform_safe(led_input_mcp.get_pin)(pinId)) self._perform_safe(setattr)(self._buttons[-1], "direction", digitalio.Direction.INPUT) self._perform_safe(setattr)(self._buttons[-1], "pull", digitalio.Pull.UP) # Initialize LED matrix self._led_wrapper = LedWrapper(matrix.MatrixBackpack16x8(tca[4]), led_input_mcp, self._perform_safe) self._led_wrapper.clear()
def display_address_privkey(self, address, privkey): # Initialize the board i2c = busio.I2C(board.SCL, board.SDA) cols = 20 rows = 4 lcd = character_lcd.Character_LCD_I2C(i2c, cols, rows) lcd.backlight = True # Prep the address and display, wait N seconds, # then display the private key while True: lcd.clear() address = self.prep_data(address, cols) lcd.message = "Address:\n" + address time.sleep(self.DISPLAY_INTERVAL) lcd.clear() privkey = self.prep_data(privkey, cols) lcd.message = "Private Key (WIF):\n" + privkey time.sleep(self.DISPLAY_INTERVAL)
def _init_lcd(self, lcd_columns, lcd_rows): try: if self._lcd_type is None: raise Exception("No LCD define") i2c = busio.I2C(board.SCL, board.SDA) if self._lcd_type == "sainsmart_charlcd_led": self._lcd = character_lcd_rgb_i2c.Character_LCD_RGB_I2C( i2c, lcd_columns, lcd_rows) self._lcd._mcp.iodira = set_bit(self._lcd._mcp.iodira, 5, 0) # Turn on backlight self._lcd._mcp.gpioa = set_bit(self._lcd._mcp.gpioa, 5, 0) elif self._lcd_type == "adafruit_charlcd_mono": self._lcd = character_lcd_i2c.Character_LCD_I2C( i2c, lcd_columns, lcd_rows) elif self._lcd_type == "adafruit_charlcd_rgb": self._lcd = character_lcd_rgb_i2c.Character_LCD_RGB_I2C( i2c, lcd_columns, lcd_rows) except: self._logger.debug(sys.exc_info())
""" import time import board import busio import adafruit_character_lcd.character_lcd_i2c as character_lcd # Define LCD nr of characters per line and nr of lines. lcd_columns = 16 lcd_rows = 2 # Setup I2C Bus i2c = busio.I2C(board.SCL, board.SDA) # Define lcd in variable lcd = character_lcd.Character_LCD_I2C(i2c, lcd_columns, lcd_rows, 0x21) try: # turn backlight on lcd.backlight = True # Print 2 words lcd.message = "Hello\nWorld!" # Wait 5 seconds time.sleep(5.0) # Show cursor lcd.clear() lcd.cursor = True lcd.message = "Show Cursor!"
"""Simple test for 16x2 character lcd connected to an MCP23008 I2C LCD backpack.""" import time import board import busio import adafruit_character_lcd.character_lcd_i2c as character_lcd # Modify this if you have a different sized Character LCD lcd_columns = 16 lcd_rows = 2 # Initialise I2C bus. i2c = busio.I2C(board.SCL, board.SDA) # Initialise the lcd class lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2, usingPCF=True, address=0x27) # Turn backlight on lcd.backlight = True # Print a two line message lcd.message = "Hello\nCircuitPython" # Wait 5s time.sleep(5) lcd.clear() # Print two line message right to left lcd.text_direction = lcd.RIGHT_TO_LEFT lcd.message = "Hello\nCircuitPython" # Wait 5s time.sleep(5) # Display cursor lcd.clear() lcd.cursor = True
# For the LCD import busio import adafruit_character_lcd.character_lcd_i2c as character_lcd # Modify this if you have a different sized Character LCD lcd_columns = 16 lcd_rows = 2 lcd_address = 0x27 #The i2c address for the LCD backpack in the IDEA center # Initialise I2C bus. i2c = busio.I2C(board.SCL, board.SDA) # Initialise the lcd class lcd = character_lcd.Character_LCD_I2C(i2c, lcd_columns, lcd_rows, False, True, lcd_address) # For the encoder encoder = rotaryio.IncrementalEncoder(board.D2, board.D3) last_position = 0 initialTime = time.monotonic() -0.1 TIC_PER_ROTATION = 20 loopCount = 0 rpm = 0 lst = [] def mathMap(input,minInput,maxInput,minOutput,maxOutput): return (input - minInput)*(maxOutput - minOutput)/(maxInput - minInput) + minOutput
def __init__(self, rows: int, columns: int, rs_pin: DigitalInOut, en_pin: DigitalInOut, d7_pin: DigitalInOut, d6_pin: DigitalInOut, d5_pin: DigitalInOut, d4_pin: DigitalInOut, colour_lcd: bool, i2c_enabled: bool, red_pin: PWMOut = None, green_pin: PWMOut = None, blue_pin: PWMOut = None, backlight_pin: DigitalInOut = None, button_controller: ButtonController = None): """ Create a Display object to simplify LCD operations. The pins need to be specified as following: digitalio.DigitalInOut( board.<PIN> ) For colours: pulseio.PWMOut( board.<PIN> ) If it's a colour LCD, the pins for RED, GREEN and BLUE must be specified. backlight_pin can remain None. If it's a mono LCD, the backlight pin has to be specified. :param rows: Amount of rows on the LCD. :param columns: Amount of columns on the LCD. :param rs_pin: Location where the RS pin is connected on the board. :param en_pin: Location where the EN pin is connected on the board. :param d7_pin: Location where the D7 pin is connected on the board. :param d6_pin: Location where the D6 pin is connected on the board. :param d5_pin: Location where the D5 pin is connected on the board. :param d4_pin: Location where the D4 pin is connected on the board. :param colour_lcd: Whether it's a colour display or not. :param i2c_enabled: Whether the screen has buttons or not. :param red_pin: Location where the RED pin is connected on the board. :param blue_pin: Location where the BLUE pin is connected on the board. :param green_pin: Location where the GREEN pin is connected on the board. :param backlight_pin: Location where the backlight pin is connected on the board. :param button_controller: A Button Controller class. """ # Set a global variable for checking if it's a colour LCD or not. # Then set the colour tuple for a blue screen. self.is_colour_lcd = colour_lcd self.is_i2c = i2c_enabled self.colour = None self.set_colour(0, 0, 100) # Set a global variable with the dimensions self.dimensions = (columns, rows) if self.is_i2c: if self.is_colour_lcd: self.lcd = i2crgb.Character_LCD_RGB_I2C( button_controller.i2c, columns, rows) else: self.lcd = i2cmono.Character_LCD_I2C(button_controller.i2c, columns, rows) else: # Initialise the LCD screen (type depending on the type of screen). if self.is_colour_lcd: self.lcd = charlcd.Character_LCD_RGB(rs_pin, en_pin, d4_pin, d5_pin, d6_pin, d7_pin, columns, rows, red_pin, blue_pin, green_pin) else: self.lcd = charlcd.Character_LCD_Mono(rs_pin, en_pin, d4_pin, d5_pin, d6_pin, d7_pin, columns, rows, backlight_pin)
import board import audiocore import audiopwmio import digitalio #import adafruit_character_lcd.character_lcd as characterlcd #THIS ONE import adafruit_character_lcd.character_lcd_i2c as character_lcd from random import randint import time lcd_columns = 16 lcd_rows = 4 i2c = busio.I2C(board.SCL, board.SDA) lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2) a = audiopwmio.PWMAudioOut(board.SPEAKER) #lcd_rs = digitalio.DigitalInOut(board.D26) #lcd_en = digitalio.DigitalInOut(board.D19) #lcd_d7 = digitalio.DigitalInOut(board.D27) #lcd_d6 = digitalio.DigitalInOut(board.D22) #lcd_d5 = digitalio.DigitalInOut(board.D24) #lcd_d4 = digitalio.DigitalInOut(board.D25) #lcd = characterlcd.Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows) normalAudioFiles = [] drunkAudioFiles = [] audioFiles = []