From: jimmy Date: Mon, 8 Jul 2024 23:58:07 +0000 (-0500) Subject: measure distance and light in garage using veml7700 X-Git-Url: https://vault307.fbx.one/gitweb/garage_door_sensor.git/commitdiff_plain/fa935a996e2a15ad5a8a60f5471e4b6d08d1d4bd?ds=sidebyside measure distance and light in garage using veml7700 will be using pico as sensor pack. will read data from sensors, then process over data (door{open/closed},light{on/off}), send data to zero 2 w over usb. zero will host webpage displaying status of DOOR and LIGHT. --- diff --git a/distanceLux.py b/distanceLux.py new file mode 100644 index 0000000..1cdb2b7 --- /dev/null +++ b/distanceLux.py @@ -0,0 +1,34 @@ +from machine import Pin, I2C, time_pulse_us +import veml7700, time + +i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=10000) # connected on i2c0 + +veml = veml7700.VEML7700(address=0x10, i2c=i2c, it=100, gain=1/8) + +def measure(): + lux_val = veml.read_lux() + print(lux_val) + return(lux_val) + +SOUND_SPEED=340 +TRIG_PULSE_DURATION=10 + +trig_pin=Pin(3, Pin.OUT) +echo_pin=Pin(2,Pin.IN) + +def distance(): + trig_pin.value(0) + time.sleep_us(5) + trig_pin.value(1) + time.sleep_us(TRIG_PULSE_DURATION) + trig_pin.value(0) + + ultransonic_duration=time_pulse_us(echo_pin,1,30000) + distance_cm=SOUND_SPEED*ultransonic_duration/20000 + print(distance_cm) + return(distance_cm) + +while True: + measure() + distance() + \ No newline at end of file