Selasa, 19 Desember 2017

Setting DHT22 & LCD 16x2 di Raspberry PI

Raspberry PI DHT22 humidity sensor with a LCD 16×2 display – Weather station

For a workshop I’m going to give about Raspberry PI and how to interact with the outside world, I thought for a start, why not something simple like some kind of a Weather Station.

Materials

1x Raspberry PI (I’m using b+)
1x LCD 16×2
1x DHT22 (or DHT11 or am2303) sensor
1x 10K potentiometer
1x 10K resistor
1x breadboard
Here’s the schematic in Fritzing
Weather_AICB

Connections
SensorArduino PINs
LCD displayBoardBCM
1GND
25v
3Potentiometer
47GPIO27
5GND
69GPIO22
7
8
9
10
1122GPIO25
1218GPIO24
1316GPIO23
1412GPIO18
155v
167GPIO4
DHT22
8 GPIO14
 GND
5v
After the wiring, time to connect the PI
Note: Using this wiring and the Adafruit’s LCD libraries, the LCD display will not light up when connecting the PI. After testing the example and running the python script, the LCD will light up and start displaying information

Software

DHT

dht22
For the sensor to work, we need the DHT libraries developed by Adafruit and setup the environment.
NOTE: As stated by Adafruit, this driver is work in progress
First, set up your development environment
Now, clone the Adafruit libraries
After cloned, enter the directory
Install the libraries
Everything now should be installed. Let’s try the sensor
Now, execute the test file without arguments to see the options available
We’re using DHT22 and connected to the GPIO PIN 4, so, our command line will be:
And the result:

LCD 16×2

LCD
With this method, we’re not going to use i2c or UART, but Adafruit’s libraries for LCD. They are easy to install and easy to work with.
Note: If you just want to connect the LCD, refere to this post.
Install the necessary packages
Upgrade distribute
Use PIP to install the GPIO packages
Install the necessary software modules
Try with an example
Now, you can see information on the LCD display
If you want to check the API of the LCD Adafruit’s Python Library:

The Code

The final product
Weather2