This program reads temp and humidity fram a DHT11, connected to GPIO26. The RPi is also connected to the network with WiFi.
Inpired from this link: AdaFruit DHT11
To get the source code:
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
To install the library:
sudo apt-get update
sudo apt-get install build-essential python-dev python-openssl
and:
sudo python setup.py install
Pictures
This is what the 3.5" screen looks like
The Perfboard is shaped so it fits in the USB port of the Pi.
The code
from Tkinter import *
import Adafruit_DHT
import datetime
''' Function to update time, date, temp and hum'''
def tick():
now = datetime.datetime.now()
h, t = Adafruit_DHT.read_retry(11, 26)
temp_string = ('T:{0:0.0f}'.format(t))
temperature.config(text=temp_string)
hum_string = (' - H:{0:0.0f}'.format(h))
humidity.config(text=hum_string)
time_string = now.strftime("%H:%M")
clock.config(text=time_string)
clock.after(2000,tick)
date_string = now.strftime("%a %d %b %y")
date.config(text=date_string)
''' This function quits the program'''
def quit():
global window
window.quit()
''' Make us some workspace'''
window = Tk()
window.overrideredirect(True)
window.geometry("480x320")
window.configure(background='white')
''' Label that shows the time'''
clock = Label(window, font=("serif", 100, "bold"), bg="white")
clock.pack()
''' Label that shows the date'''
date = Label(window, font=("serif", 20, "bold"), bg="white")
date.pack()
''' Label that shows the temperature'''
temperature = Label(window, font=("serif", 70, "bold"), bg="white")
temperature.pack(side = LEFT)
''' Label that shows the humidity'''
humidity = Label(window, font=("serif", 70, "bold"), bg="white")
humidity.pack(side = LEFT)
''' Quit button in the top left corner'''
quit_btn = Button(window, text="Q", activebackground='red', background='white', command=quit)
quit_btn.place(x=0, y=0)
tick()
window.mainloop()