class LCD: def __init__(self): GPIO.setwarnings(False) self.lcd = CharLCD(numbering_mode=GPIO.BOARD, cols=16, rows=2, pin_rs=40, pin_e=38, pins_data=[36, 37, 35, 33]) self.lcd.cursor_mode = 'hide' self.lcd.create_char(0, full_square) def write(self, code, seconds_remaining): ''' Keyword arguments: code -- the code to be displayed seconds_remaining -- the seconds remaining (max 16) ''' self.clear() # Center code horizontally LCD_WIDTH = 16 lcd_y = (LCD_WIDTH - len(str(code))) // 2 self.lcd.cursor_pos = (0, lcd_y) self.lcd.write_string(code) self.lcd.cursor_pos = (1, 0) self.lcd.write_string(chr(0) * seconds_remaining) def clear(self): self.lcd.clear()
class LcdOutput(object): def __init__(self): self.lcd = CharLCD(pin_rs=3, pin_e=5, pins_data=[18, 22, 7, 13], pin_rw=None, numbering_mode=GPIO.BOARD, cols=16, rows=2, dotsize=8) self.chars = {} def update(self, *lines): with cleared(self.lcd): for i in range(0, len(lines)): self.lcd.cursor_pos = (i, 0) text = self.__replace_custom_chars(lines[i]) self.lcd.write_string(text) def __replace_custom_chars(self, text): for search, replace in self.chars.items(): text = text.replace(search, replace) return text def create(self, new_char): self.lcd.create_char(new_char.code, new_char.bitmap) self.chars[new_char.replacement] = chr(new_char.code) def close(self): self.lcd.close(clear=True)
class LcdDisplayHardware: def __init__(self, width, height): GPIO.setwarnings(False) self.lcd = None self.width = width self.height = height def __initHardware(self): if (self.lcd is None): self.lcd = CharLCD(pin_rs=26, pin_e=24, pins_data=[22, 18, 16, 12], numbering_mode=GPIO.BOARD, cols=self.width, rows=self.height, dotsize=8) def defineCharacter(self, characterNumber, characterDefinition): self.__initHardware() self.lcd.create_char(characterNumber, characterDefinition) def drawLine(self, lineNumber, line): self.__initHardware() self.lcd.cursor_pos = (lineNumber, 0) self.lcd.write_string(line) def drawString(self, lineNumber, columnNumber, line): self.__initHardware() self.lcd.cursor_pos = (lineNumber, columnNumber) self.lcd.write_string(line) def turnDisplay(self, state): LED_ON = 32 GPIO.setup(LED_ON, GPIO.OUT) GPIO.output(LED_ON, state) def setupCharacters(self, characterDefinition): self.__initHardware() for characterNumber in range(0, len(characterDefinition.CustomCharacters)): self.defineCharacter(characterNumber, characterDefinition.CustomCharacters[characterNumber])
def main(): # on lit les sondes # point froid humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 22) # point chaud humidityC, temperatureC = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 27) # on arrondi a 2 chiffres humidity = round(humidity, 2) temperature = round(temperature, 2) humidityC = round(humidityC, 2) temperatureC = round(temperatureC, 2) lcd = CharLCD(cols=16, rows=2, pin_rw=None, pin_rs=7, pin_e=8, pins_data=[25, 24, 23, 18], pin_backlight=13, backlight_enabled=True, numbering_mode=GPIO.BCM) with cleared(lcd): lcd.create_char(2, tete) lcd.create_char(3, corpsbas) lcd.create_char(4, corpshaut) lcd.write_string(unichr(3)) lcd.write_string(unichr(4)) lcd.write_string(unichr(3)) lcd.write_string(unichr(4)) lcd.write_string(unichr(3)) lcd.write_string(unichr(4)) lcd.write_string(unichr(2)) lcd.write_string(u' ') lcd.write_string(unichr(2)) lcd.write_string(unichr(4)) lcd.write_string(unichr(3)) lcd.write_string(unichr(4)) lcd.write_string(unichr(3)) lcd.write_string(unichr(4)) lcd.write_string(unichr(3)) with cursor(lcd, 1, 0): lcd.create_char(1, coeur) lcd.write_string(unichr(1)) lcd.write_string(unichr(1)) lcd.write_string(unichr(1)) lcd.write_string(u' Salut ! ') lcd.write_string(unichr(1)) lcd.write_string(unichr(1)) lcd.write_string(unichr(1)) time.sleep(4) with cleared(lcd): lcd.write_string(u'Point chaud :') with cursor(lcd, 1, 0): lcd.write_string(u' Temp = %s ' % temperatureC) lcd.create_char(0, degres) lcd.write_string(unichr(0)) lcd.write_string(u'C') time.sleep(5) with cleared(lcd): lcd.write_string(u'Point chaud :') with cursor(lcd, 1, 0): lcd.write_string(u' Humi = %s ' % humidityC) lcd.write_string(u'%') time.sleep(5) with cleared(lcd): lcd.write_string(u'Point froid :') with cursor(lcd, 1, 0): lcd.write_string(u' Temp = %s ' % temperature) lcd.create_char(0, degres) lcd.write_string(unichr(0)) lcd.write_string(u'C') time.sleep(5) with cleared(lcd): lcd.write_string(u'Point froid :') with cursor(lcd, 1, 0): lcd.write_string(u' Humi = %s ' % humidity) lcd.write_string(u'%') time.sleep(5) with cleared(lcd): lcd.create_char(2, tete) lcd.create_char(3, corpsbas) lcd.create_char(4, corpshaut) lcd.write_string(unichr(3)) lcd.write_string(unichr(4)) lcd.write_string(unichr(3)) lcd.write_string(unichr(4)) lcd.write_string(unichr(3)) lcd.write_string(unichr(4)) lcd.write_string(unichr(2)) lcd.write_string(u' ') lcd.write_string(unichr(2)) lcd.write_string(unichr(4)) lcd.write_string(unichr(3)) lcd.write_string(unichr(4)) lcd.write_string(unichr(3)) lcd.write_string(unichr(4)) lcd.write_string(unichr(3)) with cursor(lcd, 1, 0): lcd.create_char(1, coeur) lcd.write_string(unichr(1)) lcd.write_string(unichr(1)) lcd.write_string(unichr(1)) lcd.write_string(u' Bye-bye ! ') lcd.write_string(unichr(1)) lcd.write_string(unichr(1)) lcd.write_string(unichr(1)) time.sleep(4) lcd.close(clear=True)
import time import RPi.GPIO as GPIO from RPLCD import CharLCD, cleared, cursor print "" print "Programma python scritto da Michele Lizzit" print "Written by Michele Lizzit" print "Last update 25 Apr 2016" print "" campanella = (0b00100, 0b00100, 0b00100, 0b01110, 0b01110, 0b11111, 0b00100, 0b00000) lcd = CharLCD(pin_rs=19, pin_rw=21, pin_e=3, pins_data=[23, 26, 22, 24], numbering_mode=GPIO.BOARD, cols=20, rows=4, dotsize=8) lcd.create_char(0, campanella) while (1): lcd.clear() lcd.write_string(unichr(0)) lcd.write_string(u'Gestione campanelle') lcd.cursor_pos = (1, 0) timeStr = time.strftime("%H:%M:%S %d/%m") lcd.write_string(timeStr) time.sleep(1)
class LCD_SYS_2: def __init__(self): if gv.IS_DEBIAN: self.thread_sleep = 0.1 else: self.thread_sleep = 0.2 self.timeout_init = 3 # 3 sec self.timeout_init /= self.thread_sleep # Adjust according to while loop sleep time self.timeout = self.timeout_init self.display_called = False if (gv.USE_HD44780_16x2_LCD or gv.USE_HD44780_20x4_LCD or gv.USE_I2C_16X2DISPLAY) and gv.IS_DEBIAN: import lcdcustomchars as lcdcc import RPi.GPIO as GPIO from RPLCD import CharLCD if (gv.USE_HD44780_16x2_LCD or gv.USE_HD44780_20x4_LCD): self.lcd = CharLCD(pin_rs=gv.GPIO_LCD_RS, pin_rw=None, pin_e=gv.GPIO_LCD_E, pins_data=[ gv.GPIO_LCD_D4, gv.GPIO_LCD_D5, gv.GPIO_LCD_D6, gv.GPIO_LCD_D7 ], numbering_mode=GPIO.BCM, cols=gv.LCD_COLS, rows=gv.LCD_ROWS, charmap='A00') elif (gv.USE_I2C_16X2DISPLAY): self.lcd = CharLCD('PCF8574', gv.I2C_16x2DISPLAY_ADDR) self.lcd.create_char(1, lcdcc.block) self.lcd.create_char(2, lcdcc.arrow_right_01) self.lcd.create_char(3, lcdcc.voice_button_on) self.lcd.create_char(4, lcdcc.voice_button_off) if (gv.USE_HD44780_16x2_LCD or gv.USE_HD44780_20x4_LCD) and gv.SYSTEM_MODE == 2: self.STRING_1 = '' self.STRING_2 = '' self.LCDThread = threading.Thread(target=self.lcd_main) self.LCDThread.daemon = True self.LCDThread.start() # time.sleep(0.5) # display('Start SamplerBox') # bug: the way autochorder is loaded causes issue # time.sleep(0.5) def lcd_main(self): if gv.IS_DEBIAN: self.lcd.clear() self.lcd_string("WELCOME TO", 1) self.lcd_string("-=SAMPLERBOX=-", 2) time.sleep(1) while True: if self.display_called: if self.timeout > 0: self.timeout -= 1 else: self.display_called = False self.tempDisplay = False self.lcd_string(self.STRING_1, 1) self.lcd_string(self.STRING_2, 2) time.sleep(self.thread_sleep) def lcd_string(self, message, line): message = message.center(gv.LCD_COLS, " ") if gv.IS_DEBIAN: global lcd lcd._set_cursor_pos((line - 1, 0)) lcd.write_string(message) def display(self, s2): if gv.USE_ALSA_MIXER: s1 = "%s %s %d%% %+d" % ( gv.autochorder.CHORD_NAMES[gv.autochorder.current_chord], gv.sample_mode, gv.global_volume, gv.globaltranspose) else: s1 = "%s %s %+d" % ( gv.autochorder.CHORD_NAMES[gv.autochorder.current_chord], gv.sample_mode, gv.globaltranspose) pass if s2 == "": if gv.currvoice > 1: s2 = str(gv.currvoice) + ":" s2 += str(gv.basename) + str(" " * gv.LCD_COLS) if gv.nav.buttfunc > 0: s2 = s2[:gv.LCD_COLS - 2] + "*" + gv.nav.button_disp[gv.nav.buttfunc] else: s2 = s2 + ' ' * gv.LCD_COLS if gv.PRINT_LCD_MESSAGES: message = "\r%s || %s" % (s1[:gv.LCD_COLS], s2[:gv.LCD_COLS]) # print "display: %s \\ %s" % (s1[:gv.LCD_COLS], s2[:gv.LCD_COLS]) sys.stdout.write(message) sys.stdout.flush() if gv.USE_GUI: gui_message = message.replace('\r', '') gui_message = gui_message.replace(' || ', '\r') gv.gui.output['text'] = gui_message # lcd.message(s1 + " "*8 + "\n" + s2 + " "*15) # if gv.IS_DEBIAN: # lcd.message(s1 + "\n" + s2) self.STRING_1 = str(s1[:gv.LCD_COLS]) # line 1 self.STRING_2 = str(s2[:gv.LCD_COLS]) # line 2 self.timeout = self.timeout_init self.display_called = True
unichr = chr old_time = 0 counter = 0 lcd = CharLCD(cols=16, rows=2) # custom symbols lcd.clear() top_line = (0b11111, 0b11111, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000) bottom_line = (0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b11111, 0b11111) both_lines = (0b11111, 0b11111, 0b00000, 0b00000, 0b00000, 0b00000, 0b11111, 0b11111) dot = (0b00000, 0b00000, 0b00011, 0b00011, 0b00011, 0b00011, 0b00000, 0b00000) lcd.create_char(0, top_line) lcd.create_char(1, bottom_line) lcd.create_char(2, both_lines) lcd.create_char(3, dot) # build big digits def disp_number(number, position): if number=="1" : lcd.cursor_pos = (0, position) lcd.write_string(unichr(0)) lcd.write_string(unichr(255)) lcd.write_string(unichr(254)) lcd.cursor_pos = (1, position) lcd.write_string(unichr(1))
import RPi.GPIO as GPIO from RPLCD import CharLCD #Set up LCD lcd = CharLCD(pin_rs=17, pin_rw=None, pin_e=27, pins_data=[12, 16, 20, 21], numbering_mode=GPIO.BCM, cols=20, rows=4, dotsize=8, auto_linebreaks=True) lcd.create_char( 1, [0b01100, 0b10010, 0b10010, 0b01100, 0b00000, 0b00000, 0b00000, 0b00000]) lcd.create_char( 2, [0b00000, 0b10000, 0b01000, 0b00100, 0b00010, 0b00001, 0b00000, 0b00000]) #Wait for LCD to start up - otherwise you get garbage time.sleep(1) # Set up MySQL Connection SQLHost = '127.0.0.1' SQLUser = '******' SQLPass = '******' SQLDB = 'PiLN' AppDir = '/home/PiLN'
lcd.clear() lcd.cursor_mode = CursorMode.hide lcd.write_string('Paris: 21{deg}C\n\rZ{uuml}rich: 18{deg}C'.format( deg=unichr(176), uuml=unichr(129))) print( 'Text should now show "Paris: 21°C, Zürich: 18°C" without any encoding issues.', end='') input() # Test custom chars lcd.clear() happy = (0b00000, 0b01010, 0b01010, 0b00000, 0b10001, 0b10001, 0b01110, 0b00000) sad = (0b00000, 0b01010, 0b01010, 0b00000, 0b01110, 0b10001, 0b10001, 0b00000) lcd.create_char(0, sad) lcd.write_string(unichr(0)) lcd.create_char(1, happy) lcd.write_string(unichr(1)) input('You should now see a sad and a happy face next to each other. ') lcd.create_char(0, happy) lcd.home() lcd.write_string(unichr(0)) input('Now both faces should be happy. ') lcd.clear() lcd.write_string('1234567890123456\r\n2nd line') input( 'The first line should be filled with numbers, the second line should show "2nd line"' )
# Declare LCD: cols and rows for your lcd, pin_rs = reset pin, pin_e = enable pin, pins_data for 4 bits communication, set pin numeriotation lcd = CharLCD(cols=16, rows=2, pin_rs=37, pin_e=35, pins_data=[33, 31, 29, 23], numbering_mode=GPIO.BOARD) # Turn off gpio warnings while in dev GPIO.setwarnings(False) # Declare the buffer to write on lcd (the buffer must be 16x2 - same as lcd) framebuffer = [ '', '', ] long_string = str(framebuffer[1]) # save in long_string string to write on lcd # Make icons for lcd for index,val in enumerate(icon_bytes): lcd.create_char(index, val) # Function to write the buffer on the screen ( scroll animation of second row is made by deleting and drawing the text each .4s ) def write_to_lcd(lcd, framebuffer, num_cols): lcd.home() for row in framebuffer: lcd.write_string(row.ljust(num_cols)[:num_cols]) lcd.write_string('\r\n') # Function which makes scroll effect def loop_string(string, lcd, framebuffer, row, num_cols, delay=0.4): #DELAY= CONTROLS THE SPEED OF SCROLL padding = ' ' * num_cols s = padding + string + padding for i in range(len(s) - num_cols + 1):
0b01010, 0b01010, 0b10001, 0b10001, 0b10001, 0b01110, ) temp = ( 0b00100, 0b01010, 0b01010, 0b01110, 0b01110, 0b11111, 0b11111, 0b01110, ) lcd.create_char(0, omega) lcd.create_char(1, pi) lcd.create_char(2, mu) lcd.create_char(3, drop) lcd.create_char(4, temp) lcd.write_string(unichr(0)) lcd.write_string(unichr(1)) lcd.write_string(unichr(2)) lcd.write_string(unichr(3)) lcd.write_string(unichr(4))
class radio: def __init__(self): # Settings. Get from config file # self.Frequency = 434.250 self.Modes = [{ 'label': 'USB', 'frequency': 434.250, 'largestep': 0.1, 'smallstep': 0.0005 }, { 'label': 'LSB', 'frequency': 434.250, 'largestep': 0.1, 'smallstep': 0.0005 }, { 'label': 'AM', 'frequency': 20.0, 'largestep': 1.0, 'smallstep': 0.1 }, { 'label': 'FM', 'frequency': 434.250, 'largestep': 0.1, 'smallstep': 0.025 }, { 'label': 'WFM', 'frequency': 90.2, 'largestep': 0.1, 'smallstep': 0.0005 }, { 'label': 'APRS', 'frequency': 434.250, 'largestep': 0, 'smallstep': 0 }] self.APRSModes = [{ 'label': 'US', 'frequency': 144.390 }, { 'label': 'NZ', 'frequency': 144.575 }, { 'label': 'JP', 'frequency': 144.660 }, { 'label': 'EU', 'frequency': 144.800 }, { 'label': 'AR', 'frequency': 144.930 }, { 'label': 'AU', 'frequency': 145.175 }, { 'label': 'BR', 'frequency': 145.570 }] # self.Frequency = 90.8 self.SmallStep = 0.1 self.LargeStep = 1 self.Mode = 0 self.APRSMode = 0 self.LargeSteps = False self.Volume = 80 self.DataEntry = '' self.ModePressed = False # LCD self.lcd = CharLCD(pin_rs=21, pin_e=20, pins_data=[26, 19, 13, 6], numbering_mode=GPIO.BCM, cols=16, rows=2, dotsize=8, auto_linebreaks=True, pin_backlight=None, backlight_enabled=True, backlight_mode=BacklightMode.active_low) # pin_rw=... (not using this pin) for j in range(6): bar = [] mask = 0 for i in range(j): mask = mask | (1 << (4 - i)) for i in range(8): value = ((1 << (i - 2)) - 1 if i > 2 else 0) & mask bar = bar + [value] self.lcd.create_char(j, bar) # Dials self.f_dial = rotary_encoder(12, 16, 5, self.f_up, self.f_down, self.f_press) self.v_dial = rotary_encoder(8, 7, 1, self.v_up, self.v_down, self.v_press) # Keypad pad = keypad([0, 11, 9, 10], [22, 27, 17], self.key_press) # SDR self.sdr = rtl_sdr() # Set default mode, frequency, volume etc self.set_frequency(self.Modes[self.Mode]['frequency']) self.set_volume(self.Volume) self.set_data_entry('') self.set_mode(0) def show_frequency(self): self.lcd.cursor_pos = (0, 0) self.lcd.write_string(" " * 11) self.lcd.cursor_pos = (0, 0) self.lcd.write_string("%8.4fMHz" % self.Modes[self.Mode]['frequency']) def set_frequency(self, new_frequency): self.Modes[self.Mode]['frequency'] = new_frequency self.sdr.set_frequency(self.Modes[self.Mode]['frequency']) self.show_frequency() def set_frequency_for_mode(self): if self.Modes[self.Mode]['label'] == 'APRS': frequency = self.APRSModes[self.APRSMode]['frequency'] else: frequency = self.Modes[self.Mode]['frequency'] self.set_frequency(frequency) def set_volume(self, new_volume): self.Volume = min(max(0, new_volume), 100) os.system("amixer cset numid=1 -- " + str(self.Volume) + "% > /dev/null") # self.lcd.cursor_pos = (1, 0) # self.lcd.write_string("Vol " + str(self.Volume) + " ") def show_mode(self): ModeString = self.Modes[self.Mode]['label'].rjust(4) self.lcd.cursor_pos = (0, 12) self.lcd.write_string(ModeString) def set_mode(self, mode): if mode < 0: self.Mode = len(self.Modes) - 1 elif mode >= len(self.Modes): self.Mode = 0 else: self.Mode = mode self.show_mode() self.set_frequency_for_mode() def set_data_entry(self, line): self.DataEntry = line self.lcd.cursor_pos = (1, 0) self.lcd.write_string(" " * 16) if line == '': self.lcd.cursor_mode = CursorMode.hide else: self.lcd.cursor_pos = (1, 0) self.lcd.cursor_mode = CursorMode.blink self.lcd.write_string(line) def cancel_data_entry(self): self.set_data_entry('') def cancel_setting(self): self.set_data_entry('') self.lcd.cursor_pos = (1, 0) self.lcd.write_string(" " * 16) def key_press(self, key): if key == '*': self.cancel_data_entry() elif key == '#': self.set_frequency(float(self.DataEntry)) self.set_data_entry('') else: if len(self.DataEntry) == 2: self.set_data_entry(self.DataEntry + key + '.') else: self.set_data_entry(self.DataEntry + key) def f_down(self): self.set_frequency(self.Modes[self.Mode]['frequency'] - ( self.LargeStep if self.LargeSteps else self.SmallStep)) def f_up(self): self.set_frequency(self.Modes[self.Mode]['frequency'] + ( self.LargeStep if self.LargeSteps else self.SmallStep)) def f_press(self): self.LargeSteps = not self.LargeSteps def v_down(self): if self.ModePressed: self.set_mode(self.Mode - 1) else: self.set_volume(self.Volume - 5) def v_up(self): if self.ModePressed: self.set_mode(self.Mode + 1) else: self.set_volume(self.Volume + 5) def v_press(self): self.ModePressed = not self.ModePressed self.cancel_data_entry() if self.ModePressed: self.lcd.cursor_pos = (1, 0) self.lcd.write_string("*Selecting Mode*") else: self.cancel_setting() self.show_frequency()
return ip_add # init gpio GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.setup(PIN_GPIO, GPIO.IN, pull_up_down = GPIO.PUD_UP) # init LCD lcd = CharLCD(cols=16, rows=2) # create custom chars :) and :(, block and ° happy = (0b00000, 0b01010, 0b01010, 0b00000, 0b10001, 0b10001, 0b01110, 0b00000) sad = (0b00000, 0b01010, 0b01010, 0b00000, 0b01110, 0b10001, 0b10001, 0b00000) block = (0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111) degr = (0b01110, 0b01010, 0b01110, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000) lcd.create_char(0, sad) lcd.create_char(1, happy) lcd.create_char(2, block) lcd.create_char(3, degr) # endless loop while True: count = 0 lcd.clear() lcd.write_string(_get_time()) lcd.cursor_pos = (1, 0) # put smiley indicator if connected to the internet if _is_connected() == True: lcd.write_string(_get_ip()) lcd.cursor_pos = (1, 15)
import RPi.GPIO as GPIO from RPLCD import CharLCD import time GPIO.setmode(GPIO.BOARD) lcd = CharLCD(cols=16, rows=2, pin_rs=37, pin_e=35, pins_data=[33, 31, 29, 23], numbering_mode=GPIO.BOARD) backslash = (0b00000, 0b10000, 0b01000, 0b00100, 0b00010, 0b00001, 0b00000, 0b00000) lcd.create_char(0, backslash) gaming_animation = [ ' o_ _o /\x00 GAMING /\x00', ' o_. _o /\x00 GAMING /\x00', ' o_ . _o /\x00 GAMING /\x00', ' o_ . _o /\x00 GAMING /\x00', ' o_ . _o /\x00 GAMING /\x00', ' o_ . _o /\x00 GAMING /\x00', ' o_ _* /\x00 GAMING /\x00', ' o_ _\\ /\x00 GAMING /\x00', '\x00o/ /\x00 YEAH >->o', '\x00o/ /\x00 YEAH! >->o', '\x00o/ /\x00 !YEAH! >->o' ]
class LCD_SYS_1: def __init__(self): if gv.SYSTEM_MODE == 1 and (gv.USE_HD44780_16x2_LCD or gv.USE_HD44780_20x4_LCD): # Timing constants self.E_PULSE = 0.0005 self.E_DELAY = 0.0005 self.display_called = False self.temp_display = False if gv.IS_DEBIAN: self.thread_sleep = 0.05 else: self.thread_sleep = 0.1 self.timeout_init = 2 # default timeout reset time self.timeout_length = self.timeout_init # initial timeout length (timeout_custom will override) self.STRING_1 = '' self.STRING_2 = '' self.STRING_3 = '' self.STRING_4 = '' self.STRING_1_PRIORITY = '' self.STRING_2_PRIORITY = '' self.STRING_3_PRIORITY = '' self.STRING_4_PRIORITY = '' self.loop_alive = True if gv.IS_DEBIAN: import RPi.GPIO as GPIO from RPLCD import CharLCD self.lcd = CharLCD(pin_rs=gv.GPIO_LCD_RS, pin_rw=None, pin_e=gv.GPIO_LCD_E, pins_data=[gv.GPIO_LCD_D4, gv.GPIO_LCD_D5, gv.GPIO_LCD_D6, gv.GPIO_LCD_D7], numbering_mode=GPIO.BCM, cols=gv.LCD_COLS, rows=gv.LCD_ROWS, charmap='A00') self.lcd.clear() # Hide the cursor self.lcd._set_cursor_mode("hide") # Fill the display with blank spaces for i in range(1, gv.LCD_ROWS+1): self.lcd_string(' ', i) # Write custom codes to the LCD self.lcd.create_char(1, lcdcc.block) self.lcd.create_char(2, lcdcc.pause) self.lcd.create_char(3, lcdcc.voice_button_on) self.lcd.create_char(4, lcdcc.voice_button_off) self.lcd.create_char(5, lcdcc.block2) self.lcd.create_char(6, lcdcc.loading_hour_glass) self.LCDThread = threading.Thread(target=self.lcd_main) self.LCDThread.daemon = True self.LCDThread.start() def reset_after_timeout(self): self.display_called = False self.temp_display = False self.timeout_start = time.time() def lcd_main(self): if gv.USE_HD44780_20x4_LCD and gv.IS_DEBIAN: self.lcd.clear() # if gv.USE_HD44780_16x2_LCD: # self.lcd_string("WELCOME TO".center(gv.LCD_COLS, ' '), 1) # self.lcd_string("SAMPLERBOX".center(gv.LCD_COLS, ' '), 2) # elif gv.USE_HD44780_20x4_LCD: # self.lcd_string(unichr(1) * gv.LCD_COLS, 1) # self.lcd_string("WELCOME TO".center(gv.LCD_COLS, ' '), 2) # self.lcd_string("SAMPLERBOX".center(gv.LCD_COLS, ' '), 3) # self.lcd_string(unichr(1) * gv.LCD_COLS, 4) # time.sleep(0.6) self.timeout_start = time.time() print_message = '' while self.loop_alive: if self.display_called: now = time.time() if (now - self.timeout_start) > self.timeout_length: self.reset_after_timeout() if (self.temp_display or gv.displayer.menu_mode == gv.displayer.DISP_UTILS_MODE): self.lcd_string(self.STRING_1, 1) self.lcd_string(self.STRING_2, 2) print_message = "\r%s||%s" % (self.STRING_1[:gv.LCD_COLS], self.STRING_2[:gv.LCD_COLS]) if gv.USE_HD44780_20x4_LCD: self.lcd_string(self.STRING_3, 3) self.lcd_string(self.STRING_4, 4) print_message = "\r%s||%s||%s" % (print_message, self.STRING_3[:gv.LCD_COLS], self.STRING_4[:gv.LCD_COLS]) elif gv.displayer.menu_mode == gv.displayer.DISP_PRESET_MODE: self.lcd_string(self.STRING_1_PRIORITY, 1) self.lcd_string(self.STRING_2_PRIORITY, 2) print_message = "\r%s||%s" % (self.STRING_1_PRIORITY[:gv.LCD_COLS], self.STRING_2_PRIORITY[:gv.LCD_COLS]) if gv.USE_HD44780_20x4_LCD: self.lcd_string(self.STRING_3_PRIORITY, 3) self.lcd_string(self.STRING_4_PRIORITY, 4) print_message = "\r%s||%s||%s" % (print_message, self.STRING_3_PRIORITY[:gv.LCD_COLS], self.STRING_4_PRIORITY[:gv.LCD_COLS]) elif gv.displayer.menu_mode == gv.displayer.DISP_MENU_MODE: self.lcd_string(self.STRING_1_PRIORITY, 1) self.lcd_string(self.STRING_2_PRIORITY, 2) print_message = "\r%s||%s" % (self.STRING_1_PRIORITY[:gv.LCD_COLS], self.STRING_2_PRIORITY[:gv.LCD_COLS]) if gv.USE_HD44780_20x4_LCD: self.lcd_string(self.STRING_3_PRIORITY, 3) self.lcd_string(self.STRING_4_PRIORITY, 4) print_message = "\r%s||%s||%s" % (print_message, self.STRING_3_PRIORITY[:gv.LCD_COLS], self.STRING_4_PRIORITY[:gv.LCD_COLS]) if gv.PRINT_LCD_MESSAGES: sys.stdout.write(print_message) sys.stdout.flush() gui_message = print_message.replace('\r', '') gui_message = gui_message.replace('||', '\r') if gv.USE_GUI and not gv.IS_DEBIAN: gv.gui.output['text'] = gui_message time.sleep(self.thread_sleep) def lcd_string(self, message, line): message = message[:gv.LCD_COLS] message = message.ljust(gv.LCD_COLS, " ") if (gv.USE_HD44780_16x2_LCD or gv.USE_HD44780_20x4_LCD) and gv.IS_DEBIAN: self.lcd.write_string(message[:gv.LCD_COLS]) def display(self, message, line=1, is_priority=False, timeout_custom=None): message += ' ' * gv.LCD_COLS # Send string to display if line == 1: self.STRING_1 = message if is_priority: self.STRING_1_PRIORITY = message else: self.temp_display = True if line == 2: self.STRING_2 = message if is_priority: self.STRING_2_PRIORITY = message else: self.temp_display = True if line == 3: self.STRING_3 = message if is_priority: self.STRING_3_PRIORITY = message else: self.temp_display = True if line == 4: self.STRING_4 = message if is_priority: self.STRING_4_PRIORITY = message else: self.temp_display = True if timeout_custom != None: self.timeout_length = timeout_custom else: self.timeout_length = self.timeout_init self.timeout_start = time.time() self.display_called = True def stop(self): self.lcd.close() self.loop_alive = False
import RPi.GPIO as GPIO from RPLCD import CharLCD, cleared, cursor from time import sleep # Auspex LCD for Warhammer 40,000 Victory Point and Turn Tracking # wired as here: https://github.com/dbrgn/RPLCD # Initialize display. All values have default values and are therefore optional. lcd = CharLCD(pin_rs=15, pin_rw=18, pin_e=16, pins_data=[21, 22, 23, 24], numbering_mode=GPIO.BOARD, cols=20, rows=4, dotsize=8) # create the aquila characters aquila0 = (0b01111,0b00011,0b00001,0b00000,0b00000,0b00000,0b00000,0b00000) lcd.create_char(0,aquila0) aquila1 = (0b11101,0b11000,0b11111,0b11111,0b01101,0b00001,0b00011,0b00010) lcd.create_char(1,aquila1) aquila2 = (0b01011,0b10001,0b11111,0b11111,0b11011,0b11000,0b11100,0b10100) lcd.create_char(2,aquila2) aquila3 = (0b11111,0b11100,0b11000,0b10000,0b00000,0b00000,0b00000,0b00000) lcd.create_char(3,aquila3) # prep the LCD lcd.clear() lcd.home() with cursor(lcd, 0, 2): lcd.write_string('AUSPEX 410014.M2') # test github editor for spaces # OK it worked
0b00000, 0b00000 ) a5 = ( 0b11111, 0b11111, 0b11111, 0b11111, 0b00000, 0b00000, 0b00000, 0b00000 ) lcd.create_char(0, a0) lcd.create_char(1, a1) lcd.create_char(2, a2) lcd.create_char(3, a3) lcd.create_char(4, a4) lcd.create_char(5, a5) d0 = ( (0, 2, 1), (0b11111111,0b11111110,0b11111111), (0b11111111,0b11111110,0b11111111), (3,5,4) ); d1 = (
from RPLCD import CharLCD, cleared, cursor lcd = CharLCD(cols=16, rows=2, pin_rs=37, pin_e=35, pins_data=[33, 31, 29, 23]) smiley = ( 0b00000, 0b00000, 0b01010, 0b00000, 0b10001, 0b01010, 0b00100, 0b00000, ) lcd.create_char(0, smiley) lcd.write_string(unichr(0))
0b00100, 0b10101, 0b01110, 0b01110, 0b00100) dg = ( 0b01100, 0b10010, 0b10010, 0b01100, 0b00000, 0b00000, 0b00000, 0b00000) lcd.create_char(0, up) lcd.create_char(1, dn) lcd.create_char(2, dg) def main(): lcd.write_string("WELCOME BACK !!! ") time.sleep(3) while (True): # main: read tempeatures, save to file, save contents of file to SQL try: lcd.clear() lcd.write_string("fetching data...") dbs = GetDataBySensor()
lcd.clear() lcd.write_string('This will wrap around both lines') input('Text should nicely wrap around lines. ') lcd.clear() lcd.cursor_mode = CursorMode.hide lcd.write_string('Paris: 21{deg}C\n\rZ{uuml}rich: 18{deg}C'.format(deg=unichr(176), uuml=unichr(129))) print('Text should now show "Paris: 21°C, Zürich: 18°C" without any encoding issues.', end='') input() # Test custom chars lcd.clear() happy = (0b00000, 0b01010, 0b01010, 0b00000, 0b10001, 0b10001, 0b01110, 0b00000) sad = (0b00000, 0b01010, 0b01010, 0b00000, 0b01110, 0b10001, 0b10001, 0b00000) lcd.create_char(0, sad) lcd.write_string(unichr(0)) lcd.create_char(1, happy) lcd.write_string(unichr(1)) input('You should now see a sad and a happy face next to each other. ') lcd.create_char(0, happy) lcd.home() lcd.write_string(unichr(0)) input('Now both faces should be happy. ') lcd.clear() lcd.write_string('1234567890123456\r\n2nd line') input('The first line should be filled with numbers, the second line should show "2nd line"') lcd.clear() lcd.write_string('999456\n\r\n123')
0b00100, 0b00000, ) same = ( 0b00000, 0b11111, 0b11111, 0b00000, 0b00000, 0b11111, 0b11111, 0b00000, ) lcd.create_char(0, up1) lcd.create_char(1, down) lcd.create_char(2, same) def main(): # Main program block GPIO.setwarnings(False) lcd.write_string(unichr(0)) lcd.write_string(unichr(1)) lcd.write_string(unichr(2)) time.sleep(25) if __name__ == '__main__': try: main()