Exemplo n.º 1
0
def read_temp_c():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = int(temp_string) / 1000.0 
        temp_c = str(round(temp_c, 1
        return temp_c

#FAHRENHEIT CALCULATION
def read_temp_f():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_f = (int(temp_string) / 1000.0) * 9.0 / 5.0 + 32.0 
        temp_f = str(round(temp_f, 1)) 
        return temp_f

while True:

    lcd.string("Temp: " + read_temp_c() + chr(223) + "C",LCD_LINE_1)
    lcd.string("           " + read_temp_f() + chr(223) + "F",LCD_LINE_2)
import time
import lcdlib as lcd

LCD_LINE_1 = 0x80  # LCD RAM address for the 1st line
LCD_LINE_2 = 0xC0  # LCD RAM address for the 2nd line

# Initialise display
lcd.init(25, 24, 23, 17, 18, 22, 16)

while True:
    # Send some test
    lcd.string("Rasbperry Pi", LCD_LINE_1)
    lcd.string("16x2 LCD Test", LCD_LINE_2)

    time.sleep(3)  # 3 second delay

    # Send some text
    lcd.string("1234567890123456", LCD_LINE_1)
    lcd.string("abcdefghijklmnop", LCD_LINE_2)

    time.sleep(3)  # 3 second delay
Exemplo n.º 3
0
        )  # Retrieve latest quote data with the url and parameters specified.
        data = json.loads(
            response.text
        )  # Convert the json response data into a python dictionary.
        price = int(data['data']['1']['quote']['USD']
                    ['price'])  # Retrieve current BTC price.
        price = str("{:,}".format(price))  # Convert BTC price into a string.
        percent_change = (
            data['data']['1']['quote']['USD']['percent_change_24h']
        )  # Retrieve 24 hr percentage change data.
        percent_change_str = str("{:.2f}".format(
            percent_change))  # Convert perctage change into a string.

        # LCD outputs.
        lcd.string(
            "BTC: $" + price,
            LCD_LINE_1)  # Output current BTC price on first row of the LCD.
        sleep(0.2)
        lcd.string(
            "24hr del: " + percent_change_str + "%", LCD_LINE_2
        )  # Output 24hr price percentage change on the second row of the LCD.

        # Turn on amber LED if 24hr price percentage change is positive. Or
        # turn on red LED if the percentage change is negative.
        if percent_change > 0:
            GPIO.output(amberLedPin, GPIO.HIGH)
        else:
            GPIO.output(redLedPin, GPIO.HIGH)

        # Add delay to request an update every minute.
        sleep(60)
Exemplo n.º 4
0
i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
mlx = adafruit_mlx90614.MLX90614(i2c)

GPIO.setwarnings(False)
#Select GPIO mode
GPIO.setmode(GPIO.BCM)
#Set buzzer - pin 23 as output
buzzer=17
GPIO.setup(buzzer,GPIO.OUT)
#Run forever loop

while True:
  url='https://obscure-cliffs-43212.herokuapp.com/pythontoExpress'
  headers={}
  lcd.string("ENTER BARCODE :",LCD_LINE_1)
  barcode = input("enter BArcode:")
  lcd.string(barcode,LCD_LINE_1)
  sleep(1)
  headers['barcode']=barcode
  GPIO.output(buzzer,GPIO.HIGH)
  sleep(0.5)
  GPIO.output(buzzer,GPIO.LOW)
  i = 50 
  temp = "0"
  while i >= 0:
    
    distance = measure_average()
    print( distance)
    if distance < 10:
        
Exemplo n.º 5
0
    dist_3 = distance_3()
    print(
        "Volume 3:",
        round((100 - ((dist_3 - min_dist) / (max_dist - min_dist) * 100)), 0),
        "%")
    n3 = round((100 - ((dist_3 - min_dist) / (max_dist - min_dist) * 100)), 0)
    vol_3 = str(int(n3)) + '%'
    time.sleep(1)
    print("ready to send data")
    msg = {"sensor1": vol_1, "sensor2": vol_2, "sensor3": vol_3}
    # convert the data to JSON
    data = json.dumps(msg)
    print(str(data))
    client.publish(topic, str(data))

    #the line to be displayed on LCD
    lcd.set_line(LCD_LINE_1)
    lcd.string(vol_1 + ' ' + vol_2 + ' ' + vol_3, LCD_LINE_1)
    #test if there is changements every 3 min

    time.sleep(60)

    #clear the LCD
    lcd.clear()

    time.sleep(1)
#//////////////////////////#

#restart all IN/OUT put
GPIO.cleanup()