OK, Instructables is really having some strange issues, Once again the Intro disappeared, now the history is gone, and I’ve had to recreate the Intro from a PDF download.
I had some issues with Kingston SD Cards, but the SanDisk cards I’m using now have run for weeks without issues, so I’m changing the parts list to reflect that.
Also, after some 49 days, 16 hours, the display flatlines, as the reading routines start returning the same number over and over again. A reboot clears it, so just reboot once a month until I figure out what’s up.
Over the past summer, my vacation home had a small water leak for three months, and I realized that had I been measuring the humidity in the effected area, I’d have
seen it go to 100% for a long time and I could have dispatched someone to fix the small problem before it became a big one.
And since I’ve been playing with Raspberry Pi computers for a while now, and saw an inexpensive temperature/humidity sensor on AdaFruit, I had all the pieces I needed
to implement an inexpensive network-connected monitor.
The Bill Of Materials (BOM):
1) Raspberry Pi Model B
3) SD Card
4) Temperature/Humidity sensor
5 ) Power Supply (I use PoE splitters, but any 5V 1A Micro-USB supply will work)
I used the following exact parts, but obvious substitutions can be made to match local conditions and the state of your junk box. Shipping and the availability of bundles
may effect your final price.
$35.00 RPi http://www.newark.com/raspberry-pi/raspbrry-modb-…
$ 8.12 Case http://thepihut.com/products/classic-raspberry-pi… (5.99 Euros)
$ 6.99 SD Card (Sandisk, not Kingston)
$15.00 Sensor http://www.adafruit.com/products/393
$15.99 PoE Splitter http://www.newegg.com/Product/Product.aspx?Item=N…
And a few other miscellaneous things like hand tools, soldering iron, hot melt glue gun, small pieces of plastic wood, etc.
Step 1: Physical assembly
Split the case, find the hardware bag inside, and set the rubber feet aside for later.
Attach the Raspberry Pi to the case bottom with the supplied hardware.
Remove the GPIO knockout with a razor blade or Xacto knife and snap the two case halves together.
To keep the power dissipation of the power supply and Raspberry Pi from effecting the sensor readings, I cut a piece of Azek plastic lumber about 1.1 x 2.4 x 0.75 inches as a standoff.
Heat up your hot-melt glue gun and stack the parts as in the picture. You’ll have a few seconds to make the alignment perfect before the glue sets, so get the alignment close before you press the parts together. Be careful not to use so much glue that it extrudes from the edges of the seams or extrudes into the case, where it might interfere with the SD card connector.
1) Glue the sensor to the standoff
2) Glue the standoff to the top half of the case. Be careful not to block the LED cutouts on the one side or the ribbon cable cutout for the camera on the other side.
3) Glue the case bottom to the top of the PoE adapter. Make sure the “LAN Out” connector is on the same side as the Raspberry Pi Ethernet adapter.
4) Stick the 4 rubber feet to the bottom of the power adapter.
5) Ensure the voltage-output selection switch is set to 5V. Put a dab of hot-melt glue in the switch to prevent it from being changed and destroying your Raspberry Pi.
Step 2: Electrical Assembly
The White wire from the sensor is a spare ground, and is not needed. Cut it off inside the sensor case, being careful not to cut any of the other wires.
Braid the other three wires to keep them together, and cut them off about 3.5 inches long.
Prepare a 5-pin single inline female connector (cut from https://www.sparkfun.com/products/115 or equivalent), and solder the wires to it:
1) Red (+3.3V)
2) No Connection
3) No Connection
4) Yellow (Data)
5) Black (Ground)
Plug the connector into the GPIO on the Raspberry Pi so that pin 1 on the connector (red wire) is on pin 1 of the GPIO connector (label P1 on the board, upper right in the picture). Note that the Red wire is on GPIO Pin 1 (+3.3V), the Yellow wire is on GPIO pin 7 (GPIO 4), and the Black wire is on GPIO Pin 9 (Ground).
Tuck the excess wire into the case.
Use a short CAT5 cable (something like http://www.monoprice.com/Product?c_id=102&cp_id=10232&cs_id=1023201&p_id=7505 ) to connect the LAN OUT on the PoE splitter and the Raspberry Pi Ethernet jack. Twist it up to make it stay close to the case.
Take the PoE output cable and a Micro-USB connector or cable and solder them together. If using an AdaFruit http://www.adafruit.com/products/1390 Micro-USB connector, wire it up as shown at http://learn.adafruit.com/assets/12402 , if using a cut-off cable, determine +5 and Gnd wires with a multimeter. Note that the TP-Link wire with the white stripe is POSITIVE.
Step 3: Raspberry Pi software setup
Getting the basic Raspberry Pi software up and running has been documented elsewhere, but basically, go to:
download the latest NOOBS (v1.3.2 as of this writing)
Format the SD card using the SD card tool at https://www.sdcard.org/downloads/formatter_4/
Unzip the NOOBS file and put the contents at the root of the SD card.
Insert the SD card into the Raspberry Pi
Connect a keyboard, monitor, mouse, and LAN cable to the Raspberry Pi and connect the power supply (when you plug the PoE splitter into the LAN cable, the Raspberry Pi will power up).
Select the Raspian distribution and install it.
While that’s installing, select English-US keyboard, which autoselects US Keymap
On first boot, the raspi-config utility will run.
Select Console Login as the default on boot
Change Locale to en_US UTF-8
Set timezone for your location
Set keyboard to Generic 105-key, English US
Enable the camera
change the hostname to something memorable (I used ‘rpithon’ for Raspberry Pi Temp/Humid On Net)
set 16M memory split as we’ll be running headless
Now you can either continue to use the console or ssh to it from another machine. From my Mac I can just say:
and log in using the password ‘raspberry’. If your router doesn’t do the DNS to help you find ‘rpithon’ then make note of the IP address on the console and use that instead.
Update everything (this will take a while):
sudo apt-get update
sudo apt-get upgrade
Since this is going to be a LAN-only device, I get sick of playing “Mother May I?” with sudo, and I want to avoid any permissions problems with the additional software, so let’s enable the root user and delete the pi user:
sudo passwd root
<rootpassword> repeated twice
log back in as root user (or ssh root@rpithon) using the password selected above
remove pi user:
deluser -remove-home pi
I prefer Emacs, and don’t want all the X-Windows stuff, so:
apt-get install emacs23-nox
Tell it to check the disk (SD Card) every time it boots:
tune2fs -c 1 /dev/mmcblk0p6
change X11Forwarding to no
service ssh restart
Step 4: Setting up LAMP server (web server)
So we want to be able to see the graphs we’ll be generating (below), so we need to install a LAMP server.
Linux is the operating system you are using (Raspian is a version of Debian, which is one of the common flavors of Linux)
Apache is the name of the web server software
MySQL is a SQL (Standard Query Language) database interface. Databases sound really scary, but they are easy to use for simple things once you get used to them.
PHP and Perl are programming languages that are commonly used with websites, though we’ll be using the Raspberry Pi standard Python for graphing the data and ‘creating’ the website.
apt-get install apache2 php5 mysql-client mysql-server vsftpd
This takes a while to install. Midway through it’ll ask you for a MySQL password, pick one memorable, I’ll use ‘password’ for this tutorial.
Now you should be able to browse to http://rpithon (or http://<IP ADDRESS> if the DNS doesn’t work) and see a demo web page. Try to edit /var/www/index.html and see if your changes show up when you refresh the webpage.
Step 5: Ez_setup, MySQL, matplotlib
ez_setup is a Python program that loads some nice addons (think of it as apt-get on steroids)
These next steps install some integration between Python and MySQL:
apt-get install python-mysqldb
apt-get install libmysqlclient-dev
We’ll be using the wonderful, powerful, and free(!) matplotlib for graphing our data, though we won’t be using much of its power.
apt-get install libblas-dev liblapack-dev python-dev libatlas-base-dev gfortran python-setuptools python-scipy python-matplotlib
Step 6: WiringPi – GPIO interface
Gordon Henderson has created a wonderful programming interface for the GPIO pins, including some drivers for the esoteric interface that our Temperature/Humidity sensor uses.
For more detail: Raspberry Pi Temperature & Humidity Network Monitor