def update_lcd(line1, line2=None): """Print messages to LCD 16x2""" if lcd_options['address'] == 0: find_lcd_address() if lcd_options['address'] != 0: import pylcd # Library for LCD 16x2 PCF8574 lcd = pylcd.lcd(lcd_options['address'], 0 if helpers.get_rpi_revision() == 1 else 1, lcd_options['hw_PCF8574']) # (address, bus, hw version for expander) # DF - alter RPi version test fallback to value that works on BBB else: lcd = dummy_lcd lcd.lcd_clear() sleep_time = 1 while line1 is not None: lcd.lcd_puts(line1[:16], 1) if line2 is not None: lcd.lcd_puts(line2[:16], 2) if max(len(line1), len(line2)) <= 16: break if line1 is not None: if len(line1) > 16: line1 = line1[1:] if line2 is not None: if len(line2) > 16: line2 = line2[1:] time.sleep(sleep_time) sleep_time = 0.25
def __init__(self): threading.Thread.__init__(self) self.msg = "LCD Ready" self.new = 1 time.sleep(1.0) self.lcd = lcd(0x3f, 0, 1) time.sleep(1.0) self.lcd.clear() self.updateLCD()
Copyright (C) 2012 Matthew Skolaut Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' import pylcd # Create instances of the tmp102 temp sensor and io # expander controlling lcd # tmp102 = pylcd.tmp102(0x48, 0) # address, bus# lcd = pylcd.lcd(0x27, 0, 1) #while 1: # lcd.lcd_puts(" Temp C: " + str(tmp102.read_temp()), 2) lcd.lcd_puts("Hello",1) lcd.lcd_puts("How are you doing?",2)
associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' import pylcd use_temp = None # Create instances of the tmp102 temp sensor and io # expander controlling lcd lcd = pylcd.lcd(0x38, 3, mode=3) if(use_temp): tmp102 = pylcd.tmp102(0x48, 3) # address, bus# while 1: if(use_temp): lcd.lcd_puts(" Temp C: " + str(tmp102.read_temp()), 2) else: lcd.lcd_puts("Hello, World!", 2)
def _lcd_print(self, report, txt=None): self._lcd_lock.acquire() # Print messages to LCD 16x2 datalcd = get_lcd_options() adr = int(datalcd[u"adress"], 0) if adr not in self._addresses: self.status = "" self.add_status( u"Error: Address is not range 0x20-0x27 or 0x38-0x3F!") self._lcd_lock.release() self._sleep(5) return # If the address has changed: Turn off the backlight and clear the LCD then forget the pylcd object. if self._lcd is not None and self._lcd.lcd_device.addr != adr: self._lcd.backlight = 0 # takes effect during next update call on self._lcd self._lcd.lcd_clear() self._lcd = None # Create a pylcd object if necessary if self._lcd is None: self._lcd = pylcd.lcd( adr, (1 if get_rpi_revision() >= 2 else 0), 1 ) # Address for PCF8574 = example 0x20, Bus Raspi = 1 (0 = 256MB, 1=512MB) if self._lcd.error is not None: self.status = u"" self.add_status(u"Error: [Errno " + str(self._lcd.error.errno) + u"] Display not found at address " + datalcd[u"adress"]) self._lcd = None self._lcd_lock.release() self._sleep(5) return if report == u"name": self._lcd.lcd_clear() self._lcd.lcd_puts(gv.sd[u"name"], 1) self._lcd.lcd_puts(u"Irrigation syst.", 2) self.add_status(u"SIP. / Irrigation syst.") elif report == u"d_sw_version": self._lcd.lcd_clear() self._lcd.lcd_puts(u"Software SIP:", 1) self._lcd.lcd_puts(gv.ver_date, 2) self.add_status(u"Software SIP: / " + gv.ver_date) elif report == u"d_ip": self._lcd.lcd_clear() ip = get_ip() self._lcd.lcd_puts(u"My IP is:", 1) self._lcd.lcd_puts(str(ip), 2) self.add_status(u"My IP is: / " + str(ip)) elif report == u"d_port": self._lcd.lcd_clear() self._lcd.lcd_puts(u"Port IP:", 1) self._lcd.lcd_puts(str(gv.sd[u"htp"]), 2) self.add_status(u"Port IP: / {}".format(gv.sd[u"htp"])) elif report == u"d_cpu_temp": self._lcd.lcd_clear() temp = str(get_cpu_temp()) + u" " + gv.sd[u"tu"] self._lcd.lcd_puts(u"CPU temperature:", 1) self._lcd.lcd_puts(temp, 2) self.add_status(u"CPU temperature: / " + temp) elif report == u"d_date_time": self._lcd.lcd_clear() da = time.strftime(u"%d.%m.%Y", time.gmtime(gv.now)) ti = time.strftime(u"%H:%M:%S", time.gmtime(gv.now)) self._lcd.lcd_puts(da, 1) self._lcd.lcd_puts(ti, 2) self.add_status(da + " " + ti) elif report == u"d_uptime": self._lcd.lcd_clear() up = uptime() self._lcd.lcd_puts(u"System run time:", 1) self._lcd.lcd_puts(up, 2) self.add_status(u"System run time: / " + up) elif report == u"d_rain_sensor": self._lcd.lcd_clear() if gv.sd[u"rs"]: rain_sensor = u"Active" else: rain_sensor = u"Inactive" self._lcd.lcd_puts(u"Rain sensor:", 1) self._lcd.lcd_puts(rain_sensor, 2) self.add_status(u"Rain sensor: / " + rain_sensor) elif report == u"d_running_stations": # Report running Stations self._lcd.lcd_clear() if gv.pon is None: prg = u"Idle" elif gv.pon == 98: # something is running prg = u"Run-once" elif gv.pon == 99: prg = u"Manual Mode" else: prg = u"Prog: {}".format(gv.pon) s = "" if prg != u"Idle": # Get Running Stations from gv.ps for i in range(len(gv.ps)): p, d = gv.ps[i] if p != 0: s += u"S{} ".format(str(i + 1)) self._lcd.lcd_puts(prg, 1) self._lcd.lcd_puts(s, 2) elif report == u"d_alarm_signal": # ALARM!!!! self._lcd.lcd_clear() self._lcd.lcd_puts(u"ALARM", 1) self._lcd.lcd_puts(txt, 2) self.add_status(u"Alarm! / " + txt) elif report == u"d_stat_schedule_signal": # A program has been scheduled self._lcd.lcd_clear() self._lcd.lcd_puts(u"New Program", 1) txt = u"Running" # Do not Know what else to display self._lcd.lcd_puts(txt, 2) self.add_status(u"New Program Running / " + txt) self._lcd_lock.release()
associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' import pylcd use_temp = None # Create instances of the tmp102 temp sensor and io # expander controlling lcd lcd = pylcd.lcd(0x38, 3, mode=3) if (use_temp): tmp102 = pylcd.tmp102(0x48, 3) # address, bus# while 1: if (use_temp): lcd.lcd_puts(" Temp C: " + str(tmp102.read_temp()), 2) else: lcd.lcd_puts("Hello, World!", 2)
def setup(): print "Setting up......." global lcd global Inet_access #comms_timer() lcd = pylcd.lcd(0x23, 1, 2) #wait for network to be up n = 0 lcd.lcd_clear() while (n < 60): lcd.lcd_puts("Wating for Ethernet..." + str(n), 1, 0) if is_interface_up("eth0"): lcd.lcd_clear() lcd.lcd_puts("Ethernet is online :-)", 1, 0) time.sleep(2) break else: time.sleep(2) n = n + 1 if debug == False: n = 0 lcd.lcd_clear() while (n < 60): lcd.lcd_puts("Checking for router... :" + str(n), 1, 0) response = os.system("ping -c 1 -W 1 192.168.88.1 >/dev/null") time.sleep(1) if response == 0: time.sleep(1) lcd.lcd_clear() lcd.lcd_puts("Router found :-)", 1, 0) time.sleep(2) break n = n + 1 if n == 60: lcd.lcd_clear() lcd.lcd_puts("Router not found!!!", 1, 0) time.sleep(2) n = 0 lcd.lcd_clear() while (n < 60): lcd.lcd_puts("Checking for Encoder... :" + str(n), 1, 0) response = os.system("ping -c 1 -W 1 192.168.88.249 >/dev/null") if response == 0: time.sleep(1) lcd.lcd_clear() lcd.lcd_puts("Encoder found :-)", 1, 0) time.sleep(2) break n = n + 1 if n == 60: lcd.lcd_clear() lcd.lcd_puts("Encoder not found!!!", 1, 0) time.sleep(2) n = 0 lcd.lcd_clear() while (n < 60): lcd.lcd_puts("Checking for Pluto... :" + str(n), 1, 0) response = os.system("ping -c 1 -W 1 192.168.88.16 >/dev/null") if response == 0: time.sleep(1) lcd.lcd_clear() lcd.lcd_puts("Pluto found :-)", 1, 0) time.sleep(2) break n = n + 1 if n == 60: lcd.lcd_clear() lcd.lcd_puts("Pluto not found!!!", 1, 0) time.sleep(2) lcd.lcd_clear() lcd.lcd_puts("Rebooting ADALM Pluto", 1, 0) print "Sending reboot request to Pluto..." try: requests.post('http://192.168.88.16/pluto.php', {'reboot': ''}) except: print "Error rebooting Pluto." time.sleep(4) #pluto take a while to restart if already online lcd.lcd_clear() while (n < 60): lcd.lcd_puts("Waiting for Pluto to Reboot... :" + str(n), 1, 0) response = os.system("ping -c 1 -W 1 192.168.88.16 >/dev/null") if response == 0: time.sleep(1) lcd.lcd_clear() lcd.lcd_puts("Pluto found :-)", 1, 0) time.sleep(2) break n = n + 1 if n == 60: lcd.lcd_clear() lcd.lcd_puts("Pluto not found!!!", 1, 0) time.sleep(2) ##################################################################### ## restart UDP on Encoder Box lcd.lcd_clear() lcd.lcd_puts("Configuring Encoder...", 1, 0) enc.set_streaming_source( ) #set streaming params for 'sub stream' 1280x720, h264, 15fps enc.streaming("SD") time.sleep(1) enc.restartUDP() lcd.lcd_clear() lcd.lcd_puts("Starting Logic...", 1, 0)
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''' import pylcd # Create instances of the tmp102 temp sensor and io # expander controlling lcd # tmp102 = pylcd.tmp102(0x48, 0) # address, bus# lcd = pylcd.lcd(0x27, 1, 1) #while 1: # lcd.lcd_puts(" Temp C: " + str(tmp102.read_temp()), 2) #lcd.lcd_puts("Hello",1) #lcd.lcd_puts("How are you doing?",2) import socket import fcntl import struct def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR
#!/usr/bin/env python # -*- coding: utf-8 -*- import RPi.GPIO as GPIO #Importamos la librería GPIO import time #Importamos time (time.sleep) import pylcd lcd = pylcd.lcd(0x3f,1,1) GPIO.setmode(GPIO.BCM) #Ponemos la placa en modo BCM GPIO_TRIGGER = 18 GPIO_ECHO = 12 GPIO.setup(GPIO_TRIGGER,GPIO.OUT) #Configuramos Trigger como salida GPIO.setup(GPIO_ECHO,GPIO.IN) #Configuramos Echo como entrada GPIO.output(GPIO_TRIGGER,False) #Ponemos el pin 25 como LOW try: while True: #Iniciamos un loop infinito GPIO.output(GPIO_TRIGGER,True) #Enviamos un pulso de ultrasonidos time.sleep(0.00001) #Una pequeñña pausa GPIO.output(GPIO_TRIGGER,False) #Apagamos el pulso start = time.time() #Guarda el tiempo actual mediante time.time() while GPIO.input(GPIO_ECHO)==0: #Mientras el sensor no reciba señal... start = time.time() #Mantenemos el tiempo actual mediante time.time() while GPIO.input(GPIO_ECHO)==1: #Si el sensor recibe señal... stop = time.time() #Guarda el tiempo actual mediante time.time() en otra variable elapsed = stop-start #Obtenemos el tiempo transcurrido entre envío y recepción distance = (elapsed * 34300)/2 #Distancia es igual a tiempo por velocidad partido por 2 D = (T x V)/2 #Imprimir por LCD
def _lcd_print(self, report, txt=None): self._lcd.acquire() """Print messages to LCD 16x2""" datalcd = get_lcd_options() adr = 0x20 if datalcd['adress'] == '0x20': # range adress from PCF8574 or PCF 8574A adr = 0x20 elif datalcd['adress'] == '0x21': adr = 0x21 elif datalcd['adress'] == '0x22': adr = 0x22 elif datalcd['adress'] == '0x23': adr = 0x23 elif datalcd['adress'] == '0x24': adr = 0x24 elif datalcd['adress'] == '0x25': adr = 0x25 elif datalcd['adress'] == '0x26': adr = 0x26 elif datalcd['adress'] == '0x27': adr = 0x27 elif datalcd['adress'] == '0x38': adr = 0x38 elif datalcd['adress'] == '0x39': adr = 0x39 elif datalcd['adress'] == '0x3a': adr = 0x3a elif datalcd['adress'] == '0x3b': adr = 0x3b elif datalcd['adress'] == '0x3c': adr = 0x3c elif datalcd['adress'] == '0x3d': adr = 0x3d elif datalcd['adress'] == '0x3e': adr = 0x3e elif datalcd['adress'] == '0x3f': adr = 0x3f else: self.status = '' self.add_status('Error: Address is not range 0x20-0x27 or 0x38-0x3F!') self._sleep(5) return import pylcd # Library for LCD 16x2 PCF8574 lcd = pylcd.lcd(adr, (1 if get_rpi_revision() >= 2 else 0), 1) # Address for PCF8574 = example 0x20, Bus Raspi = 1 (0 = 256MB, 1=512MB) if report == 'name': lcd.lcd_clear() lcd.lcd_puts(gv.sd['name'], 1) lcd.lcd_puts("Irrigation syst.", 2) self.add_status('SIP. / Irrigation syst.') elif report == 'd_sw_version': lcd.lcd_clear() lcd.lcd_puts("Software SIP:", 1) lcd.lcd_puts(gv.ver_date, 2) self.add_status('Software SIP: / ' + gv.ver_date) elif report == 'd_ip': lcd.lcd_clear() ip = get_ip() lcd.lcd_puts("My IP is:", 1) lcd.lcd_puts(str(ip), 2) self.add_status('My IP is: / ' + str(ip)) elif report == 'd_port': lcd.lcd_clear() lcd.lcd_puts("Port IP:", 1) lcd.lcd_puts(str(gv.sd['htp']), 2) self.add_status('Port IP: / {}'.format(gv.sd['htp'])) elif report == 'd_cpu_temp': lcd.lcd_clear() temp = get_cpu_temp(gv.sd['tu']) + ' ' + gv.sd['tu'] lcd.lcd_puts("CPU temperature:", 1) lcd.lcd_puts(temp, 2) self.add_status('CPU temperature: / ' + temp) elif report == 'd_date_time': lcd.lcd_clear() da = time.strftime('%d.%m.%Y', time.gmtime(gv.now)) ti = time.strftime('%H:%M:%S', time.gmtime(gv.now)) lcd.lcd_puts(da, 1) lcd.lcd_puts(ti, 2) self.add_status(da + ' ' + ti) elif report == 'd_uptime': lcd.lcd_clear() up = uptime() lcd.lcd_puts("System run time:", 1) lcd.lcd_puts(up, 2) self.add_status('System run time: / ' + up) elif report == 'd_rain_sensor': lcd.lcd_clear() if gv.sd['rs']: rain_sensor = "Active" else: rain_sensor = "Inactive" lcd.lcd_puts("Rain sensor:", 1) lcd.lcd_puts(rain_sensor, 2) self.add_status('Rain sensor: / ' + rain_sensor) elif report == 'd_running_stations': # Report running Stations lcd.lcd_clear() if gv.pon is None: prg = 'Idle' elif gv.pon == 98: # something is running prg = 'Run-once' elif gv.pon == 99: prg = 'Manual Mode' else: prg = "Prog: {}".format(gv.pon) s = "" if prg != "Idle": # Get Running Stations from gv.ps for i in range(len(gv.ps)): p, d = gv.ps[i] if p != 0: s += "S{} ".format(str(i+1)) lcd.lcd_puts(prg, 1) lcd.lcd_puts(s, 2) elif report == 'd_alarm_signal': # ALARM!!!! lcd.lcd_clear() lcd.lcd_puts("ALARM", 1) lcd.lcd_puts(txt, 2) self.add_status('Alarm! / ' + txt) elif report == 'd_stat_schedule_signal': # A program has been scheduled lcd.lcd_clear() lcd.lcd_puts("New Program", 1) txt = "Running" # Do not Know what else to display lcd.lcd_puts(txt, 2) self.add_status('New Program Running / ' + txt) self._lcd.release()