import time from w1thermsensor import W1ThermSensor import board import busio import adafruit_bme280 i2c = busio.I2C(board.SCL, board.SDA) import adafruit_ads1x15.ads1015 as ADS from adafruit_ads1x15.analog_in import AnalogIn import RPi.GPIO as GPIO print ("Starting ambTHP_Wind_ambLight_LED_btn_A4.py") #version A4 works fully as of 2021AJan26 # with digOut, digIn and Heat if True : #pins definitions btn_pin=10 redled_pin=11 yelled_pin=8 grnled_pin=7 heat_pin=9 #setup pins GPIO.setmode(GPIO.BCM) GPIO.setup(btn_pin,GPIO.IN) GPIO.setup(redled_pin,GPIO.OUT) GPIO.setup(yelled_pin,GPIO.OUT) GPIO.setup(grnled_pin,GPIO.OUT) GPIO.setup(heat_pin,GPIO.OUT) #Turn on 1 sec, off 1 sec twice print("Flash redLED twice") GPIO.output(redled_pin,GPIO.HIGH) time.sleep(1) GPIO.output(redled_pin,GPIO.LOW) time.sleep(1) GPIO.output(redled_pin,GPIO.HIGH) time.sleep(1) GPIO.output(redled_pin,GPIO.LOW) time.sleep(1) print("Flash yelLED once") GPIO.output(yelled_pin,GPIO.HIGH) time.sleep(1) GPIO.output(yelled_pin,GPIO.LOW) time.sleep(1) print("Flash grnLED once") GPIO.output(grnled_pin,GPIO.HIGH) time.sleep(1) GPIO.output(grnled_pin,GPIO.LOW) time.sleep(1) #end if bme = adafruit_bme280.Adafruit_BME280_I2C(i2c) ads = ADS.ADS1015(i2c) ads.gain = 1 #ds18b20 = W1ThermSensor() interval = 5 #How long we want to wait between loops (seconds) while True: time.sleep(interval) #Pull Temperature from DS18B20 #temperature = ds18b20.get_temperature() #Pull temperature from BME280 case_temp = bme.temperature #Pull pressure from BME280 Sensor & convert to kPa pressure_pa = bme.pressure pressure = pressure_pa / 10 #Pull humidity from BME280 humidity = bme.humidity #Calculate wind direction based on ADC reading # read P1 , not P0 chan = AnalogIn(ads, ADS.P0) chanA1 = AnalogIn(ads, ADS.P1) chanA3 = AnalogIn(ads, ADS.P3) valA1 = chanA1.value valA3 = chanA3.value val=chan.value valA0=val #1.5v = 30 lux 1.477 #2.0v = 75 lux 1.87 #2.5v = 275 lux 2.43 print("10^2.5=", 10**2.5) print("valA0=",valA0) print("valA1=",valA1) print("valA3=",valA3) Ahigh=26400 Alow=0 valV0=3.3*(valA0-Alow)/(Ahigh-Alow) valV1=3.3*(valA1-Alow)/(Ahigh-Alow) valV3=3.3*(valA3-Alow)/(Ahigh-Alow) valV3=valV3/1.087 #Correction to make CDS0 = CDS1 print("valV0:",valV0,"v") print("valV1:",valV1,"v") print("valV3:",valV3,"v") print("ambLight0=",10**valV1,"lux") print("ambLight1=",10**valV3,"lux") windDir = "Not Connected" windDeg = 999 if 20000 <= val <= 20500: windDir = "N" windDeg = 0 if 10000 <= val <= 10500: windDir = "NNE" windDeg = 22.5 if 11500 <= val <= 12000: windDir = "NE" windDeg = 45 if 2000 <= val <= 2250: windDir = "ENE" windDeg = 67.5 if 2300 <= val <= 2500: windDir = "E" windDeg = 90 if 1500 <= val <= 1950: windDir = "ESE" windDeg = 112.5 if 4500 <= val <= 4900: windDir = "SE" windDeg = 135 if 3000 <= val <= 3500: windDir = "SSE" windDeg = 157.5 if 7000 <= val <= 7500: windDir = "S" windDeg = 180 if 6000 <= val <= 6500: windDir = "SSW" windDeg = 202.5 if 16000 <= val <= 16500: windDir = "SW" windDeg = 225 if 15000 <= val <= 15500: windDir = "WSW" windDeg = 247.5 if 24000 <= val <= 24500: windDir = "W" windDeg = 270 if 21000 <= val <= 21500: windDir = "WNW" windDeg = 292.5 if 22500 <= val <= 23000: windDir = "NW" windDeg = 315 if 17500 <= val <= 18500: windDir = "NNW" windDeg = 337.5 #Print the results #print( 'Temperature: ' , temperature) print( ' Case Temp: ' , case_temp, 'C at',time.ctime()) print( 'Humidity: ' , humidity, '%') print( 'Pressure: ' , pressure, 'kPa') print( 'Wind Dir: ' , windDir, ' (', windDeg, ')') print( ' ') print("Examine the PushButton") if GPIO.input(btn_pin): print("Turn on the RedLED and Heat") GPIO.output(redled_pin,GPIO.HIGH) GPIO.output(heat_pin,GPIO.HIGH) else: print("Turn off the RedLED and Heat") GPIO.output(redled_pin,GPIO.LOW) GPIO.output(heat_pin,GPIO.LOW) #if end print(".") #end while #ambTHP_Wind_ambLight_LED_btn_A4.py