def main(): global lcd lcd.backlight(1) # 1: On, 0: Off now_str_prev = datetime.datetime.now().strftime('%m-%d %H:%M:%S') is_said = False while True: now = datetime.datetime.now() now_str = datetime.datetime.now().strftime('%m-%d %H:%M:%S') if (now.second == 1): if not is_said: say(str(now.hour) + "時" + str(now.minute) + "分です") is_said = True if (now.second == 2): is_said = False if (datetime.datetime.now().second == 31): show_ip(2) show_temp(3) # openjtalk が間に合わない show_humidity(2) show_humiditydeficit(2) show_CO2(2) if not now_str == now_str_prev: lcd.lcd_display_string(now_str) now_str_prev = now_str time.sleep(0.1)
def show_temp(sec): global lcd p = subprocess.Popen("tail -n 1 " + ini.get("data", "temp_path") + "/temp.csv", stdout=subprocess.PIPE, shell=True) result = p.stdout.readline().strip().decode('utf-8', 'ignore').split(',') lcd.lcd_clear() # lcd.lcd_display_string("TEMP = " + result[1]) lcd.lcd_display_string("TEMP = " + result[2]) say(u"温度" + result[1] + u"度") time.sleep(sec)
def show_humiditydeficit(sec): global lcd p = subprocess.Popen("tail -n 1 " + ini.get("data", "humiditydeficit_path") + "/humiditydeficit.csv", stdout=subprocess.PIPE, shell=True) result = p.stdout.readline().strip().decode('utf-8').split(',') lcd.lcd_clear() # lcd.lcd_display_string("HumidDef = " + result[1]) lcd.lcd_display_string("HumidDef = " + result[2]) time.sleep(sec)
def __init__(self): self.mylcd = I2C_LCD_driver.lcd() self.custom_highlighted = [ highlighted_right, highlighted_left, one, two, three, four, five, pusty ] self.mylcd.lcd_load_custom_chars(self.custom_highlighted)
def __init__(self, num_cols=DEFAULT_NUM_COLUMNS, num_rows=DEFAULT_NUM_ROWS): self._lcd = LCD.lcd() self._lines = ['' for i in range(num_rows)] self._num_rows = num_rows self._num_cols = num_cols
def __init__(self, screen_width): self.LCD_WIDTH = screen_width self.shift = 0 self.msg_width = 1 self.message = " \n " self.clear_screen = False self.lcd_driver = I2C_LCD_driver.lcd()
def test_main(): #mylcd = I2C_LCD_driver.lcd() #mylcd.lcd_display_string("Hello World!", 2, 3) """Test function for verifying basic functionality.""" mylcd = I2C_LCD_driver.lcd(1, DEFAULT_I2C_ADDR, 2, 16) #lcd = I2cLcd(1, DEFAULT_I2C_ADDR, 2, 16) #mylcd.blink_cursor_on() #lcd.putstr("Please wait\ninitialising") time.sleep(0.5) mylcd.lcd_clear() #lcd.blink_cursor_off() count = 0 total = len(sys.argv) # nmumber of arguments in string msg1 = sys.argv[1:] # get everything after python script name text_line, l_number, p_number = msg1 # strip out the text and the line ref line_number = int(l_number) - 1 pos_number = int(p_number) - 1 #move_to(self, cursor_x, cursor_y): while True: #mylcd.move_to(pos_number, line_number) #lcd.putstr(time.strftime('%b %d %Y\n%H:%M:%S', time.localtime())) #time.sleep(1) #lcd.backlight_on() mylcd.lcd_display_string("Hello World!", 2, 3) #mylcd.lcd_display_string(str(text_line), pos_number, line_number) #lcd.putstr(str(text_line)) #lcd.putstr(time.strftime('%b %d %Y\n%H:%M:%S', time.localtime())) #lcd.putstr(datetime.datetime.now().time()), 3) # Write just the time to the display time.sleep(1) exit()
def lcd_init(cls): try: cls.lcd = mylcd = I2C_LCD_driver.lcd() return 0 except: print("Error while initializing LCD") return 1
def main(): ### KEYPAD INITIALIZATION ### kp = keypad(columnCount=4) digit = None #global target global target target = "" print("Enter your zip code or press '#' for Irvine: ") for i in range(5): digit = None while digit == None: digit = kp.getKey() if (digit == "#"): break print(digit) target = target + str(digit) time.sleep(0.4) ### END KEYPAD ### relay_motion.setup() current_hr = datetime.datetime.now().time().hour print(current_hr) mylcd = I2C_LCD_driver.lcd() #current_hr = 18 rpi_data.read_sensors(current_hr, mylcd)
def main(argv): display = I2C_LCD_driver.lcd() display.lcd_clear() mutex_lock = threading.Lock() # Run the clock in a separate thread, since it needs to update more # often (pretty much every second) lcd_clock = Clock(display, mutex_lock) lcd_clock.run() nic = NIC(display, mutex_lock) try: while True: nic.show_eth0() sleep(5) nic.show_wifi() sleep(5) except (KeyboardInterrupt, SystemExit): lcd_clock.stop() display.lcd_write(0x01) # Faster and more consistent than lcd_clear() finally: display.lcd_write(0x01) sys.exit
def message(firstLine, secondLine): mylcd = I2C_LCD_driver.lcd() mylcd.lcd_display_string(secondLine, 2) while True: for i in range (0, len(firstLine)): lcd_text = firstLine[i:(i+16)] mylcd.lcd_display_string(lcd_text,1) sleep(0.10) mylcd.lcd_display_string(str_pad,1)
def __init__(self): self.lcd = I2C_LCD_driver.lcd() self.processing = False self.queue = [] queue = threading.Thread(name='queue', target=self.run) logger.info("starting queue") queue.start() bootup = threading.Thread(name='bootled', target=self.startup) bootup.start()
def __init__(self): self.mylcd = I2C_LCD_driver.lcd() self.custom = [ caly_kwadrat, gorny_kwadrat, dolny_kwadrat, pusty, ludzik_pelny_dol, ludzik_pusty_dol, ludzik_pelny_gora, ludzik_pusty_gora ] self.mylcd.lcd_load_custom_chars(self.custom) self.next = 0
def run(self): global end_Thread now = time.time() mylcd = I2C_LCD_driver.lcd() which_door = self.door while (end_Thread == 0): mode = sql_fetch("mode", which_door) locked = sql_fetch("locked", which_door) mylcd.lcd_clear() while ((mode == 1) or (mode == 6)): now_time = time.strftime("%-I:%M:%S %p") mylcd.lcd_display_string(str(now_time), 1) if (locked == 1): mylcd.lcd_display_string("Door Locked", 2) elif ((locked == 0) or (mode == 6)): mylcd.lcd_display_string("Door Unlocked", 2) else: print("Not 1 or 0") time.sleep(.05) mode = sql_fetch("mode", which_door) locked = sql_fetch("locked", which_door) mylcd.lcd_clear() while (mode == 2): ##Door Unlocked lcd_name = sql_fetch("tag_name", which_door) mylcd.lcd_display_string("Access Granted", 1) mylcd.lcd_display_string(lcd_name, 2) time.sleep(.05) mode = sql_fetch("mode", which_door) while (mode == 3): ## Access Denied lcd_name = sql_fetch("tag_name", which_door) mylcd.lcd_display_string("Access Denied", 1) time.sleep(.05) mode = sql_fetch("mode", which_door) while (mode == 4): ## Add Tag lcd_name = sql_fetch("tag_name", which_door) mylcd.lcd_display_string("Swipe Tag", 1) mylcd.lcd_display_string(lcd_name, 2) time.sleep(.05) mode = sql_fetch("mode", which_door) while (mode == 5): ## Remove Tag mylcd.lcd_display_string("Swipe Tag", 1) mylcd.lcd_display_string("to Remove", 2) time.sleep(.05) mode = sql_fetch("mode", which_door) while (mode == 7): now_time = time.strftime("%-I:%M:%S %p") mylcd.lcd_display_string(str(now_time), 1) if (locked == 1): mylcd.lcd_display_string("Away Mode", 2) time.sleep(.05) mode = sql_fetch("mode", which_door) locked = sql_fetch("locked", which_door)
def __init__(self): """ """ self.db = set_up_firebase() self.user_id = 'Morty' self.mylcd = I2C_LCD_driver.lcd() self.receive_data()
def evaluate_status(score, fall_status, water_status): GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) # red led GPIO.setup(25, GPIO.OUT) # green led GPIO.setup(12, GPIO.OUT) # yellow led GPIO.setup(24, GPIO.OUT) # buzzer GPIO.setup(23, GPIO.OUT) # blue led mylcd = I2C_LCD_driver.lcd() mylcd.lcd_display_string("Health: " + str(score), 1) fall = False need_water = False try: # eval score if 70 <= score <= 100: # good! GPIO.output(25, True) # green GPIO.output(12, False) # yellow GPIO.output(18, False) # red GPIO.output(24, False) # buzzer elif 40 <= score <= 70: # ok -- yellow GPIO.output(25, False) # green GPIO.output(12, True) # yellow GPIO.output(18, False) # red GPIO.output(24, False) # buzzer elif 0 < score <= 40: # bad -- red GPIO.output(25, False) # green GPIO.output(12, False) # yellow GPIO.output(18, True) # red GPIO.output(24, True) # buzzer else: # something went wrong GPIO.output(25, True) # green GPIO.output(12, True) # yellow GPIO.output(18, True) # red # eval water_status if water_status <= 700: # TODO*: figure out value GPIO.output(23, True) # blue need_water = True else: GPIO.output(23, False) # blue # eval fall if -12 <= fall_status["z"] <= -8: # upright if 0 < score <= 40: pass else: GPIO.output(18, False) # red GPIO.output(24, False) # buzzer else: GPIO.output(18, True) # red GPIO.output(24, True) # buzzer fall = True except Exception as e: pass return fall, need_water
def printHealthLcd(init = False): global charLcdHealth # lcd_display_string (string, row (1~4), column (0~19)) if init: charLcdHealth = I2C_LCD_driver.lcd(CHAR_LCD_HEALTH_I2C_ADDRESS) #12345678901234567890# charLcdHealth.lcd_display_string ("AP 0m | PID 0", 1, 0) charLcdHealth.lcd_display_string ("SNR 0 | RSSI 0", 2, 0) charLcdHealth.lcd_display_string ("B/s 0 | PGPS OFF", 3, 0) charLcdHealth.lcd_display_string ("READ | RGPS OFF", 4, 0) else: if managerDict["apogee"] is not None: string = str(managerDict["apogee"]) string = fixStringLcd(string, CHAR_DISPLAY_APOGEE_MAX_LEN) charLcdHealth.lcd_display_string (string, 1, CHAR_DISPLAY_APOGEE_BASE_POS - len(string) + 1) string = str(int(logArray[(managerDict["logLength"] - 1) * DATA_LIST_VARIABLES + DATA_LIST_PACKET_ID])) string = fixStringLcd(string, CHAR_DISPLAY_PID_MAX_LEN) charLcdHealth.lcd_display_string (string, 1, PID_BASE_POS - len(string) + 1) string = str(int(logArray[(managerDict["logLength"] - 1) * DATA_LIST_VARIABLES + DATA_LIST_SNR])) string = fixStringLcd(string, CHAR_DISPLAY_SNR_MAX_LEN) charLcdHealth.lcd_display_string (string, 2, CHAR_DISPLAY_SNR_BASE_POS - len(string) + 1) string = str(int(logArray[(managerDict["logLength"] - 1) * DATA_LIST_VARIABLES + DATA_LIST_RSSI])) string = fixStringLcd(string, CHAR_DISPLAY_RSSI_MAX_LEN) charLcdHealth.lcd_display_string (string, 2, CHAR_DISPLAY_RSSI_BASE_POS - len(string) + 1) string = str(managerDict["bytePerSecondRF"]) string = fixStringLcd(string, CHAR_DISPLAY_BPS_MAX_LEN) charLcdHealth.lcd_display_string (string, 3, CHAR_DISPLAY_BPS_BASE_POS - len(string) + 1) #string = str(int(logArray[(managerDict["logLength"] - 1) * DATA_LIST_VARIABLES + DATA_LIST_SYSTEM_RESETS])) #fixStringLcd(string, RSTS_MAX_LEN) #charLcdHealth.lcd_display_string (string, 4, RSTS_BASE_POS - len(string) + 1) if managerDict["readingRF"]: charLcdHealth.lcd_display_string (" ON", 4, 5) else: charLcdHealth.lcd_display_string ("OFF", 4, 5) if managerDict["pdaDataDict"]["gpsIsOn"]: charLcdHealth.lcd_display_string (" ON", 3, 17) else: charLcdHealth.lcd_display_string ("OFF", 3, 17) if logArray[managerDict["logLength"] * DATA_LIST_VARIABLES + DATA_LIST_GPS_LAT]: charLcdHealth.lcd_display_string (" ON", 4, 17) else: charLcdHealth.lcd_display_string ("OFF", 4, 17)
def update_screen(moisture): if LCD_ENABLE: print(datetime.datetime.now(), 'Updating screen with moisture {}...'.format(moisture)) updated_time = str( datetime.datetime.fromtimestamp(float( data['updated'])).strftime('%Y-%m-%d %H:%M:%S')) moisture_lcd = 'MOISTURE:' + str(moisture) my_lcd = I2C_LCD_driver.lcd() my_lcd.lcd_display_string(updated_time, 1, 0) my_lcd.lcd_display_string(moisture_lcd, 2, 0)
def main(): file = open("output.txt", "r") torrents = parseDelugeOutput(file) mylcd = I2C_LCD_driver.lcd() print "Currently downloading..." for torrent in torrents: printLCD(mylcd, torrent) print "Title: " + torrent.getTitle() print "Size: " + torrent.getSize()
def main(): mylcd = I2C_LCD_driver.lcd() mylcd.lcd_clear() mylcd.lcd_load_custom_chars(fontdata1) print_zero(mylcd) time.sleep(5) mylcd.lcd_clear() time.sleep(1) print_one(mylcd)
def __init__(self): self.lcd = I2C_LCD_driver.lcd() self.reader = MFRC522.MFRC522() self.encendido = None self.mac = "21B6232DE6B4" self.numero_lineas = 2 self.lineas = [] self.keepalive = None GPIO.setmode(GPIO.BOARD) # Use board pin numbering GPIO.setup(7, GPIO.OUT) # Setup GPIO Pin 7 to OUT GPIO.output(7, False) # Turn on GPIO pin 7
def show_ip(sec): global lcd p = subprocess.Popen("hostname -I", stdout=subprocess.PIPE, shell=True) lcd.lcd_clear() lcd.lcd_display_string("IP:") lcd.lcd_display_string(p.stdout.readline().strip().decode('utf-8'), 2) time.sleep(sec)
def __init__(self, _sWelcome): threading.Thread.__init__(self) # variables to hold pir current and last states self.pir_state = 0 self.bStopRequest = False self.iDisplay = 1 self.sScreen1Row1 = _sWelcome self.sScreen1Row2 = " Target: " self.sScreen2Row1 = " SG: " self.sScreen2Row2 = " Beer: " self.sScreen3Row1 = "(W)Beer: " self.sScreen3Row2 = "Chamber: " self.lcdOffTime = datetime.datetime.now() self.displaySwitchTime = datetime.datetime.now() + datetime.timedelta( seconds=DISPLAY_ON_SEC) self.dataTime = datetime.datetime.now() # Initialize the GPIO Pins os.system('modprobe w1-gpio') # Turns on the GPIO module # Set the GPIO naming conventions GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) # Set the three GPIO pins for Output GPIO.setup(PIN_PIR, GPIO.IN) # Create LCD, passing in MCP GPIO adapter. self.lcd = I2C_LCD_driver.lcd() time.sleep(5) self.lcd.backlight(0) self.bLcdOn = False if _sWelcome != None: self.lcd.backlight(1) self.bLcdOn = True self.lcd.lcd_display_string(_sWelcome, 1) self.lcdOffTime = datetime.datetime.now() + datetime.timedelta( seconds=LCD_ON_SEC) logger.debug("1 - LCD is on to show welcome") else: self.lcd.backlight(0) self.bLcdOn = False # Loop until PIR output is 0 while GPIO.input(PIN_PIR) == 1: self.pir_state = 0
def local_data(): #lcd = CharLCD(cols=15,rows=2,pin_rs=37,pin_e=35,pins_data=[33,31,29,23]) mylcd = I2C_LCD_driver.lcd() #we are using DHT11 so 11 is our sensor type and it's connected to GPIO pin 4 humidity, temperature = fruit.read_retry(11, 4) if humidity is not None and temperature is not None: #display temp and humidity on lcd temperature = temperature * (9 / 5) + 32 mylcd.lcd_display_string("Temp: %.1f F" % (temperature), 1) mylcd.lcd_display_string("Humidity: %.1f %% " % (humidity), 2) #print ("Temp: {0:0.1f}C Humidity: {1:0.1f} %".format(temperature,humidity)) return (temperature, humidity) else: return None
def show_CO2(sec): global lcd lcd.lcd_clear() if ini.get("data", "CO2_path"): # settings is NOT null then p = subprocess.Popen("tail -n 1 " + ini.get("data", "CO2_path") + "/co2.csv", stdout=subprocess.PIPE, shell=True) result = p.stdout.readline().strip().decode('utf-8').split(',') lcd.lcd_clear() # lcd.lcd_display_string("CO2 = " + result[1]) lcd.lcd_display_string("CO2 = " + result[2]) say(u"二酸化炭素濃度" + result[1] + u"ppmです") time.sleep(sec)
def run(): print('starting server...') # Server settings # Choose port 8080, for port 80, which is normally used for a http server, you need root access server_address = ('', 80) httpd = HTTPServer(server_address, testHTTPServer_RequestHandler) print('running server...') httpd.serve_forever() ##### LCD Code Here mylcd = I2C_LCD_driver.lcd() mylcd.lcd_clear() print("Starting...") print("Current Local IP: " + get_pi_ip_address('wlan0')) mylcd.lcd_display_string("Server", 1, 0) mylcd.lcd_display_string(get_pi_ip_address('wlan0'), 2, 0)
def main(): mylcd = I2C_LCD_driver.lcd() newPhrase = 'mini jibberish !!!' mylcd.lcd_display_string(newPhrase, 1) mylcd.lcd_display_string("vs Sat 9 Nov 19", 2) theWords = minijib.getWords() combinedList = minijib.getCombinedList(theWords) minijib.printSummary(theWords, combinedList) while True: oldPhrase = newPhrase newPhrase = minijib.getPhrase(combinedList) mylcd.lcd_display_string(newPhrase, 1) mylcd.lcd_display_string(oldPhrase, 2) sleep(5)
def __init__(self): # Set class logger self.log = logging.getLogger("GPIOHandler") logging.getLogger("GPIOHandler").setLevel(logging.INFO) # Create flags checked by Game Class self.exitFlag = False self.startFlag = False self.shootFlag = False self.resetFlag = False self.forfeitFlag = False # Create LCD screen object self.lcd = I2C_LCD_driver.lcd() self.lcd.lcd_clear() # Create button update thread self.buttonThread = Thread(target=self.__updateButtonStates) # Create counter to be updated by Game class self.shotCounter = 0 # Set up GPIO self.__setupGPIO()
import I2C_LCD_driver from time import * import os import socket address = 0x27 # LCD i2c #use i2cdetect -y 1 to scan all i2c devices def get_ip_address(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) return s.getsockname()[0] if (__name__ == "__main__"): print(get_ip_address()) mylcd = I2C_LCD_driver.lcd() mylcd.lcd_display_string("Robot IP", 1) mylcd.lcd_display_string(str(get_ip_address()), 2)
# IP_Script Developed by: tlsrudak, modified by zzeromin # requires I2C_LCD_driver.py from mpd import MPDClient import I2C_LCD_driver from sys import exit from time import * from subprocess import * client = MPDClient() # create client object client.timeout = 10 # network timeout in seconds (floats allowed), default: None client.idletimeout = None # timeout for fetching the result of the idle command is handled seperately, default:$ client.connect("localhost", 6600) # connect to localhost:6600 currentsong = client.currentsong() mylcd = I2C_LCD_driver.lcd() status = client.status() bitrate = "bitrate" audio = "audio" for text in status: if text == bitrate: mylcd.lcd_display_string("bitrate:", 1) mylcd.lcd_display_string(str(status.get(text)) + "kbps", 1, 9) for text in status: if text == audio: mylcd.lcd_display_string("audio:", 2) mylcd.lcd_display_string(str(status.get(text)), 2, 7) sleep(2) # 2 sec delay
def set_lcd(q): lcd = i2c_lcd.lcd() while True: lcd.lcd_display_string(q.get(), 1) q.task_done()
#!/usr/bin/env python import I2C_LCD_driver import socket import fcntl import struct import time import os LCD = I2C_LCD_driver.lcd() def get_ip_address( ifname ): s = socket def fgc( fileName='/var/www/lcd' ):# file_get_contents f = open( fileName , "r" ) ret = f.read() f.close() return ret def fpc( str ):# file_put_contents f = open( "/var/www/lcd" , "w" ) f.write( str ) f.close() def adaptMsg( msg , charNumber=16 ): while len( msg ) < 16: msg += " " return msg while True: lcd = fgc().strip( "\n\t " ).split( ";" )