-
Notifications
You must be signed in to change notification settings - Fork 0
Make Raspberry Pi & DHT 22 Sensor Device
- Prepare a micro SD memory card.
- Go to https://www.raspberrypi.org/downloads/raspbian/, download RASPBIAN JESSIE LITE.
- Install the downloaded RASPBIAN JESSIE LITE image into the micro SD memory card. ApplePi-Baker is recommended. https://www.tweaking4all.com/software/macosx-software/macosx-apple-pi-baker/
- Insert the installed micro SD memory card into raspberry pi, plugin the power and you're ready to start the machine.
The default username is "pi" and password is "raspberry", login to the OS and proceed to env. settings.
You can check network status by this command:
$ ifconfig
To connect raspberry pi to wifi, we need to edit the setting file:
$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Add the following lines at the end of the file:
network={
ssid="yourWifiName"
psk="yourWifiPassword"
}
If you need to give it a fixed IP (we DON'T suggest you doing so),
$ sudo nano /etc/dhcpcd.conf
Then add the following lines at the end of the file:
interface wlan0
static ip_address=***.***.***.***/24
static routers=***.***.***.***
static domain_name_servers=***.***.***.***
You might need to reboot your machine to make the change of network setting work:
$ sudo reboot
Once you successfully connect raspberry pi to internet, we can proceed to update it and install some useful function packages.
Enter the following command to check update list:
$ sudo apt-get update
then
$ sudo apt-get upgrade
We can install some useful packages, for example the wavemon (http://www.raspberrypi-spy.co.uk/2014/10/how-to-use-wavemon-to-monitor-your-wifi-connection/) is a handy tool for monitoring wifi signals, we can install it by the command:
$ sudo apt-get install wavemon
And certainly we'd like to install git:
$ sudo apt-get install git
There's some basic settings we have to change, like password, time zone, SSH allow or not, host name, etc. Enter the following command to configure.
$ sudo raspi-config
Run the following commands step by step:
$ git clone https://github.com/adafruit/Adafruit_Python_DHT.git
$ cd Adafruit_Python_DHT
$ sudo apt-get install build-essential python-dev python-openssl
$ sudo python setup.py install
Please refer here for the example content of the script:
You can create a folder for the script:
$ mkdir fileFolderName
Send the script from your local machine (MacOS or Linux) to the folder you created:
$ scp ~/sensor2api.py pi@***.***.***.***:fileFolderName/
Crontab is a tool for automatically executing given commands, we can use it to send sensor reading repeatedly or reboot the system at given time schedule.
$ crontab -e
There're 5 parameter of time settings: minute, hour, day of month (1-31), month (1-12) and day of week (1-7).
For example:
*/5 * * * * python /home/pi/sensor/sensor2api.py
3 */8 * * * sudo reboot
means automatically run sensor2api.py every 5 mins, and automatically reboot on the 3rd min every 8 hour (08:03, 16:03 & 00:03).