def balance(): client = Client(PUBLIC_API_KEY, PRIVATE_API_KEY) bm = BinanceSocketManager(client) bal = client.get_asset_balance('BTC')['free'] LCD1602.write(0, 0, bal) time.sleep(3) LCD1602.clear()
def setup(): ADC.setup(0x48) GPIO.setup(D0, GPIO.IN) LCD1602.init(0x27, 1) # init(slave address, background light) #LCD1602.write(0, 0, 'Andorich') #LCD1602.write(1, 1, 'Sugondese') time.sleep(2)
def setup(): ADC0834.setup() GPIO.setmode(GPIO.BCM) GPIO.setup(ledPin, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(buzzPin, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(Joy_BtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) LCD1602.init(0x27, 1)
def setup(self): GPIO.setmode(GPIO.BCM) ADC.setup(0x48) LCD.init(0x27, 1) self.display_text("System startup") # setup pins for sensors GPIO.setup(self.THERMISTOR_PIN, GPIO.IN) GPIO.setup(self.GAS_SENSOR_PIN, GPIO.IN) GPIO.setup(self.BUZZ_PIN, GPIO.OUT) GPIO.setup(self.H2O_PIN, GPIO.IN) # setup pins for "eyes" # first eye GPIO.setup(self.SDI_0, GPIO.OUT) GPIO.setup(self.RCLK_0, GPIO.OUT) GPIO.setup(self.SRCLK_0, GPIO.OUT) GPIO.output(self.SDI_0, GPIO.LOW) GPIO.output(self.RCLK_0, GPIO.LOW) GPIO.output(self.SRCLK_0, GPIO.LOW) # second eye GPIO.setup(self.SDI_1, GPIO.OUT) GPIO.setup(self.RCLK_1, GPIO.OUT) GPIO.setup(self.SRCLK_1, GPIO.OUT) GPIO.output(self.SDI_1, GPIO.LOW) GPIO.output(self.RCLK_1, GPIO.LOW) GPIO.output(self.SRCLK_1, GPIO.LOW)
def printer(temp): if (temp < 0 or temp > 100): return if (temp < 10): temp = " " + str(temp) elif (temp < 100): temp = " " + str(temp) LCD1602.write(3, 1, str(temp))
def setup(): LCD1602.init(0x27, 1) # init(slave address, background light) LCD1602.write(0, 0, 'Greetings!!') LCD1602.write(1, 1, 'from SunFounder') time.sleep(2) LCD1602.write(0, 0, 'Hello!!') LCD1602.write(1, 1, 'Everyone') time.sleep(2)
def shutdown(): LCD1602.write(0, 0, ' ') LCD1602.write(1, 1, ' ') disp.clear() setColor(0x000000) os.system("rm ip") os.system("rm .ip.swp") os.system("sudo shutdown -h now")
def destroy(): GPIO.output(BuzzerPin, GPIO.LOW) #Turn off buzzer for pin in pins: GPIO.output(pin, GPIO.LOW) #Turn off all leds GPIO.cleanup() LCD1602.clear()
def get_password_keypad(): LCD.write(0, 0, "Type Password on Keypad") #print on LCD as required key1 = keypad() #get first key time.sleep(1) #wait 1 second before next key to avoid glitches key2 = keypad() #get 2nd key time.sleep(0.5) keyF = str(key1) + str(key2) #concatenate both keys return keyF
def terminate(): print("terminating matrbot interface") LCD1602.clear() GPIO.cleanup() p.terminate() p.join() sched.shutdown() print("bye!")
def write(self, x, y, text): """ 输出屏幕 :param x: 横坐标:[0,16] :param y: 纵坐标:{0,1} :param text: str,输出文本 :return: """ LCD1602.write(x, y, text)
def loop(): #space = ' ' #greetings = 'Thank you for buying SunFounder Sensor Kit for Raspberry! ^_^' #greetings = space + greetings while True: LCD1602.write(0, 0, ADC.read(0)) tmp = GPIO.input(D0) time.sleep(0.8) LCD1602.clear()
def process_message(msg): if msg['e'] == 'error': print("There's an error") else: timestamp = msg['T'] / 1000 timestamp = datetime.fromtimestamp(timestamp).strftime('%m-%d') line_one = symbol + " " + timestamp line_two = msg['p'][:-6] LCD1602.write(0, 0, line_one) LCD1602.write(0, 1, line_two)
def ON_OFF(self): global on_off LCD1602.clear() if GPIO.input(SWITCH)==0: #if system is off GPIO.output(LEDR, GPIO.LOW) GPIO.output(LEDG, GPIO.LOW) on_off=False else: #if system is on GPIO.output(LEDG, GPIO.HIGH) on_off=True
def setup_board(): #SETUP The board global Buzz #use the global var GPIO.setmode(GPIO.BCM) #Set mode to BCM GPIO.setwarnings(False) # call this function to avoid warnings #Switch 1 Parking GPIO.setup( door_switch, GPIO.OUT ) #Set door_switch as OUTPUT - High tells door to open and low tells door to close #Buzzer Setup GPIO.setup(buzzer_output, GPIO.OUT) Buzz = GPIO.PWM( buzzer_output, 500) # buzzer output is the channel, initial frequency is 500 #ultrasonic setup GPIO.setup(TRIG, GPIO.OUT) GPIO.setup(ECHO, GPIO.IN) #Setup RFID #This pin corresponds to GPIO22, which we'll use to turn the RFID reader on and off with. GPIO.setup(ENABLE_PIN, GPIO.OUT) GPIO.output(ENABLE_PIN, GPIO.LOW) global ser #Set up the serial port as per the Parallex reader's datasheet ser = serial.Serial(baudrate=2400, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, port=SERIAL_PORT, stopbits=serial.STOPBITS_ONE, timeout=1) #IR Detector Interrupt setup GPIO.setup(INTR_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #interrupt call defintion GPIO.add_event_detect(INTR_PIN, GPIO.RISING, callback=door_bell_pressed, bouncetime=2000) #Keypad Setup According to the default connections GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(23, GPIO.OUT) GPIO.setup(24, GPIO.OUT) GPIO.setup(25, GPIO.OUT) GPIO.setup(26, GPIO.OUT) #initialize LCD LCD.init(0x27, 1) #(slave address, background light) #ADC Initialization ADC.setup(0x48) #Address of the ADC on i2c in hex
def displayonlcd(temperature, humidity, strdoorstatus): # LCD1602.write(0, 0, 'ABCDEFGHIJKLMNOPQURSTUVWXYZ') # LCD1602.write(1, 1, 'abcdefghighijklmnopqurstuvwxyz') # line1 = 'Temp: ' + str(temperature) + ' ' + chr(223) + 'C' + ' ' + str( strdoorstatus) #add degree symbol line2 = 'Humidity: ' + str(humidity) + '%' # # LCD1602.write(0, 0, line1) #line 1 LCD1602.write(0, 1, line2) #line 2
def loop(): space = ' ' greetings = 'Thank you for buying ZHINENG Sensor Kit for Raspberry! ^_^' greetings = space + greetings while True: tmp = greetings for i in range(0, len(greetings)): LCD1602.write(0, 0, tmp) tmp = tmp[1:] time.sleep(0.8) LCD1602.clear()
def setup(): GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location GPIO.setup(RoAPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # input mode GPIO.setup(RoBPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(BtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) LCD1602.init(0x27, 1) # init(slave address, background light) LCD1602.clear() LCD1602.write(0, 0, "Temperature is") LCD1602.write(0, 1, ' ') LCD1602.write(7, 1, 'degrees') time.sleep(2)
def loop(): space = ' ' greetings = 'Thank you for buying SunFounder Sensor Kit for Raspberry! ^_^' greetings = space + greetings while True: tmp = greetings for i in range(0, len(greetings)): LCD1602.write(0, 0, tmp) tmp = tmp[1:] time.sleep(0.8) LCD1602.clear()
def main(): print("Raspberry Pi wiringPi DHT11 Temperature test program\n") while True: result = read_dht11_dat() if result: humidity, temperature = result print("humidity: %s %%, Temperature: %s C`" % (humidity, temperature)) LCD.print_lcd(0, 0, 'HUM: ' + str(humidity) + ' %') LCD.print_lcd(0, 1, 'TEM: ' + str(temperature) + ' C') time.sleep(1)
def on_change(self, gpio): """used to report the state of the led. This is attached to the on change event. And will speak the status of the led. """ key = self.getSwitchKey(self.switches, gpio) status = GPIO.get(gpio) name = self.switches[key]['name'] self.speak("%s is %s" % (name, status)) LCD1602.init(0x27, 1) # init(slave address, background light) LCD1602.write(0, 0, "%s is %s" % (name, status))
def setup(): GPIO.setwarnings(False) GPIO.setup(pirInput, GPIO.IN) #Read output GPIO 21 from PIR motion sensor #Button and LED setup #GPIO.setup(Gpin, GPIO.OUT) # Set Green Led Pin mode to output #GPIO.setup(Rpin, GPIO.OUT) # Set Red Led Pin mode to output #GPIO.setup(BtnPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set BtnPin's mode is input, and pull up to high level(3.3V) #GPIO.add_event_detect(BtnPin, GPIO.BOTH, callback=detect, bouncetime=200) #setup display LCD1602.init(0x27, 1) # init(slave address, background light)
def loop(): worker = Thread(target=queue_task, args=(q,)) worker.setDaemon(True) worker.start() alarm_thread = Thread(target=alarm_task) alarm_thread.setDaemon(True) alarm_thread.start() status = 1 count = 0 q_count = 0 now = datetime.now() LCD.write(0,0,'System Normal') while True: # get and convert temperature analogTemp = ADC.read(0) Vr = 5 * float(analogTemp) / 255 Rt = 10000 * Vr / (5 - Vr) temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15 + 25))) temp = (temp - 273.15) * 9/5 + 32 print 'temperature = ', temp, 'F' # get and convert gas sensor data gas = ADC.read(1) print 'gas sensor = ', gas # tmp = GPIO.input(GAS_SENSOR) # if tmp != status: # check_gas(tmp) # status = tmp # if status == 0: # count += 1 # if count % 2 == 0: # GPIO.output(BUZZ, 1) # else: # GPIO.output(BUZZ, 0) # else: # GPIO.output(BUZZ, 1) # count = 0 # get water data h2o = ADC.read(2) print "h2o sensor = " + str(h2o) update_LCD(temp, gas, h2o) if q_count > 3.5: updates = [] updates.append({'type' : 'temperature', 'value': str(temp), 'timestamp': str(datetime.now())}) updates.append({'type' : 'gas', 'value': str(ADC.read(1)), 'timestamp': str(datetime.now())}) updates.append({'type' : 'h2o', 'value': str(h2o), 'timestamp': str(datetime.now())}) q.put(updates) q_count = 0 q_count = q_count + 1 time.sleep(2)
def main(): bus.write_byte(address,A3) value=bus.read_byte(address) #print("AOUT:%1.3f "%(value*3.3/255)) value=str(value*3.3/255) LCD.print_lcd(1,1,value[0:5]) LCD.print_lcd(7,1,"V") display="t0.txt=\""+value[0:5]+"V\"" t.write(display) end_uart_lcd(t) time.sleep(0.1)
def __init__(self): logging.basicConfig(format=Settings.LOG_FORMAT, filename=Settings.LOG_FILE) self.logger = logging.getLogger(__name__) self.logger.setLevel(Settings.LOG_LEVEL) self.lock = Lock() LCD1602.init(0x27,1) self.queues = [] # one queue per row for row in range(self.ROWS): self.queues.append(Queue()) self.light_queue = Queue() self.start()
def Print(x): if x == 0: #if ActivarAlarma == 0: print ' ***********************' print ' * Button Pressed! *' print ' ***********************' LCD1602.clear() LCD1602.write(0, 0, ' # RaspiAlert #') LCD1602.write(1, 1, 'Alarma activada') time.sleep(3) LCD1602.write(1, 1, 'Tiene 30s... ') time.sleep(30) LCD1602.clear() detect_movement()
def init(self): LCD1602.init(0x27, 1) # init(slave address, background light) LCD1602.write(0, 0, 'Hello') LCD1602.write(1, 1, 'World') time.sleep(1) LCD1602.clear()
def main(): logging.info("****************** Starting pibater ****************** ") temp = 95 # Set initial values in case humiture doesn't work humidity = 50 camera = picamera.PiCamera() GPIO.output(FAN_RELAY_PIN, GPIO.LOW) # Turn on Fan rotate_eggs(LEFT_DEGREES, camera) # Initialize the rotation, probably not necessary while True: # Since there are problems sometimes reading the humiture sensor, # use the old value if gethumiture() returns false result = gethumiture(last_email_sent) if result != False: humidity, temp = result if temp < MIN_TEMP: GPIO.output(LIGHT_RELAY_PIN, GPIO.LOW) # Light on logging.info("Temp: %s˚F, so turning light on" % temp) elif temp > MAX_TEMP: GPIO.output(LIGHT_RELAY_PIN, GPIO.HIGH) # Light off logging.info("Temp: %s˚F, so turning light off" % temp) if (humidity < MIN_HUMIDITY) or (humidity > MAX_HUMIDITY): logging.info("Humidity out of range" + str(humidity) + "%%") # sendemail("Humidity out of the range:" + str(humidity) + "%%", # "Humidity out of range.", # last_email_sent) # if int(hour()) % 3 == 0: # If hour evenly divisible (mod) by 3 # if int(hour()) % 2 == 0: # If even hour turn left # rotate_eggs(LEFT_DEGREES, camera) # else: # rotate_eggs(RIGHT_DEGREES, camera) if int(minutes()) % 15 == 0: # Take a picture every 15 minutes GPIO.output(LIGHT_RELAY_PIN, GPIO.LOW) # Light on camera.capture(PICTURE_FILENAME + "." + gettime() + ".jpg") # Not ideal to turn the Light off if it was already on, # but it'll turn on in the next min GPIO.output(LIGHT_RELAY_PIN, GPIO.HIGH) # Update LCD Message LCD1602.write(0, 0, str(temp) + '˚F ' + str(humidity) + '%') LCD1602.write(1, 1, gettime()) time.sleep(60)
def loop(): lastState=1 stage=0 while True: currentState=GPIO.input(Joy_BtnPin) if currentState==1 and lastState ==0: stage=(stage+1)%2 time.sleep(0.1) LCD1602.clear() lastState=currentState if stage == 1: upper_tem_setting() else: monitoring_temp()
def light_worker(self): self.logger.info('Starting light worker') while True: event = self.light_queue.get() if event == 'openlight': self.logger.info('Turn on the light') with self.lock: LCD1602.openlight() elif event == 'closelight': self.logger.info('Turn off the light') with self.lock: LCD1602.closelight() else: self.logger.error('Unknown light command') self.light_queue.task_done()
def loop(): global Rt loops = 0 while True: #get sensor data dis = distance() if (dis > 120): dis = 120 d_gas = ADC.read(2) d_flame = ADC.read(1) d_temp = ADC.read(3) Vr = 5 * float(d_temp) / 255 try: Rt = 10000 * Vr / (5 - Vr) except ZeroDivisionError: print('temp is 255') temp = 1 / (((math.log(Rt / 10000)) / 3950) + (1 / (273.15 + 25))) temp = temp - 273.15 #print locally dstring = '{0:.2f}'.format(dis) + ' cm, Gas:' + '{}'.format(d_gas) print dstring #LCD1602.write(1, 1, dstring) LCD1602.write(1, 1, 'Flame:' + '{}'.format(d_flame)) if (dis > 50): setColor(0x00FF00) elif (dis > 25): setColor(0x00FFFF) else: setColor(0xFF0000) #publish if (loops % 7 == 0): myAWSIoTMQTTClient.publish("sensor_data/temperature/", str(temp), 1) myAWSIoTMQTTClient.publish("sensor_data/sonar/", str(dis), 1) myAWSIoTMQTTClient.publish("sensor_data/gas/", str(d_gas), 1) myAWSIoTMQTTClient.publish("sensor_data/flame/", str(255 - d_flame), 1) if (loops > 100): loops = 0 loops = loops + 1 print("loop: " + str(loops)) time.sleep(0.1)
def setup(): global DB global DB_Connect global Sensor2 Sensor2 = BMP085.BMP085(2, A77) LCD1602.init(A27, 1) LCD1602.clear() GPIO.setmode(GPIO.BCM) GPIO.setup(PERSON_PORT, GPIO.IN) try: host, user, passwd, db = genDB() DB = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db) DB_Connect = DB.cursor() except Exception as e: DB = None
def signal_handler(signal, frame): print('SIGINT RECIEVED') LCD1602.write(0, 0, ' ') LCD1602.write(1, 1, ' ') motion.stop() disp = Adafruit_SSD1306.SSD1306_128_32(0) disp.clear() setColor(0xff0000) global CONNECTION_MADE if CONNECTION_MADE: CONNECTION_MADE = 0 conn.send("close") conn.close() global RUN_SERVER exit(0) RUN_SERVER = 0
def display_text(self, text): LCD.clear() if len(text) <= 16: LCD.write(0,0,text) else: top = text[0:15] bot = text[16:] LCD.write(0,0,top) LCD.write(0,1,bot)
def destroy(self): LCD.clear() LCD.write(0,0,'') LCD.write(0,1,'') self.set_eyes(0x00) GPIO.output(self.BUZZ_PIN, GPIO.HIGH) GPIO.cleanup()
def setup(): ADC.setup(0x48) LCD.init(0x27, 1) LCD.write(0,0,'System startup...') time.sleep(1) ALARM = False LCD.clear() GPIO.setup(THERMISTOR_PIN, GPIO.IN) GPIO.setup(GAS_SENSOR_PIN, GPIO.IN) GPIO.setup(BUZZ_PIN, GPIO.OUT) GPIO.setup(H2O_PIN, GPIO.OUT) GPIO.output(BUZZ_PIN, GPIO.HIGH)
def loop(self): current_text = "" while True: "Scroll Text" # add whitespace if len(self.TEXT) > 16: text = self.TEXT # fancy scrolling if we have a long string for i in range(len(text)): #break if text changes if text != self.TEXT: break LCD1602.write(0, 0, text) text = text[1:] time.sleep(0.5) LCD1602.clear() elif current_text != self.TEXT: #static change LCD1602.clear() LCD1602.write(0, 0, self.TEXT) current_text = self.TEXT time.sleep(1) # hold for at least 1 second else: # sleep poll time.sleep(1)
def mouth_open(): LCD.clear() LCD.write(0,0,"")
def destroy(): LCD1602.clear()
def get_mem_info(): total = commands.getoutput('free -m|grep Mem:|awk \'{print $2}\'') free = commands.getoutput('free -m|grep cache:|awk \'{print $4}\'') return 'M:F' + free + '/T' + total + ' MiB' def run_cmd(cmd): p = Popen(cmd, shell=True, stdout=PIPE) output = p.communicate()[0] return output if __name__ == '__main__': LCD.init_lcd() LCD.turn_light(0) # LCD.print_lcd(0,0,datetime.now().strftime('%b %d %H:%M:%S\n')) # LCD.print_lcd(1,1,'local time') # print('wait 5 seconds') # time.sleep(5) while True: # nowtime = datetime.now().strftime('%b %d %H:%M:%S') # mintime = time.strftime('%M',time.localtime(time.time())) # print('current time:'+nowtime) # LCD.print_lcd(0,0,nowtime) # if mintime == 59:
def mouth_close(self): LCD.clear() LCD.write(0,0,'________________') LCD.write(0,1,'----------------')
def mouth_open(self): LCD.clear() LCD.write(0,0,'|--------------|') LCD.write(0,1,'|______________|')
def update_LCD(temp, gas, h2o): global ALARM_ON if not IS_TALKING: if gas >= 150: if not ALARM_ON == True: ALARM_ON = True LCD.clear() LCD.write(0,0,"ALERT!") LCD.write(0,1,"Gas detected!") print '' print ' ***************' print ' * Danger Gas! *' print ' ***************' print '' elif temp <= 45: if not ALARM_ON == True: ALARM_ON = True status = 0 LCD.clear() LCD.write(0,0,"ALERT!") LCD.write(0,1,"Low temperature!") print '' print ' ********************' print ' * Danger Low Temp! *' print ' ********************' print '' elif h2o <= 200: if not ALARM_ON == True: ALARM_ON = True LCD.clear() LCD.write(0,0,"ALERT!") LCD.write(0,1,"Water detected!") print '' print ' **************************' print ' * Danger Water Detected! *' print ' **************************' print '' else: if ALARM_ON: ALARM_ON = False LCD.clear() LCD.write(0,0, "System Normal") print '' print ' --------------------------' print ' * System Status Normal *' print ' --------------------------' print '' else: pass
def destroy(): LCD.clear() GPIO.output(BUZZ_PIN, GPIO.HIGH) GPIO.output(H2O_PIN, GPIO.HIGH) GPIO.cleanup()
def temp_out_LCD(temp): LCD1602.clear() LCD1602.write(0, 0, 'current temp:') LCD1602.write(1, 1, temp + ' C')
def alert(self, text): LCD.clear() LCD.write(0,0,"ALERT!") LCD.write(0,1,text)
def setup(): LCD1602.init(0x27, 1) # init(slave address, background light) LCD1602.write(0, 0, 'Greetings!!') LCD1602.write(1, 1, 'from SunFounder') time.sleep(2)
def setup(): LCD1602.init(0x27, 1) LCD1602.write(0, 0, 'Hello!')