def light_sensor_setup(): DO = 17 light_sensor_address = 0x48 GPIO.setmode(GPIO.BCM) ADC.setup(light_sensor_address) GPIO.setup(DO, GPIO.IN)
def setup(): ADC.setup(0x48) GPIO.setup(ledPin, GPIO.OUT) GPIO.output(ledPin, GPIO.LOW) global p p = GPIO.PWM(ledPin, 1000) p.start(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 setup(): ADC.setup(0x48) GPIO.setup(DO, GPIO.IN) def Print(x): if x == 1: print '' print ' ***************' print ' * Not raining *' print ' ***************' print '' if x == 0: print '' print ' *************' print ' * Raining!! *' print ' *************' print '' def loop(): status = 1 while True: print ADC.read(0) tmp = GPIO.input(DO); if tmp != status: Print(tmp) status = tmp time.sleep(0.2) if __name__ == '__main__': try: setup() loop() except KeyboardInterrupt: pass
def setup(): global CURRENT_DAY global CURRENT_MON global CURRENT_HOUR global CROP global SYSTEM_CONTROLLER GPIO.setmode(GPIO.BOARD) GPIO.setup(RAIN_SENSOR_PIN, GPIO.IN) ADC.setup(0x48) global TEMPERATURE_SENSOR for i in os.listdir('/sys/bus/w1/devices'): if i != 'w1-bus-master1': TEMPERATURE_SENSOR = i print('== Program starting ==') GPIO.setup(FAN_PIN, GPIO.OUT) GPIO.setup(ROOF_PIN, GPIO.OUT) GPIO.setup(HEAT_PIN, GPIO.OUT) GPIO.setup(WATER_PIN, GPIO.OUT) GPIO.setup(SHADE_PIN, GPIO.OUT) GPIO.setup(BLACKOUT_PIN, GPIO.OUT) GPIO.setup(LIGHT_PIN, GPIO.OUT) CURRENT_DAY = datetime.datetime.today().day CURRENT_MON = datetime.datetime.today().month CURRENT_HOUR = datetime.datetime.today().hour CROP = Crop('plant.csv') SYSTEM_CONTROLLER = SystemController(SYSTEM_PINS, GPIO) # Starting thread for user input thread.start_new_thread(listen_for_input, ())
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 run(): ADC.setup(0x48) while True: out_file = open('TempOutput.txt', "a+") mean_value = [] for i in range(20): analogVal = ADC.read(0) Vr = 5 * float(analogVal) / 255 Rt = 10000 * Vr / (5 - Vr) temp = 1 / (((math.log(Rt / 10000)) / 3950) + (1 / (273.15 + 25))) temp = temp - 273.15 mean_value.append(temp) print(temp) if len(mean_value) > 20: mean_value.remove(mean_value[0]) sleep(0.1) average_temp = sum(mean_value) / len(mean_value) print(average_temp) out_file.write(str(average_temp) + "\n") if 36.1 <= average_temp <= 37.2: time.sleep(10) # insert name of function that reads data from sensor elif average_temp >= 38: # insert code for app alerts print("High Temperature! Risk of fever! " + "\n" + str(datetime.now())) # insert name of function that reads data from sensor else: # insert code for app alerts print("Low Temperature! Risk of fever! " + "\n" + str(datetime.now())) # insert name of function that reads data from sensor out_file.close()
def setup(): ADC.setup(0x48) GPIO.setup(DO, GPIO.IN) GPIO.setup(LEDOUT, GPIO.OUT) GPIO.setup(PUSH_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_UP) reset_system() initialize_tradlos() initialize_flash_led()
def get_temperature(): ADC.setup(0x48) analogVal = ADC.read(0) Vr = 5 * float(analogVal) / 255 Rt = 10000 * Vr / (5 - Vr) temp = 1 / (((math.log(Rt / 10000)) / 3950) + (1 / (273.15 + 25))) temp = temp - 273.15 print('temperature = %s C'%temp) return '%.2f'%temp
def setup(gpioPort, i2cAddress): global initialRainIntensityReading global lowerBoundary GPIO.setmode(GPIO.BCM) ADC.setup(i2cAddress) GPIO.setup(gpioPort, GPIO.IN) initialRainIntensityReading = ADC.read(0) # set the delta zone so we dont need to recalc it every time lowerBoundary = initialRainIntensityReading - rainDelta print "initial rain intensity reading: ", initialRainIntensityReading
def measure(): ADC.setup(0x48) bus = smbus.SMBus(1) reading = ADC.read(2) ADC.write(ADC.read(0)) value = ((0.641025641) * reading) moistureLevel = (100 - value) * 2 if moistureLevel > 100: moistureLevel = 100 return moistureLevel
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 read_PCF8591(channel, analogInput): ADC.setup(channel) value = 0 runs = 5 # read sensor a few times to ensure a good value for x in range(runs): analogVal = ADC.read(analogInput) value += analogVal time.sleep(0.1) # calculate the average of the sensing runs avgValue = value / runs percentage = avgValue / 255 return percentage
def __init__(self): """ pi.init() constructor to initialize class """ self._valid_import = VALID_IMPORT #setup constants self._DO = 17 if(self._valid_import): GPIO.setmode(GPIO.BCM) ADC.setup(0x48) GPIO.setup(self._DO, GPIO.IN) self._humiture = HumitureSensor()
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
def setup(): global mqttClient global not_done_message_sent global done_message_sent ADC.setup(0x48) GPIO.setup(DO, GPIO.IN) cycle_done = 0 done_led_status = 255 not_done_message_sent = 0 done_message_sent = 0 mqttClient = mqtt.Client(clientName) mqttClient.on_connect = connectionStatus mqttClient.on_message = messageDecoder mqttClient.on_publish = on_publish mqttClient.connect(serverAddress, port) ret = mqttClient.publish("Basement/Washer/Done", "0")
def setup(): global state global drone global running global flying global battery_level LCD1602.init(0x27, 1) # init(slave address, background light) LCD1602.write(0, 0, 'Greeting!!') LCD1602.write(1, 1, 'Coderdojo:-)') ADC.setup(0x48) # Setup PCF8591 GPIO.setmode(GPIO.BOARD) GPIO.setup(TRIG, GPIO.OUT) GPIO.setup(ECHO, GPIO.IN) drone = libardrone.ARDrone() drone.set_speed(0.2)
def main(): try: ADC.setup(0x48) # Set up the GPIO pins used to talk to the DAC monitor = PeakMonitor(SINK_NAME, METER_RATE) for sample in monitor: # samples range from 0 to 127 so double them to get the full voltage # range of the DAC ("<< 1") # sample = sample << 1 sample = sample * 1.42 # reduce range for better VU scale # sample = table[sample] # ...using loopup table # print sample ADC.write(sample) except KeyboardInterrupt: #Ctrl+C pressed print print "Shutdown requested...exiting" monitor.flushqueue()
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() setupMotors() #setup webcam pygame.camera.init() global cam cam = pygame.camera.Camera("/dev/video0",(640,480)) cam.start() # Create an S3 client global s3 s3 = boto3.client('s3') print 'Done AWS_IOT_MQTT setup' time.sleep(2)
def setup(): ADC.setup(0x48)
def setup(): ADC.setup(0x48) GPIO.setup(DO, GPIO.IN)
def setup(): ADC.setup(0x48) GPIO.setup (DO, GPIO.IN) GPIO.setup (Buzz, GPIO.OUT) GPIO.output (Buzz, 1)
def setup(): print 'Setting up, please wait...' ADC.setup(0x48)
def setup(): GPIO.setmode(GPIO.BCM) ADC.setup(0x48) GPIO.setup(DO, GPIO.IN)
def setup(): ADC.setup(0x48) # Setup PCF8591 global state
dsSND= get_datastream(feed,"SunfounderSound","db") dsSND.max_value = None dsSND.min_value = None dsLIGHT= get_datastream(feed,"SunfounderLight","cnd") dsLIGHT.max_value = None dsLIGHT.min_value = None # connections Sensor = 11 humiture = 17 lightSensor=1 # Ananlog In 1 soundSensor=0 # Ananlog In 0 #setup ADC.setup(0x48) while True: # Error handling in case of problems communicating with the Sunfounder try: # Get value from temperature sensor [humidity,temp] = DHT.read_retry(Sensor, humiture) t=temp h=humidity # Get value from light sensor light_intensity = ADC.read(lightSensor) # Get sound level sound_level = ADC.read(soundSensor)