def __init__(self): """ Initialize menu """ self.lcd = i2c.CharLCD(i2c_expander, address, port=port, charmap=charmap, cols=cols, rows=rows) # self.lcd.initDisplay() self.clearDisplay() super(self.__class__, self).__init__()
cols = int(options_pop('cols')) rows = int(options_pop('rows')) charmap = options_pop('charmap', 'A00') if lcdmode == 'i2c': if len(sys.argv) < 5: print_usage() # i2c options, pop all required options, pass remaining options to expander_params i2c_expander = options_pop('expander') address = int(options_pop('addr'), 16) port = int(options_pop('port', '1')) try: lcd = i2c.CharLCD(i2c_expander, address, port=port, charmap=charmap, cols=cols, rows=rows, expander_params=options) except IOError: print_usage( 'IOError: Usually caused by the wrong i2c address/port ' 'or device not connected properly') elif lcdmode == 'gpio': if len(sys.argv) < 8: print_usage() # gpio options mode = options_pop('mode') if mode == 'BCM': numbering_mode = GPIO.BCM
) print(' characters, it probably uses the A00 charmap, otherwise A02.') print( 'Note: The I²C address can be found with `i2cdetect 1` from the i2c-tools package.' ) sys.exit(1) # Parse command line parameters if len(sys.argv) < 2: print_usage() if sys.argv[1] == 'i2c': if len(sys.argv) != 4: print_usage() lcd = i2c.CharLCD(int(sys.argv[2], 16), cols=16, rows=2, charmap=sys.argv[3]) elif sys.argv[1] == 'gpio': if len(sys.argv) != 3: print_usage() lcd = gpio.CharLCD(cols=16, rows=2, charmap=sys.argv[2]) else: print_usage() input('Display should be blank. ') lcd.cursor_mode = CursorMode.blink input('The cursor should now blink. ') lcd.cursor_mode = CursorMode.line input('The cursor should now be a line. ')
print(' %s gpio <rows> <cols>' % sys.argv[0]) print('') print( 'Note: The I²C address can be found with `i2cdetect 1` from the i2c-tools package.' ) sys.exit(1) if __name__ == '__main__': if len(sys.argv) < 2: print_usage() if sys.argv[1] == 'i2c': if len(sys.argv) != 5: print_usage() rows, cols = int(sys.argv[3]), int(sys.argv[4]) lcd = i2c.CharLCD(int(sys.argv[2], 16), cols=cols, rows=rows) elif sys.argv[1] == 'gpio': if len(sys.argv) != 4: print_usage() rows, cols = int(sys.argv[2]), int(sys.argv[3]) lcd = i2c.CharLCD(cols=cols, rows=rows) else: print_usage() print('This tool shows the character map of your LCD on the display.') print('Press ctrl+c at any time to abort.\n') page = 0 chars = rows * cols try:
import datetime # constants to initialise the LCD lcdmode = 'i2c' cols = 20 rows = 4 charmap = 'A00' i2c_expander = 'PCF8574' i=60 # Generally 27 is the address;Find yours using: i2cdetect -y 1 address = 0x27 port = 1 # 0 on an older Raspberry Pi # Initialise the LCD lcd = i2c.CharLCD(i2c_expander, address, port=port, charmap=charmap, cols=cols, rows=rows) lcd.clear() lcd.home() lcd.write_string('Flow on 1 here:') lcd.crlf() lcd.write_string('Flow on 2 here:') lcd.crlf() lcd.write_string('----------------') lcd.crlf() lcd.write_string('Countdown:') while i > 0: # Clear the LCD screen #lcd.clear() lcd.home()
##################################################################################3 # Globals backlight = True dim_timer = "" api_url = ("http://" + osAddress + ":" + str(osPort) + "/ja?pw=" + md5hash) dim_timer = Timer(backlight_timeout, dim_backlight) signal.signal(signal.SIGINT, signal_handler) # === Setup the Display === lcd = i2c.CharLCD(i2c_expander=LCD_i2c_expander, address=LCD_i2c_address, port=1, cols=LCD_cols, rows=LCD_rows, dotsize=8, charmap='A02', auto_linebreaks=True, backlight_enabled=True) # Define Custom LCD characters i_wific = (0b00000, 0b00000, 0b00000, 0b00001, 0b00001, 0b00101, 0b00101, 0b10101) # Wifi connected icon i_wifid = (0b00000, 0b10100, 0b01000, 0b10101, 0b00001, 0b00101, 0b00101, 0b10101) # WiFi disconnected icon i_usd = (0b00000, 0b00000, 0b11111, 0b10001, 0b11111, 0b10001, 0b10011, 0b11110 ) # uSD card icon i_rain = (0b00000, 0b00000, 0b00110, 0b01001, 0b11111, 0b00000, 0b10101, 0b10101) # Rain icon i_conn = (0b00000, 0b00000, 0b00111, 0b00011, 0b00101, 0b01000, 0b10000,
## Initialise the LCD lcdmode = 'i2c' # cols = 16 # 16 or 20 rows = 2 # 1, 2 or 4 charmap = 'A00' # A00 or A02 or ST0B dotsize = 8 # 8 or 10 pixel char height i2c_expander = 'PCF8574' # “PCF8574”, “MCP23008”, “MCP23017”. #expander_params={‘gpio_bank’:‘A’} # only for MCP23017 - A or B address = 0x27 # Find using: i2cdetect -y 1 port = 1 # 0 on an older Raspberry Pi try: lcd = i2c.CharLCD(i2c_expander, address, port=port, charmap=charmap, cols=cols, rows=rows, dotsize=dotsize, backlight_enabled=True, auto_linebreaks=True) # False non funziona, true forse causa sovrapposizioni except IOError: logging.critical("Nessun display LCD") ####print("ERRORE: nessun display LCD") raise SystemExit lcd.cursor_mode = 'hide' logging.info("Display OK") ####print("display OK") ## Connect to mpd client
' characters, it probably uses the A00 charmap, otherwise A02.' ) print('') sys.exit(1) # Parse command line parameters if len(sys.argv) < 2: print_usage() if sys.argv[1] == 'i2c': if len(sys.argv) != 7: print_usage() cols, rows = int(sys.argv[4]), int(sys.argv[5]) lcd = i2c.CharLCD(sys.argv[2], int(sys.argv[3], 16), cols=cols, rows=rows, charmap=sys.argv[6]) elif sys.argv[1] == 'gpio': if len(sys.argv) != 4: print_usage() lcd = gpio.CharLCD(cols=cols, rows=rows, charmap=sys.argv[2]) else: print_usage() # Get max column index maxcol = cols - 1 numstr = '' lcd.backlight = True input('Display should be blank. ')
def run(): if len(sys.argv) < 3: print_usage() lcdmode = sys.argv[1] test = sys.argv[2] # Parse options into a dictionary try: options = dict([arg.split('=', 1) for arg in sys.argv[3:]]) except ValueError: print_usage( 'Malformed option detected, must be in the form option=value') # Common options cols = int(options_pop('cols')) rows = int(options_pop('rows')) charmap = options_pop('charmap', 'A00') if lcdmode == 'i2c': from RPLCD import i2c if len(sys.argv) < 5: print_usage() # i2c options, pop all required options, pass remaining options to expander_params i2c_expander = options_pop('expander') address = int(options_pop('addr'), 16) port = int(options_pop('port', '1')) try: lcd = i2c.CharLCD(i2c_expander, address, port=port, charmap=charmap, cols=cols, rows=rows, expander_params=options) except IOError: print_usage( 'IOError: Usually caused by the wrong i2c address/port ' 'or device not connected properly') elif lcdmode == 'gpio': import RPi.GPIO as GPIO from RPLCD import gpio if len(sys.argv) < 8: print_usage() # gpio options mode = options_pop('mode') if mode == 'BCM': numbering_mode = GPIO.BCM elif mode == 'BOARD': numbering_mode = GPIO.BOARD else: print_usage( 'Invalid GPIO numbering mode: %s, must be either BOARD or BCM' % mode) data = options_pop('data') rs = int(options_pop('rs')) e = int(options_pop('e')) rw = options_pop('rw', 'None') rw = None if rw == 'None' else int(rw) bl = options_pop('bl', 'None') bl = None if bl == 'None' else int(bl) # Parse data pins into a list pins_data = {} pins_data = data.split(',') # Convert data pins to int pins_data = [int(pin) for pin in pins_data] lcd = gpio.CharLCD(pin_rs=rs, pin_rw=rw, pin_e=e, pins_data=pins_data, pin_backlight=bl, numbering_mode=numbering_mode, cols=cols, rows=rows, charmap=charmap) elif lcdmode == 'pigpio': from pigpio import pi from RPLCD import pigpio if len(sys.argv) < 7: print_usage() # pigpio options host = options_pop('host') port = options_pop('port') if host == 'None': pi = pi() elif port == 'None': pi = pi(host) else: pi = pi(host, port) data = options_pop('data') rs = int(options_pop('rs')) e = int(options_pop('e')) rw = options_pop('rw', 'None') rw = None if rw == 'None' else int(rw) bl = options_pop('bl', 'None') bl = None if bl == 'None' else int(bl) # Parse data pins into a list pins_data = {} pins_data = data.split(',') # Convert data pins to int pins_data = [int(pin) for pin in pins_data] lcd = pigpio.CharLCD(pi, pin_rs=rs, pin_rw=rw, pin_e=e, pins_data=pins_data, pin_backlight=bl, cols=cols, rows=rows, charmap=charmap) else: print_usage( 'Connection type %s is not supported. Must be either i2c, gpio or pigpio' % lcdmode) # Run selected test if test == 'show_charmap': show_charmap.run(lcd, rows, cols) elif test == 'testsuite': if cols == 20 and rows == 4: testsuite_20x4.run(lcd) elif cols == 16 and rows == 2: testsuite_16x2.run(lcd) else: print_usage('%sx%s displays are not supported in this test.' % (cols, rows)) else: print_usage('Test \'%s\' is not supported.' % test)