The main focus of this project is to create a small and fancy, temperature, and humidity logger.
The components needed to complete this will be:

  • Raspberry Pi ( I used 3PlusB version )
  • DHT sensor my one ( AM2301)
  • LCD 16×2 with the I2C interface.
  • Python & Graphana

Now from the code point of view. Default raspberry os does not come with necessary libraries so those need to be installed.  This post is not a tutorial on how to complete every task however the process needed to do that all together with links to websites where I got the information is described.

To make this project better some of the save-read file-intensive data will be done on the ram of the device with tmpfs. Raspberry Pi is just another Linux so the support of temporary files should work. Instead of saving data every one second or every minute. The device will collect data for 5 minutes for each second. And then the data will be saved onto the sd-card database. So we saved here 300 read-writes from the sd card. Cause at the beginning project was collecting and saving data every 1 second. Trough the 5 min mark device will collect min, max, avg. Then persistent save will be done and the temporary file will be cleared.

But consider it will require cpu to do more operation i went with a simple list in python. But if you want to use ramdisk just read more about tmpfs.

Another useful hint is how to update the script when I don’t want to write code directly on raspberry. Of course, you can each time copy the script from your pc. But that is so time-consuming. To make everything easier I wrote a small python-ssh easy class. Why eazy? Cause there already was a paramiko library. My class allows you to connect to your device in just two lines of code. Check that out at https://github.com/xmarkurion/python-ssh

For first you need to install libraries for DHT and I2c LCD screen.
LCD youtube tutorial – https://youtu.be/3XLjVChVgec
Github repo for LCD- https://github.com/the-raspberry-pi-guy/lcd
DHT – Resources and guide page   LINK

For a beginning, I have trouble with a weird error. Where script reported index out of range while using for loop. But there was no place that index could go out of range. Also when I replaced DHT reading with random number generator script continues. I might be something wrong with my sensor. The workaround is that the script logs the data into a temp folder and other scripts read the file. If the number of records is placed, everything is averaged and saved as the final file.

But after a short while, I realized that I can just remove a for loop and throw instead and if statement. And that works.

Now connect to raspberry using ssh or cli and load the config screen (sudo raspi-config) then make sure to enable I2C communication port.  After that test LCD and DHT. If you’re getting results to jump to graphana.

You can use my GitHub repo if you want to download the file already modified.
In my case, my sensor is AM2301 i2c is connected on 0x27 and 4 GPO pin for DHT.

For python logging, I’ve used just a normal file writes to CSV.
https://github.com/xmarkurion/pi-Temp-DHT