Exemple #1
0
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()
Exemple #2
0
    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()
Exemple #3
0
def setup():
        LCD1602.init(0x27, 1)	# init(slave address, background light)
        LCD1602.clear()
        time.sleep(2)
        LCD1602.write(0, 0, 'Greetings!!')
		LCD1602.write(1, 1, 'from SunFounder')
		time.sleep(2)
Exemple #4
0
def setup(Rpin, Gpin, Bpin):
    global pins
    global p_R, p_G, p_B
    ADC.setup(0x48)
    pins = {'pin_R': Rpin, 'pin_G': Gpin, 'pin_B': Bpin}
    GPIO.setmode(GPIO.BOARD)  # Numbers GPIOs by physical location
    GPIO.setup(TRIG, GPIO.OUT)
    GPIO.setup(ECHO, GPIO.IN)

    for i in pins:
        GPIO.setup(pins[i], GPIO.OUT)  # Set pins' mode is output
        GPIO.output(pins[i], GPIO.HIGH)  # Set pins to high(+3.3V) to off led

    p_R = GPIO.PWM(pins['pin_R'], 2000)  # set Frequece to 2KHz
    p_G = GPIO.PWM(pins['pin_G'], 1999)
    p_B = GPIO.PWM(pins['pin_B'], 5000)

    p_R.start(100)  # Initial duty Cycle = 0(leds off)
    p_G.start(100)
    p_B.start(100)

    #setup LCD
    LCD1602.init(0x27, 1)  # init(slave address, background light)
    LCD1602.write(0, 0, 'Ultrasonic Range:')
    LCD1602.write(1, 1, '...')
    print 'Done sensor setup'
    time.sleep(2)
    setupMQTT()
    print 'Done AWS_IOT_MQTT setup'
    time.sleep(2)
    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()
Exemple #6
0
 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()
Exemple #7
0
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))
Exemple #8
0
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 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
Exemple #10
0
 def write(self, x, y, text):
     """
     输出屏幕
     :param x: 横坐标:[0,16]
     :param y: 纵坐标:{0,1}
     :param text: str,输出文本
     :return:
     """
     LCD1602.write(x, y, text)
Exemple #11
0
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()
Exemple #12
0
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)
Exemple #13
0
def output(line1, line2):
    ''' Format for 1602 display and send to output '''
    try:
        LCD.clear()
        LCD.write(0, 0, line1)
        LCD.write(0, 1, line2)
        return 0
    except IOError:
        print "IOError: most likely cause is loose 3to5v converter."
        return -1
Exemple #14
0
def init():

    #print ('Setting up, please wait...')

    LCD_Width = 16
    # Configure LCD
    LCD1602.init(0x27, 1)  # init(slave address, background light)
    LCD1602.write(0, 0, 'Greetings!!')
    LCD1602.write(0, 1, 'from GordonNet Temp Monitor')
    time.sleep(5)
    LCD1602.clear()
Exemple #15
0
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
Exemple #16
0
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()
Exemple #17
0
def setup():
    print("creating new matrbot facade")
    configure_io()
    print("showing message:")
    LCD1602.init(0x27, 1)
    LCD1602.write(0, 0, "Hello im MATRBOT")
    LCD1602.write(0, 1, "IP : no ip yet!")
    #p = Process(target=updateIp)
    p.start()
    asyncmsg.setup()
    configureScheduler()
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()
Exemple #19
0
def main():
    print "Bienvenido al sistema RaspiAlert\n"
    LCD1602.clear()
    while True:
        result = read_dht11_dat()
        if result:
            humidity, temperature = result
            LCD1602.write(0, 0, ' # RaspiAlert #')
            LCD1602.write(1, 1, 'H= %s%% T= %s C' % (humidity, temperature))
            print "humidity: %s %%, Temperature: %s C`" % (humidity,
                                                           temperature)
            time.sleep(5)
Exemple #20
0
    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))
Exemple #21
0
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)
Exemple #22
0
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)
Exemple #23
0
def init_lcd():
    gw = os.popen("ip -4 route show default").read().split()
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect((gw[2], 0))
    ipaddr = s.getsockname()[0]
    gateway = gw[2]
    host = socket.gethostname()
    print("IP:", ipaddr, " GW:", gateway, " Host:", host)

    LCD1602.init(0x27, 1)  # init(slave address, background light)
    LCD1602.write(0, 0, 'Ip address:')
    LCD1602.write(0, 1, ipaddr)
    time.sleep(2)
Exemple #24
0
def loop():
    while True:
        dis = distance()
        print(dis, 'cm')
        print('')
        GPIO.output(BUZZER, GPIO.LOW)
        if (dis > 400):
            LCD1602.clear()
            LCD1602.write(0, 0, 'Error')
            LCD1602.write(3, 1, 'Out of range')
            time.sleep(0.5)
        else:
            LCD1602.clear()
            LCD1602.write(0, 0, 'Distance is')
            LCD1602.write(5, 1, str(round(dis, 2)) + ' cm')
            if (dis >= 50):
                time.sleep(0.5)
            elif (dis < 50 and dis > 20):
                for i in range(0, 2, 1):
                    GPIO.output(BUZZER, GPIO.HIGH)
                    time.sleep(0.05)
                    GPIO.output(BUZZER, GPIO.LOW)
                    time.sleep(0.2)
            elif (dis <= 20):
                for i in range(0, 5, 1):
                    GPIO.output(BUZZER, GPIO.HIGH)
                    time.sleep(0.05)
                    GPIO.output(BUZZER, GPIO.LOW)
                    time.sleep(0.05)
Exemple #25
0
def setup():
    LCD1602.init(0x27, 1)  # init(slave address, background light)
    LCD1602.write(0, 0, 'Greeting!!')
    LCD1602.write(1, 1, 'Drone :-)')

    ADC.setup(0x48)  # Setup PCF8591

    GPIO.setmode(GPIO.BOARD)
    GPIO.setup(TRIG, GPIO.OUT)
    GPIO.setup(ECHO, GPIO.IN)

    global state
    global current_dist
    global running
Exemple #26
0
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 setup():
    global keypad, last_key_pressed,keys
    rowsPins = [18,23,24,25]
    colsPins = [10,22,27,17]
    keys = ["1","2","3","A",
            "4","5","6","B",
            "7","8","9","C",
            "*","0","#","D"]
    keypad = Keypad(rowsPins, colsPins, keys)
    last_key_pressed = []
    LCD1602.init(0x27, 1)    # init(slave address, background light)
    LCD1602.clear()
    LCD1602.write(0, 0, 'Welcome!')
    LCD1602.write(0, 1, 'Press A to Start!')
Exemple #28
0
def main():
    print "Bienvenido al sistema RaspiAlert\n"
    LCD1602.clear()
    #bot.polling(none_stop=True)
    bot.set_update_listener(listener)

    while True:
        result = read_dht11_dat()
        if result:
            humidity, temperature = result
            LCD1602.write(0, 0, ' # RaspiAlert #')
            LCD1602.write(1, 1, 'H= %s%% T= %s C' % (humidity, temperature))
            print "humidity: %s %%, Temperature: %s C`" % (humidity,
                                                           temperature)
            time.sleep(5)
Exemple #29
0
def main():
	print "Arrancado el modulo meteo\n"
	LCD1602.clear()
	while True:
		result = read_dht11_dat()
		if result:
			humidity, temperature = result
			LCD1602.write(0, 0, ' # RaspiAlert #')
                        LCD1602.write(1, 1, 'H= %s%% T= %s C' % (humidity, temperature))
                        texto = "Humedad: %s %%, Temperatura: %s C" % (humidity, temperature)
			print texto
			lectura = open('temp','w')
			lectura.write(texto)
			lectura.close()
		time.sleep(5)
Exemple #30
0
def setup():
    global keypad, last_key_pressed
    rowsPins = [18,23,24,25]
    colsPins = [10,22,27,17]
    keys = ["1","2","3","A",
            "4","5","6","B",
            "7","8","9","C",
            "*","0","#","D"]
    keypad = Keypad(rowsPins, colsPins, keys)
    last_key_pressed = []
    LCD1602.init(0x27, 1)    # init(slave address, background light)
    LCD1602.clear()
    LCD1602.write(0, 0, 'WELCOME!')
    LCD1602.write(2, 1, 'Enter password')
    time.sleep(2)
Exemple #31
0
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)
Exemple #32
0
def updateIp():
    count = 0
    while True:
        try:
            current_ip = networking.get_ip_address("wlan0")
            if current_ip is None or current_ip == "":
                LCD1602.write(0, 1, "IP:no ip yet!" + count)
                count += 1
            else:
                LCD1602.write(0, 1, "IP:" + current_ip)
                break
        except:
            print("error getting ip ,retrying in 5 seconds")
            pass
        time.sleep(5)
    print("ip scan process finished")
Exemple #33
0
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
Exemple #34
0
def loop():
    #	url = 'http://192.168.10.142:8880/GetDisplay'
    url = 'http://localhost:8880/GetDisplay'
    headers = {'Content-type': 'application/json'}
    response = requests.get(url, headers=headers)
    data = response.json()
    print(data)
    print(response.url)
    #	LCD1602.init(0x27, 1)	# init(slave address, background light)
    #	line1 = 'Please keep calm'
    #	line2 = 'Help is coming )'
    line1 = data['display1']
    line2 = data['display2']
    LCD1602.clear()
    LCD1602.write(0, 0, line1)
    LCD1602.write(0, 1, line2)
    time.sleep(3.0)
Exemple #35
0
def loop():
    while True:
        analogVal = ADC.read(0)
        Vr = 5 * float(analogVal) / 255
        Rt = 10000 * Vr / (5 - Vr)
        temperature = 1 / (((math.log(Rt / 10000)) / 3950) + (1 / (273.15 + 25)))
        temperature = (temperature - 273.15)
        temperature = round(temperature, 1)
        fahrenheit = ((temperature*1.8)+32)
        LCD.write(0,0, 'Temp: {} F'.format(fahrenheit)+'        ')
        time.sleep(.5)
        print("Sending Temperature: ", fahrenheit)


        myMQTTClient.publish(
            topic="RealTimeDataTrasfer/Temperature",
            QoS=1,
            payload='{"Temperature":"'+str(fahrenheit)+'"}')
Exemple #36
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 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)
Exemple #38
0
def mouth_open():
    LCD.clear()
    LCD.write(0,0,"")
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)
Exemple #40
0
 def alert(self, text):
     LCD.clear()
     LCD.write(0,0,"ALERT!")
     LCD.write(0,1,text)
Exemple #41
0
 def mouth_close(self):
     LCD.clear()
     LCD.write(0,0,'________________')
     LCD.write(0,1,'----------------')
def temp_out_LCD(temp):
    LCD1602.clear()
    LCD1602.write(0, 0, 'current temp:')
    LCD1602.write(1, 1, temp + ' C')
Exemple #43
0
 def mouth_open(self):
     LCD.clear()
     LCD.write(0,0,'|--------------|')
     LCD.write(0,1,'|______________|')
Exemple #44
0
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 setup():
    LCD1602.init(0x27, 1)
    LCD1602.write(0, 0, 'Hello!')