Last week a played around with the Bosch BME680 Sensor module on a Heltec Wifi Kit 32, when I posted about it someone pointed out that I needed to connect an external antenna to the Heltec dev board because otherwise the LoRa module could damaged. I pointed out that I wasn’t using the Heltec LoRa 32 but the Heltec Wifi Kit 32, which doesn’t have the need for the external antenna. However this made me think about the little stack of Heltec LoRa 32 boards I had sitting around from a previous project.

So, I decided to extend the project a little and make it work with the Heltec LoRa 32 boards and in addition to that add a DHT22 sensor for secondary temperature and humidity measurements. Why you ask, well just because I could 🙂

To make it work with the previous code I just had to makes sure that I wired up the Heltec LoRa 32 module correctly, the layout of the pins is different from the Heltec Wifi Kit 32 (I have added both the pinouts for the Heltec Wifi Kit 32 and the Heltec LoRa 32 v2 to the Github Repo but make sure to check the Heltec website for any updates).

Unlike for the BME380, for the DHT22 module you don’t need any special libraries, those are already built into Micropython. All you need to do is add a few lines of code to communicate with the DHT22. Make sure to use a pin that is an input/output pin on your board as otherwise it will not work.

# Get Readings from the DHT
dhtsensor.measure() 
dhttemp = dhtsensor.temperature()
dhthum = dhtsensor.humidity()

And then when you are ready you can just print that or write it to the OLED or, who knows, send it to some online repository? To print it you can do something like this:

print('Temperature: %3.1f C' %dhttemp)
print('Humidity: %3.0f %%' %dhthum)

I have updated the code on Github so that it works with both sensors! Now it all looks like this, what I mess, I might have to do something about that!

And on a side note, I think I need to add a resistor between the data port on the DHT22 and the Dev Board, it seems to work fine but I better to check that out.

As an update to this post, I have added a 4K7 Ohm resistor between the data port of the DHT22 and the Dev Boards, it doesn’t seem to make a difference but I am sure there is some reason that is required.

And here is my first stab at Fritzing this up to make it a little clearer what I did there.

Measuring Temperature and Humidity with a DHT22 on a Heltec LoRa 32 running MicroPython

1 comment
Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts