def __init__(self): self.lcd = CharLCD(cols=16, rows=2, pin_rs=16, pin_e=36, pins_data=[38, 32, 11, 37], numbering_mode=GPIO.BOARD)
def run(self): #This is so that the light works GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) userLightColor = 3 if self.author in self.users: userLightColor = self.users[self.author] GPIO.setup(userLightColor, GPIO.OUT) GPIO.output(userLightColor, True) #this is the lcd stuff lcd = CharLCD(cols=16, rows=2, pin_rs=22, pin_e=18, pins_data=[16, 11, 12, 15], numbering_mode=GPIO.BOARD) lcd.cursor_pos = (1, 0) lcd.write_string(self.author) for i in range(0, 2): currentPositionLCD = 0 for char in self.message: lcd.cursor_pos = (0, currentPositionLCD) #increasing the cursor position currentPositionLCD += 1 currentPositionLCD = currentPositionLCD % 16 lcd.write_string(char) time.sleep(.1) time.sleep(.5) GPIO.output(userLightColor, False) lcd.clear()
def __init__(self): self.lcd = CharLCD(pin_rs=15, pin_rw=18, pin_e=16, pins_data=[21, 22, 23, 24], numbering_mode=GPIO.BOARD) self._create_chars()
def clear(self): lcd = CharLCD(pin_rs=22, pin_rw=24, pin_e=23, pins_data=[21, 16, 12, 20], numbering_mode=GPIO.BCM, cols=16, rows=2, dotsize=8, charmap='A02', auto_linebreaks=True) lcd.clear()
def initLCD(): lcd = CharLCD(pin_rs=26, pin_e=19, pins_data=[13, 6, 5, 11], numbering_mode=GPIO.BCM, cols=16, rows=2) lcd.cursor_mode = 'hide'
def __init__(self): print("Init LCD...") self.lcd = CharLCD(numbering_mode=GPIO.BOARD, cols=16, rows=2, pin_rs=37, pin_e=35, pins_data=[33, 31, 29, 23])
def display(self, message): lcd = CharLCD(pin_rs=22, pin_rw=24, pin_e=23, pins_data=[21, 16, 12, 20], numbering_mode=GPIO.BCM, cols=16, rows=2, dotsize=8, charmap='A02', auto_linebreaks=True) lcd.write_string(message)
def __init__(self): # Configure the LCD self.lcd = CharLCD(pin_rs=38, pin_rw=None, pin_e=40, pins_data=[36, 18, 16, 12], numbering_mode=GPIO.BOARD, auto_linebreaks=False, cols=COLS, rows=ROWS)
def initialize(): try: GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) global lcd lcd = CharLCD(cols=16, rows=2, pin_rs=cfg.pins["lcd"]["rs"], pin_e=cfg.pins["lcd"]["e"], pins_data=[cfg.pins["lcd"]["d4"], cfg.pins["lcd"]["d5"], cfg.pins["lcd"]["d6"], cfg.pins["lcd"]["d7"]], numbering_mode=GPIO.BCM) lcd.clear() time.sleep(0.01) print("LCD successfully initialized.") except: print("ERROR: While initializing the LCD.")
def __init__(self): self.lcd = CharLCD(pin_rs=16, pin_rw=None, pin_e=20, pins_data=[26, 19, 13, 6], numbering_mode=GPIO.BCM, rows=2, cols=16) #self.lcd.write_string(u"Hello") #self.lcd = CharLCD (pin_rs=36, pin_rw=None, pin_e=38, pins_data=[31, 33, 35, 37], numbering_mode=GPIO.BOARD, rows=2, cols=16) self.lcd.cursor_mode = "hide"
def __init__(self, write_queue): super().__init__() self.write_queue = write_queue self.strings_to_write = ['', ''] self.changed = multiprocessing.Value(c_bool, True) self.lcd = CharLCD(pin_rs=18, pin_rw=None, pin_e=23, pins_data=[12, 16, 20, 21], numbering_mode=GPIO.BCM, cols=16, rows=2, auto_linebreaks=False) self.lock = Lock() self.lcd.cursor_mode = 'hide' self.watch_queue = Thread(target=self.update_to_write, args=(self.changed, self.lock))
def test_send2(mocker, charlcd_kwargs): """ test gpio's send """ lcd = CharLCD(**charlcd_kwargs) output = mocker.patch("RPi.GPIO.output") lcd._send(4,1) output_calls = [c[0] for c in output.call_args_list] #assert GPIO.input(lcd.pins.rs)==1 #assert GPIO.input(lcd.pins.rw)==0 assert output_calls[0]==(lcd.pins.rs,1) assert output_calls[1]==(lcd.pins.rw,0)
def test_gpio_pulse(mocker, charlcd_kwargs): """ test gpio's init_connection """ lcd = CharLCD(**charlcd_kwargs) output = mocker.patch("RPi.GPIO.output") lcd._pulse_enable() assert output.call_count== 3 output_calls = [c[0] for c in output.call_args_list] assert output_calls[0]==(lcd.pins.e,0) assert output_calls[1]==(lcd.pins.e,1) assert output_calls[2]==(lcd.pins.e,0)
def __init__(self, lcd_rs, lcd_e, lcd_data, buzzer_pin, red_led_pin, yellow_led_pin, green_led_pin, button_pins, fm_username: str, fm_key: str, spot_client: str, spot_secret: str, spot_refresh: str): self.lcd = CharLCD(numbering_mode=GPIO.BCM, cols=lcd_width, rows=2, pin_rs=lcd_rs, pin_e=lcd_e, pins_data=lcd_data, auto_linebreaks=True) self.lcd.cursor_mode = 'hide' self.leds = TrafficLights(red=red_led_pin, yellow=yellow_led_pin, green=green_led_pin, pwm=True) self.buzzer = TonalBuzzer(buzzer_pin) self.buzzer_lock = Lock() self.notif_button = Button(button_pins[0]) self.notif_button.when_activated = self.handle_notif_click self.button2 = Button(button_pins[1]) self.button2.when_activated = lambda: self.queue_text('hey', 'hey') self.button3 = Button(button_pins[2]) self.button4 = Button(button_pins[3]) self.button4.when_held = self.handle_network_hold self.location = DisplayLocation.home self.pulled_idle_text = dict() self.notification_queue = Queue() self.display_queue = Queue() self.display_thread = Thread(target=self.display_worker, name='display', daemon=True) self.network_active = True self.rsession = Session() self.fmnet = FMNetwork(username=fm_username, api_key=fm_key) self.spotnet = SpotNetwork( NetworkUser(client_id=spot_client, client_secret=spot_secret, refresh_token=spot_refresh)).refresh_access_token() self.network_pull_thread = Thread(target=self.network_pull_worker, name='puller', daemon=True)
def test_gpio_write4bits(mocker,charlcd_kwargs): """ test gpio's write4bits """ lcd = CharLCD(**charlcd_kwargs) output = mocker.patch("RPi.GPIO.output") lcd._write4bits(14) assert output.call_count== 7 output_calls = [c[0] for c in output.call_args_list] assert output_calls[0]==(lcd.pins[7],0) assert output_calls[1]==(lcd.pins[8],1) assert output_calls[2]==(lcd.pins[9],1) assert output_calls[3]==(lcd.pins[10],1)
def activate(self): self.lcd = CharLCD(pin_rs=16, pin_e=18, pins_data=[11, 12, 13, 15], numbering_mode=GPIO.BOARD, cols=20, rows=4, dotsize=8, charmap='A02', auto_linebreaks=True, pin_backlight=22) self.lcd.clear() GPIO.output(22, GPIO.HIGH) #turns on backlight
class Lcd: def __init__(self): print("Init LCD...") self.lcd = CharLCD(numbering_mode=GPIO.BOARD, cols=16, rows=2, pin_rs=37, pin_e=35, pins_data=[33, 31, 29, 23]) def display(self, output): self.lcd.clear() self.lcd.write_string(output)
def test_caching(mocker, charlcd_kwargs): """ Characters should only be written if they have changed """ lcd = CharLCD(**charlcd_kwargs) send_data = mocker.patch.object(lcd, '_send_data') send_instruction = mocker.patch.object(lcd, '_send_instruction') lcd.write_string('hello') assert send_data.call_count == 5 data_calls = [c[0] for c in send_data.call_args_list] assert data_calls[0] == (104,) assert data_calls[1] == (101,) assert data_calls[2] == (108,) assert data_calls[3] == (108,) assert data_calls[4] == (111,) lcd.home() send_data.reset_mock() send_instruction.reset_mock() lcd.write_string('he77o') assert send_data.call_count == 2 assert send_instruction.call_count == 3 data_calls = [c[0] for c in send_data.call_args_list] instruction_calls = [c[0] for c in send_instruction.call_args_list] assert instruction_calls[0] == (LCD_SETDDRAMADDR | 1,) assert instruction_calls[1] == (LCD_SETDDRAMADDR | 2,) assert data_calls[0] == (55,) assert data_calls[1] == (55,) assert instruction_calls[2] == (LCD_SETDDRAMADDR | 5,)
def test_caching(mocker): """ Characters should only be written if they have changed """ lcd = CharLCD() send = mocker.patch.object(lcd, '_send') lcd.write_string('hello') assert send.call_count == 5 calls = [c[0] for c in send.call_args_list] assert calls[0] == (104, RS_DATA) assert calls[1] == (101, RS_DATA) assert calls[2] == (108, RS_DATA) assert calls[3] == (108, RS_DATA) assert calls[4] == (111, RS_DATA) lcd.home() send.reset_mock() lcd.write_string('he77o') assert send.call_count == 5 calls = [c[0] for c in send.call_args_list] assert calls[0] == (LCD_SETDDRAMADDR | 1, RS_INSTRUCTION) assert calls[1] == (LCD_SETDDRAMADDR | 2, RS_INSTRUCTION) assert calls[2] == (55, RS_DATA) assert calls[3] == (55, RS_DATA) assert calls[4] == (LCD_SETDDRAMADDR | 5, RS_INSTRUCTION)
def distance(affichage=False,console=False,stockage=False): lcd = CharLCD(cols=16, rows=2, pin_rs=37, pin_e=35, pins_data=[33, 31, 29, 23]) #BOARD GPIO_TRIGGER = 40 GPIO_ECHO = 38 GPIO.setup(GPIO_TRIGGER, GPIO.OUT) GPIO.setup(GPIO_ECHO, GPIO.IN) # set Trigger after 0.01ms to LOW time.sleep(0.00001) GPIO.output(GPIO_TRIGGER, False) StartTime = time.time() StopTime = time.time() print(StartTime) print(StartTime) # save StartTime while GPIO.input(GPIO_ECHO) == 0: time.sleep(1) print(GPIO.input(GPIO_ECHO)) StartTime = time.time() # save time of arrival while GPIO.input(GPIO_ECHO) == 1: StopTime = time.time() # time difference between start and arrival TimeElapsed = StopTime - StartTime print(TimeElapsed) # multiply with the sonic speed (34300 cm/s) # and divide by 2, because there and back distance = (TimeElapsed * 34300) / 2 print(distance) return distance
def test_charmap(mocker, charmap, ue): """ The charmap should be used. The "ü" Umlaut should be encoded correctly. """ lcd = CharLCD(charmap=charmap) send = mocker.patch.object(lcd, '_send') text = 'Züri' lcd.write_string(text) assert send.call_count == 4, 'call count was %d' % send.call_count calls = [c[0] for c in send.call_args_list] assert calls[0] == (90, RS_DATA) assert calls[1] == (ue, RS_DATA) assert calls[2] == (114, RS_DATA) assert calls[3] == (105, RS_DATA)
def __init__(self): self.lcd_inst = CharLCDGPIO(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, charmap='A02', auto_linebreaks=True)
def init_lcd(): ''' Create the LCD with BCM pin numberings NOTE: correct pin values must be used ''' return CharLCD(pin_rs=22, pin_rw=24, pin_e=23, pins_data=[9, 25, 11, 8], numbering_mode=GPIO.BCM)
def test_gpio_init_connection(mocker, charlcd_kwargs): """ test gpio's init_connection """ lcd = CharLCD(**charlcd_kwargs) #init_connection = mocker.patch.object(lcd, '_init_connection') output = mocker.patch("RPi.GPIO.output") lcd._init_connection() #assert init_connection.call_count == 1 #assert GPIO.input(lcd.pins.rs)==0 #assert GPIO.input(lcd.pins.e)==0 #assert GPIO.input(lcd.pins.rw)==0 assert output.call_count == 3 output_calls = [c[0] for c in output.call_args_list] assert output_calls[0]==(lcd.pins.rs,0) assert output_calls[1]==(lcd.pins.e,0) assert output_calls[2]==(lcd.pins.rw,0)
def _func(cols, rows, auto_linebreaks): lcd = CharLCD(cols=cols, rows=rows, auto_linebreaks=auto_linebreaks, **charlcd_kwargs) mocker.patch.object(lcd, '_send_data') mocker.patch.object(lcd, '_send_instruction') return lcd
def test_write_simple(mocker, charlcd_kwargs): """ Write "HelloWorld" to the display. """ lcd = CharLCD(**charlcd_kwargs) send_data = mocker.patch.object(lcd, '_send_data') text = 'HelloWorld' lcd.write_string(text) assert send_data.call_count == len(text) calls = [c[0] for c in send_data.call_args_list] assert calls[0] == (72,) assert calls[1] == (101,) assert calls[2] == (108,) assert calls[3] == (108,) assert calls[4] == (111,) assert calls[5] == (87,) assert calls[6] == (111,) assert calls[7] == (114,) assert calls[8] == (108,) assert calls[9] == (100,)
def test_write_simple(mocker): """ Write "HelloWorld" to the display. """ lcd = CharLCD() send = mocker.patch.object(lcd, '_send') text = 'HelloWorld' lcd.write_string(text) assert send.call_count == len(text) calls = [c[0] for c in send.call_args_list] assert calls[0] == (72, RS_DATA) assert calls[1] == (101, RS_DATA) assert calls[2] == (108, RS_DATA) assert calls[3] == (108, RS_DATA) assert calls[4] == (111, RS_DATA) assert calls[5] == (87, RS_DATA) assert calls[6] == (111, RS_DATA) assert calls[7] == (114, RS_DATA) assert calls[8] == (108, RS_DATA) assert calls[9] == (100, RS_DATA)
def test_write_newline(mocker, rows, cols): """ Write text containing CR/LF chars to the display. """ lcd = CharLCD(rows=rows, cols=cols) send = mocker.patch.object(lcd, '_send') text = '\nab\n\rcd' lcd.write_string(text) assert send.call_count == len(text) calls = [c[0] for c in send.call_args_list] assert calls[0] == (0x80 + 0x40, RS_INSTRUCTION), calls assert calls[1] == (97, RS_DATA), calls assert calls[2] == (98, RS_DATA), calls if rows == 2: assert calls[3] == (0x80 + 2, RS_INSTRUCTION), calls assert calls[4] == (0x80 + 0, RS_INSTRUCTION), calls else: assert calls[3] == (0x80 + cols + 2, RS_INSTRUCTION), calls assert calls[4] == (0x80 + cols + 0, RS_INSTRUCTION), calls assert calls[5] == (99, RS_DATA), calls assert calls[6] == (100, RS_DATA), calls
class LCD: line1 = "" line2 = "" def __init__(self): self.lcd = CharLCD(pin_rs=26, pin_e=19, pins_data=[13, 6, 5, 11], numbering_mode=GPIO.BCM) def writeLine1(self, text: str): self.line1 = text self._toDisplay() def writeLine2(self, text: str): self.line2 = text self._toDisplay() def _toDisplay(self): #self.clear() self.lcd.write_string(f"{self.line1}\n{self.line2}") def clear(self): self.lcd.clear() def close(self): self.lcd.close(clear=True)
def test_write_newline(mocker, rows, cols, charlcd_kwargs): """ Write text containing CR/LF chars to the display. """ lcd = CharLCD(rows=rows, cols=cols, **charlcd_kwargs) send_data = mocker.patch.object(lcd, '_send_data') send_instruction = mocker.patch.object(lcd, '_send_instruction') text = '\nab\n\rcd' lcd.write_string(text) assert send_data.call_count + send_instruction.call_count == len(text) data_calls = [c[0] for c in send_data.call_args_list] instruction_calls = [c[0] for c in send_instruction.call_args_list] assert instruction_calls[0] == (0x80 + 0x40,), instruction_calls assert data_calls[0] == (97,), data_calls assert data_calls[1] == (98,), data_calls if rows == 2: assert instruction_calls[1] == (0x80 + 2,), instruction_calls assert instruction_calls[2] == (0x80 + 0,), instruction_calls else: assert instruction_calls[1] == (0x80 + cols + 2,), instruction_calls assert instruction_calls[2] == (0x80 + cols + 0,), instruction_calls assert data_calls[2] == (99,), data_calls assert data_calls[3] == (100,), data_calls
def __init__(self, config): config = config['lcd_manager'] self.dimmer_pin = int(config['dimmer_pin']) GPIO.setup(self.dimmer_pin, GPIO.OUT) self.turn_on_backlight() self.lcd_width = int(config['width']) self.lcd = CharLCD( pin_rs=int(config['rs']), pin_e=int(config['e']), pins_data=[int(y) for y in config['data_pins'].split(",")], auto_linebreaks=True, numbering_mode=GPIO.BCM, cols=self.lcd_width) for foo, bar in zip(range(len(register_char)), register_char): self.lcd.create_char(foo, bar) self.lines = [ TextLine('', self.lcd_width), TextLine('', self.lcd_width) ]
class CommonHardwarePIHD44780GPIO(object): """ Class for interfacing with pi lcd HD44780 """ def __init__(self): self.lcd_inst = CharLCDGPIO(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, charmap='A02', auto_linebreaks=True) def com_hard_pi_hd44780_write(self, lcd_string, x_pos=None, y_pos=None): if x_pos is not None: self.lcd_inst.cursor_pos = (x_pos, y_pos) self.lcd_inst.write_string(lcd_string) def com_hard_pi_hd44780_clear(self): self.lcd_inst.clear() def com_hard_pi_hd44780_close(self, clear_screen=True): self.lcd_inst.close(clear=clear_screen)
thread = threading.Thread(target=listener.output) thread.daemon = True listener.connect() thread.start() listener.run_forever() ''' Only start the client if its called as standalone and not loaded as a module. Parse arguments for host, port or use the defaults ''' if __name__ == '__main__': try: parser = argparse.ArgumentParser() parser.add_argument('-c', '--console', metavar='console', default=False, type=bool, help='If the data should be outputted to console instead') parser.add_argument('-n', '--host', metavar='HOST', default='127.0.0.1', help='the host to connect to') parser.add_argument('-p', '--port', help='the port to connect to', default=9000, type=int) args = parser.parse_args() lcd = None if using_rpi and not args.console: lcd = CharLCD(pin_rs=26, pin_rw=7, pin_e=19, pins_data=[13, 6, 5, 11], numbering_mode=GPIO.BCM, cols=CHARACTERS_PER_LINE, rows=2) else: lcd = ConsoleLCD() lcd.clear() client_init(lcd, args.host, args.port) finally: lcd.clear() if using_rpi: GPIO.cleanup()