Skip to content

Instantly share code, notes, and snippets.

@artem-smotrakov
Last active October 24, 2017 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artem-smotrakov/b864a0ebadfff0e50ec227bc6fea5c47 to your computer and use it in GitHub Desktop.
Save artem-smotrakov/b864a0ebadfff0e50ec227bc6fea5c47 to your computer and use it in GitHub Desktop.
Measuring temperature and humidity with DHT22 and MicroPython. See details on https://blog.gypsyengineer.com/fun/diy-electronics/micropython-esp8266-sending-data-to-thingspeak.html
import time
import dht
import machine
def mesure_temperature_and_humidity():
d = dht.DHT22(machine.Pin(DHT22_PIN))
d.measure()
t = d.temperature()
h = d.humidity()
print('temperature = %.2f' % t)
print('humidity = %.2f' % h)
while True:
current_time = time.time()
if current_time - last_mesurement_time > MESUREMENT_INTERVAL:
mesure_temperature_and_humidity()
last_mesurement_time = current_time
time.sleep(DELAY)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment