Esempio n. 1
0
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)
Esempio n. 2
0
def main():
    # initialize lcd screen
    lcd = CharLCD(cols=16,
                  rows=2,
                  pin_rs=37,
                  pin_e=35,
                  pins_data=[33, 31, 29, 23])

    # DHT22 sensor is only accurate to +/- 2% humidity and +/- 0.5 celsius
    # Poll 10 times and calculate median to get more accurate value
    templist = []
    humidlist = []

    lcd.cursor_pos = (0, 0)
    lcd.write_string("Polling...")
    lcd.cursor_pos = (1, 0)
    bar = "[----------]"
    lcd.write_string(bar)
    lcd.clear()

    for i in range(1, 11):
        data = poll()

        lcd.cursor_pos = (0, 0)
        lcd.write_string("Polling....")
        lcd.cursor_pos = (1, 0)

        bar = list(bar)
        bar[i] = '#'
        bar = ''.join(bar)
        lcd.write_string(bar)

        # Don't poll more often than every 2 seconds
        sleep(3)
        lcd.clear()
        temp = int(round(data[0]))
        humid = int(round(data[1]))
        templist.append(temp)
        humidlist.append(humid)

    lcd.clear()

    # Calculate median value
    temp = (sorted(templist))[5]
    humid = (sorted(humidlist))[5]

    # Display results to LCD
    display(lcd, temp, humid)

    # Write data to CSV file for later analysis
    write_data(temp, humid)

    # Clears the screen / resets cursor position and closes connection
    lcd.clear()
    lcd.close(clear=True)
class Display(SensorListener, SwitchListener):
    sensor_names: List[str]
    switch_names: List[str]

    def __post_init__(self) -> None:
        self.logger = logging.getLogger(__name__)

        self.logger.info("Initiating LCD")
        # Use compatibility mode to avoid driver timing issues https://github.com/dbrgn/RPLCD/issues/70
        self.lcd = CharLCD(compat_mode=True,
                           numbering_mode=GPIO.BCM,
                           cols=16,
                           rows=2,
                           pin_rs=22,
                           pin_e=17,
                           pins_data=[26, 19, 13, 6])
        self.lcd.cursor_mode = 'hide'
        self.lcd.clear()

        self.write_lock = Lock()

    def handle_switch(self, name: str, on: bool) -> None:
        if name not in self.switch_names:
            self.logger.warning("'%s' is not configured to be printed to lcd",
                                name)
            return

        x = floor(self.switch_names.index(name) / 2)
        y = self.switch_names.index(name) % 2

        self.__write(14 + x, y, name[0].upper() if on else " ")

    def handle_temperature(self, name: str, temperature: float,
                           avg_temperature: float) -> None:
        if name not in self.sensor_names:
            self.logger.warning(
                "Device '%s' is not configured to be printed to LCD", name)
            return

        y = floor(self.sensor_names.index(name) / 2)
        x = (self.sensor_names.index(name) - 2 * y) * 7

        self.__write(x, y, "%s %s" % (name[0].upper(), round(temperature, 1)))

    def __write(self, x, y, text) -> None:
        self.logger.debug("Writing '%s' to LCD at (%s,%s)", text, x, y)
        with self.write_lock:
            self.lcd.cursor_pos = (y, x)
            self.lcd.write_string(text)

    def shutdown(self) -> None:
        self.logger.info("Shutting down LCD")
        self.lcd.close(clear=True)
Esempio n. 4
0

def formatline(*args):
    line = "".join(args)
    linelen = len(line)
    if linelen < 20:
        pad = 20 - linelen
        return "{}{}{}".format(args[0], " " * pad, args[1])


gpio.setmode(gpio.BCM)  # Pin Belegung festlegen
lcd = CharLCD(pin_rs=7,
              pin_rw=4,
              pin_e=8,
              pins_data=[23, 18, 15, 14],
              numbering_mode=gpio.BCM,
              cols=20,
              rows=4,
              dotsize=8)

lcd.write_string(sys.argv[2])  # Uhrzeit
lcd.write_string("  ")  # Freistelle
lcd.write_string(sys.argv[1])  # Datum/ Ende mit Stelle 20

lcd.write_string(formatline("P: ", sys.argv[3]))
lcd.write_string(formatline("D: ", sys.argv[4]))
lcd.write_string(formatline("U: ", sys.argv[5]))

#Display nicht loeschen nach Script stop mit false sonst nullt er das !
lcd.close(clear=false)
Esempio n. 5
0
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')
input('The display should show "123456" on the first line')

lcd.clear()
lcd.backlight = False
lcd.close()
print('Test done. If you have a backlight, it should now be off.')
Esempio n. 6
0
# 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')
input('The display should show "123456" on the first line')

lcd.clear()
lcd.backlight = False
lcd.close()
print('Test done. If you have a backlight, it should now be off.')
Esempio n. 7
0
current_thread = None

init()

while True:
    for entry in driver.get_log('browser'):
        if entry['level'] == 'INFO':
            msg = entry['message'].split('"')[1]
            if msg in ['reset', 'reverse']:
                stop = True
                current_thread.join()
                stop = False
                if msg == 'reset':
                    init()
                else:
                    lines[1] = ''
                    write_to_screen(lines)
                continue
            if title:
                clear()
                title = None
            if len(msg) < 15:
                lines[0] = msg
                write_to_screen(lines)
            elif len(msg) > 15:
                lines[1] = msg
                current_thread = Thread(target=animate, args=[lines])
                current_thread.start()

lcd.close(clear=True)
Esempio n. 8
0
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
Esempio n. 9
0
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)
Esempio n. 10
0
		maxlen = arglen

def formatvalue(value):
	width = len(value.split(".")[0])
	if width < maxlen:
		pad = maxlen - width
		return "{}{}".format(" " * pad, value)
	return value

def formatline(*args):
	line = "".join(args)
	linelen = len(line)
	if linelen < 20:
		pad = 20 - linelen
		return "{}{}{}".format(args[0], " " * pad, args[1])

gpio.setmode(gpio.BCM) # Pin Belegung festlegen
lcd = CharLCD(pin_rs=7, pin_rw=4, pin_e=8, pins_data=[23, 18, 15, 14], numbering_mode=gpio.BCM, cols=20, rows=4, dotsize=8)


lcd.write_string(sys.argv[2]) # Uhrzeit
lcd.write_string("  ") # Freistelle
lcd.write_string(sys.argv[1]) # Datum/ Ende mit Stelle 20

lcd.write_string(formatline("P: ", sys.argv[3]))
lcd.write_string(formatline("D: ", sys.argv[4]))
lcd.write_string(formatline("U: ", sys.argv[5]))

#Display nicht loeschen nach Script stop mit false sonst nullt er das !
lcd.close(clear=false)
import netifaces
import time
from subprocess import Popen, PIPE
from RPLCD import CharLCD


def run_cmd(cmd):
    p = Popen(cmd, shell=True, stdout=PIPE)
    output = p.communicate()[0]
    return output

if __name__ == '__main__':
    lcd = CharLCD(pin_rs=37, pin_e=40, pin_rw=None, pins_data=[38, 35, 36, 33], cols=16, rows=2)

    try:
        while True:
            for interface in netifaces.interfaces():
                addresses = netifaces.ifaddresses(interface)
                if netifaces.AF_INET in addresses:
                    family = addresses[netifaces.AF_INET]
                    for idx, address_attrs in enumerate(family):
                        lcd.clear()
                        lcd.write_string('{}'.format(interface))
                        lcd.cursor_pos = (1, 0)
                        lcd.write_string(address_attrs['addr'])
                        time.sleep(4)
    finally:
        lcd.close(clear=True)