def make_connect(thread_index): global lcd, DoorbellIO cherrypy.thread_data.conn = db.make_connect() lcd = i2c_lcd_smbus.i2c_lcd(0x3f, 1, 2, 1, 0, 4, 5, 6, 7, 3) cherrypy.thread_data.lcd = lcd GPIO.setmode(GPIO.BCM) GPIO.setup(DoorbellIO, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(DoorbellIO, GPIO.FALLING, callback=TurnOnDisplay, bouncetime=1000) UpdateLCD() TurnOnDisplay(DoorbellIO)
def __init__(self): # Configuration parameters # I2C Address, Port, Enable pin, RW pin, RS pin, Data 4 pin, Data 5 pin, Data 6 pin, Data 7 pin, Backlight pin (optional) logger.info("Starting") try: self.lcd = i2c_lcd_smbus.i2c_lcd(0x27,1, 2, 1, 0, 4, 5, 6, 7, 3) # If you want to disable the cursor, uncomment the following line self.lcd.command(self.lcd.CMD_Display_Control | self.lcd.OPT_Enable_Display) self.lcd.backLightOn() except IOError: self.lcd = None # communication error with screen; giveup logger.info("Cant connect to LCD screen") self.isLighted=True self.lastDisplayTime=time.time() self.timer = self.initializeTimer() self.pos=0
import os import psutil def get_temperature(): try: s = subprocess.check_output(["/opt/vc/bin/vcgencmd", "measure_temp"]) return float(s.split('=')[1][:-3]) except: return 0 def get_cpu_usage(): try: return psutil.cpu_percent(interval=.5) except: return 0 lcd = i2c_lcd_smbus.i2c_lcd(0x27, 1, 2, 1, 0, 4, 5, 6, 7, 3) lcd.command(lcd.CMD_Display_Control | lcd.OPT_Enable_Display) lcd.backLightOn() while True: node = "#0" temperature = str(get_temperature()) + chr(223) + "C" cpu = str(get_cpu_usage()) + "%" lcd.setPosition(1, 0) lcd.writeString(node + " " + temperature + " " + cpu + " ") time.sleep(2)
# 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 sys import time import binascii import Adafruit_MPR121.MPR121 as MPR121 from i2clibraries import i2c_lcd_smbus # Configuration parameters # I2C Address, Port, Enable pin, RW pin, RS pin, Data 4 pin, Data 5 pin, Data 6 pin, Data 7 pin, Backlight pin (optional) lcd = i2c_lcd_smbus.i2c_lcd(0x27,1, 2, 1, 0, 4, 5, 6, 7, 3) # If you want to disable the cursor, uncomment the following line lcd.command(lcd.CMD_Display_Control | lcd.OPT_Enable_Display) lcd.backLightOn() print 'Adafruit MPR121 Capacitive Touch Sensor Test' # Create MPR121 instance. cap = MPR121.MPR121() import serial def dump(sdev): a="" while True:
#!/usr/bin/env python import time from lcd import lcddriver from i2clibraries import i2c_lcd_smbus lcd1 = lcddriver.lcd() lcd2 = i2c_lcd_smbus.i2c_lcd(0x3F, 1, 2, 1, 0, 4, 5, 6, 7, 3) lcd2.command(lcd2.CMD_Display_Control | lcd2.OPT_Enable_Display) lcd2.backLightOn() def writeLcd1(message): lcd1.lcd_display_string(str(message), (message % 2) + 1) def writeLcd2(message): lcd2.setPosition((message % 2) + 1, 0) lcd2.writeString(str(message)) if __name__ == "__main__": for count in [10 ** 2, 10 ** 3]: _start = time.time() for ii in xrange(0, count):
#!/usr/bin/env python import time from lcd import lcddriver from i2clibraries import i2c_lcd_smbus lcd1 = lcddriver.lcd() lcd2 = i2c_lcd_smbus.i2c_lcd(0x3f, 1, 2, 1, 0, 4, 5, 6, 7, 3) lcd2.command(lcd2.CMD_Display_Control | lcd2.OPT_Enable_Display) lcd2.backLightOn() def writeLcd1(message): lcd1.lcd_display_string(str(message), (message % 2) + 1) def writeLcd2(message): lcd2.setPosition((message % 2) + 1, 0) lcd2.writeString(str(message)) if __name__ == '__main__': for count in [10**2, 10**3]: _start = time.time() for ii in xrange(0, count):