Skip to content

Instantly share code, notes, and snippets.

@mrjoh3
Created April 25, 2017 01:39
Show Gist options
  • Save mrjoh3/badf3ba138a581193bac05acbf169d29 to your computer and use it in GitHub Desktop.
Save mrjoh3/badf3ba138a581193bac05acbf169d29 to your computer and use it in GitHub Desktop.
# script for running sharp GP2Y1010AU using micropython ESP32 controller
import machine, time
ao = machine.ADC(machine.Pin(36)) # analog read
led = machine.Pin(39) # this is not working
#led = machine.Pin(15, machine.Pin.OUT)
#mg/m3 but want ug/m3
def get_dust():
while True:
# multiple lines in one as still using minicom to test code
on = led.IN; time.sleep_us(280); meas = ao.read(); time.sleep_us(40); off = led.OUT; time.sleep_us(9680);
voltage = meas * (5.0 / 2**12); density = 0.172 * voltage - 0.0999; print('meas: %s; dens: %s; volt: %s' % (meas, density, voltage)); time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment