def test_lcd(): print('Testing LCD...') lcd = LCD() lcd.text('Works', 1) ans = input('Is Works printed on the LCD? y/n: ') lcd.clear() return ans == 'y'
def customCallback(client, userdata, message): payload = json.loads(message.payload) if payload["deviceID"] == "CA2": lcd = LCD() lcd.clear() takePic() lcd.text('Time to eat', 1) lcd.text('medicine', 2) buzzerOn() lcd.clear()
def customCallback(client, userdata, message): #get the updated string for the sign from the topic print("Received a new message: ") print(message.payload) message = message.payload lcd = LCD() data = message.split(":") #split the message from user, string contains a : to seperate row 1 and row 2 for LCD lcd.text(data[0],1) #display text onto row 1 of lcd lcd.text(data[1],2) #display text onto row 2 of lcd print("--------------\n\n") f = open("led.txt","w") f.write(message) f.close()
def lcd_display(text_list): lcd = LCD() print "displaying" print text_list try: if 'clear' in text_list[0]: lcd.clear() else: lcd.text(text_list[0], 1) lcd.text(text_list[1], 2) sleep(1) except Exception: lcd.clear()
def main(): lcd = LCD() swarm = SwarmInfo() while True: sleep(1) if not swarm.is_manager(): lcd.text('Swarm is disabled', 1) else: managers = len(swarm.get_managers()) workers = len(swarm.get_workers()) lcd.text( '%s manager, %s worker%s' % (managers, workers, '' if workers == 1 else 's'), 1) lcd.text('IP: %s' % (swarm.get_node_ip(), ), 2) lcd.text('Memory: %s' % (swarm.get_total_memory(), ), 3) lcd.text('Running tasks: %s' % (len(swarm.get_running_tasks())), 4)
my_rpi = AWSIoTMQTTClient("ADMIN_NUMBER_CLIENT") my_rpi.configureEndpoint(host, 8883) my_rpi.configureCredentials(rootCAPath, privateKeyPath, certificatePath) my_rpi.configureOfflinePublishQueueing(-1) # Infinite offline Publish queueing my_rpi.configureDrainingFrequency(2) # Draining: 2 Hz my_rpi.configureConnectDisconnectTimeout(10) # 10 sec my_rpi.configureMQTTOperationTimeout(5) # 5 sec my_rpi.connect() update = True # card reading variables uid = None prev_uid = None continue_reading = True # lcd variable lcd = LCD() # bot variable bot = telepot.Bot(my_bot_token) GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.OUT) GPIO.setup(40, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(37, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) pwm = GPIO.PWM(11, 50) pwm.start(0) def SetAngle(angle): duty = angle / 18 + 2 GPIO.output(11, True)
from rpi_lcd import LCD from time import sleep lcd = LCD(address=0x27, bus=1, width=16, rows=2) lcd.text('Hello World!', 1) lcd.text('Raspberry Pi', 2) sleep(2) lcd.clear() lcd.text("This is test string for i2c lcd screen, which has 16x2 demension.", 1) sleep(5)
#device libraries import sys import RPi.GPIO as GPIO from gpiozero import Button from time import sleep import datetime as datetime import json from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient from rpi_lcd import LCD lcd = LCD() #Soil setup soil = Button(24) #amazonaws host and certs host = "XXXXXXXXXXXXXXXX.us-east-1.amazonaws.com" rootCAPath = "rootca.pem" certificatePath = "certificate.pem.crt" privateKeyPath = "private.pem.key" #mqtt connection my_rpi = AWSIoTMQTTClient("farm1-irrigation") my_rpi.configureEndpoint(host, 8883) my_rpi.configureCredentials(rootCAPath, privateKeyPath, certificatePath) my_rpi.configureOfflinePublishQueueing(-1) # Infinite offline Publish queueing my_rpi.configureDrainingFrequency(2) # Draining: 2 Hz my_rpi.configureConnectDisconnectTimeout(10) # 10 sec my_rpi.configureMQTTOperationTimeout(5) # 5 sec def activation():
def pillSchedule(): try: # Setting up the pin for the dht sensor, the buzzer and motion sensor pin = 4 bz = Buzzer(5) pir = MotionSensor(26, sample_rate=20, queue_len=1) # To setup the certificate etc for mqtt host = "acway7h5aefsa-ats.iot.us-east-1.amazonaws.com" rootCAPath = "getEnvironmentCert/rootca.pem" certificatePath = "getEnvironmentCert/certificate.pem.crt" privateKeyPath = "getEnvironmentCert/private.pem.key" # Set the filename and bucket name BUCKET = 'sp-p1726819-s3-bucket' location = {'LocationConstraint': 'us-east-1'} file_path = "/home/pi/labs/assignment/photo" file_name = "user.jpg" my_rpi = AWSIoTMQTTClient("PubSub-p1726819" + rand_str_gen()) my_rpi.configureEndpoint(host, 8883) my_rpi.configureCredentials(rootCAPath, privateKeyPath, certificatePath) my_rpi.configureOfflinePublishQueueing( -1) # Infinite offline Publish queueing my_rpi.configureDrainingFrequency(2) # Draining: 2 Hz my_rpi.configureConnectDisconnectTimeout(10) # 10 sec my_rpi.configureMQTTOperationTimeout(5) # 5 sec # Connect and subscribe to AWS IoT my_rpi.connect() update = True while update: try: global medicine_time data = get_data_from_dynamodb(1, 'pillSchedule', -1) medicine_time = data global medicine_time_plus medicine_time_plus = datetime.datetime.strptime( medicine_time, "%H:%M:%S") medicine_time_plus += datetime.timedelta(0, 60) medicine_time_plus = medicine_time_plus.strftime("%H:%M:%S") # Get the current time now and check if it is the time specified now = datetime.datetime.now() time_string = now.strftime("%H:%M:%S") if (medicine_time_plus > time_string > medicine_time): # Alert the user by turning on the buzzer bz.on() print("Time to eat medicine") # Print on the LCD to tell the user to take med lcd = LCD() lcd.text('Time to eat', 1) lcd.text('medicine :)', 2) # Checking how long did the user take to take the medicine after buzzer on old_now = datetime.datetime.now().strftime("%H:%M:%S") start_dt = datetime.datetime.strptime(old_now, '%H:%M:%S') pir.wait_for_motion( 10) # Motion sensor will only wait for 10 seconds new_now = datetime.datetime.now() new_time = new_now.strftime("%H:%M:%S") end_dt = datetime.datetime.strptime(new_time, '%H:%M:%S') duration = (end_dt - start_dt) diff = int(duration.seconds) # If the user took more than 10 seconds it means that the user did not take the medicine on time if diff < 8: # Take a photo and store to S3 takePhoto(file_path, file_name) uploadToS3(file_path, file_name, BUCKET, location) ageLow = 0 ageHigh = 0 # Print the deteced face attribute print('Detected faces for') for faceDetail in detect_faces(BUCKET, file_name): ageLow = faceDetail['AgeRange']['Low'] ageHigh = faceDetail['AgeRange']['High'] print('Age between {} and {} years old'.format( ageLow, ageHigh)) print('Here are the other attributes:') print( json.dumps(faceDetail, indent=4, sort_keys=True)) # To ensure that the medicine is taken by elderly and not others (Kids or pets) if (ageLow < 20 < ageHigh): # The medicine is taken in less than 10 seconds, turn off buzzer lcd.text('Medicine taken', 1) lcd.text('successfully :)', 2) print("User ate medicine after {:.2f} seconds". format(diff)) bz.off() # Get the current date and time and insert the data into the database True_string = 'True' message = {} message["deviceID"] = "CA2" message["datetimeID"] = new_now.isoformat() message["takenOnTime"] = True_string my_rpi.publish("sensor/takeMed", json.dumps(message), 1) # Clear LCD print("Uploaded data to database") print("Waiting for next schedule") lcd.clear() sleep(60) # The medicine is not taken by elderly else: bz.off() print("Medicine not taken by patient") # Send a msg to the user telling that the patient did not take medicine on time send_user_Msg("Medicine not taken by patient") # Get the current date and time and insert into the database False_string = 'False' message = {} message["deviceID"] = "CA2" message["datetimeID"] = new_now.isoformat() message["takenOnTime"] = False_string my_rpi.publish("sensor/takeMed", json.dumps(message), 1) # Clear LCD print("Uploaded data to database") print("Waiting for next schedule") lcd.clear() sleep(60) else: # The user did not take medicine within 10 seconds bz.off() print("Patient did not take medicine on time") # Send a msg to the user telling that the patient did not take medicine on time send_user_Msg("User did not eat medicine on time") # Get the current date and time and insert into the database False_string = 'False' message = {} message["deviceID"] = "CA2" message["datetimeID"] = new_now.isoformat() message["takenOnTime"] = False_string my_rpi.publish("sensor/takeMed", json.dumps(message), 1) # Clear LCD print("Uploaded data to database") print("Waiting for next schedule") lcd.clear() sleep(60) except KeyboardInterrupt: update = False except: print("Error while inserting data...") print(sys.exc_info()[0]) print(sys.exc_info()[1]) except: print(sys.exc_info()[0]) print(sys.exc_info()[1])
def __init__(self): self.lcd = LCD(rows = 2) self.lcd.clear() self.internalclear() self.update_time = time.time()
# DHT11 Sensor : GPIO PIN 20 # Motion Sensor : GPIO PIN 26 # Lights LED : GPIO PIN 21 # Door LED : GPIO PIN 16 # Buzzer : GPIO PIN 5 # Servo Motor : GPIO PIN 12 # Keypad : GPIO PIN 19, 17, 27, 22, 18, 23, 24, 25 sens1 = 20 adc = MCP3008(channel=0) light = round(1024 - (adc.value * 1024)) pir = MotionSensor(26, sample_rate=5, queue_len=1) led = LED(21) doorled = LED(16) LCD = LCD() bz = Buzzer(5) passcode = '12345' # Initalize Servo GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(12, GPIO.OUT) servo1 = GPIO.PWM(12, 50) servo1.start(0) servo1.ChangeDutyCycle(2) # Numpad Matrix MATRIX = [[1, 2, 3, 'A'], [4, 5, 6, 'B'], [7, 8, 9, 'C'], ['*', 0, '#', 'D']] # Match pins to rows and columns
b2 = 12 # Botão 2 - Para contagem b3 = 7 # Botão 3 - Sincronizar com BD led_on = 8 # LED indicador de leitura ligada led_count = 25 # LED indicador de contagem # GPIO: Driver Motores mot_A_PWM = 26 mot_A_IN2 = 19 mot_A_IN1 = 13 mot_standby = 6 mot_B_IN1 = 5 mot_B_IN2 = 11 mot_B_PWM = 9 # Variáveis de Controle lcd = LCD() # LCD play = 0 # Inicio e fim da leitura do sensor count = 0 # Contagem das plantas dist_max = 40 # Distância máxima para contagem dist_min = 50 # Distância minima para contagem dist_set = 0 # Auxiliar de nova contagem # Definindo Dados do Usuário e Fazenda farm_id = 2 user_id = 3 # GPIO Setup GPIO.setmode(GPIO.BCM) GPIO.setwarnings(1) GPIO.setup(TRIGGER, GPIO.OUT) GPIO.output(TRIGGER, 0)
from dotenv import load_dotenv from gpiozero.pins.pigpio import PiGPIOFactory import os from rpi_lcd import LCD load_dotenv() try: remote_factory = PiGPIOFactory(host=os.environ['REMOTEPI']) except: print(f'Could not connect to Raspberry Pi at {os.environ["REMOTEPI"]}') camLED = LED(24) servo = Servo(18, 1, pin_factory=remote_factory) RGBLed = RGBLED(27, 23, 25) screen = LCD() systems = { 'fan': "T", 'servo': "T", 'keypad': "T", 'camera': "T", 'sensor': "T", } buzzer = Buzzer(4) remote_buzzer = Buzzer(17, pin_factory=remote_factory) fan = DigitalOutputDevice(22, pin_factory=remote_factory) def armSystem():