My Raspberry Pi Pool Timer — Setting up the Raspberry Pi


(See this post on the why of this project, and this post on the parts I selected to build with. In this post, I describe setting up the Raspberry Pi itself.)

Update 2013/01/12: Using wpa_supplicant to automatically reconnect to WiFi base station when needed.

This turns out to be remarkably simple:

  1. Steal the HDMI cable from the TV. (Yes, I wanted to buy one of the $1.99 HDMI cables Fry’s was advertising this month, and in spite of 172 (!) supposedly being in stock at my branch, no employee nor me could find a single one in the entire store.)
  2. Plug in a spare USB keyboard and HDMI-capable monitor.
  3. Find an old SDCard. Insert into Macbook Pro. Use the dd command to write a boot disk with Raspbian Wheezy according to these instructions. Move SDCard into slot on the Raspberry Pi.
  4. Find a spare USB power adaptor and mini-USB chord. Plug in.

Voila, it boots, and I log in just like any other Linux system. (Note: I could run mysql on this little board if I wanted to! Or Tomcat! Of course, fast it is not. But still…)

The Raspberry Pi’s HDMI output and my monitor don’t get along very well, though. Something wrong about resolution. So I quickly plug in ethernet instead to be able to ssh in, and configure /etc/network/interfaces as follows:

auto lo

iface lo inet loopback

allow-hotplug eth0
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcpmanual
wpa-ssid <my-home-network>
wpa-psk <my-password>
    wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp

The content of /etc/wpa_supplicant/wpa_supplicant.conf is:

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

network={
   ssid="<my-home-network>"
   key_mgmt=WPA-PSK
   psk="<my-password>"
}

To make my life easier, I take note of the Mac addresses of both Ethernet and Wi-Pi. I then assign them reserved DHCP IP addresses through my home DHCP server, like this in /etc/dhcp/dhcp.conf:

host pooleth {
    hardware ethernet xx:xx:xx:xx:xx:xx;
    fixed-address 192.168.1.41;
}
host poolwifi {
    hardware ethernet yy:yy:yy:yy:yy:yy;
    fixed-address 192.168.1.42;
}

I also add it to my home’s DNS server in /etc/bind/zones/home.zone:

pooleth      IN A  192.168.1.41
poolwifi     IN A  192.168.1.42
pool         IN A  192.168.1.42

Now I can ssh pool and later, http://pool/, which is much cooler.

Note, in case that isn’t clear, that DNS and DHCP setup cannot be done on the Raspberry Pi, but need to be done on whatever server controls DNS and DHCP on your home network. Perhaps it is your Wi-Fi router, perhaps you don’t have any way of doing this, in which case you’d have to find some other way of doing dynamic DNS, otherwise you’ll be chasing IP addresses for the rest of your life. In doubt, make the Raspberry Pi’s IP address static, and use that.

I think I am forgetting that I also installed the Wi-Pi driver per the instructions that came with the device. Or perhaps it worked out of the box and I just read the instructions but didn’t follow them. Regardless, it was not hard.

Now for basic software to see whether I can switch the Raspberry Pi’s I/O pins. Quickly, I find piStatus.pl, a Perl CGI script that provides a low-level web interface to the pins. I don’t bother to read the documentation, so it takes me a little while to understand which pin is which, and how it maps to what piStatus.pl shows. After some searching, I find the pinout diagram to the right, which I pin on the wall in front of me, and which sheds some clarity on the rather random-looking assignment of pins.

To improve immediate satisfaction, I solder an LED and a 470Ω resistor to some female connectors, connect them to a random I/O pin on the Raspberry Pi, and I manage to get the LED to come on and off, controlled by Firefox on my Mac via piStatus.pl running under Apache on the Raspberry Pi. The LED is very dim, but I err on the side of caution how many milli-amps I’m drawing out of the Raspberry Pi. My son complains that one can barely see the light, but sees that the project is making progress. (It’s always important that the family has some clue what one is doing!)

In the next post, I assemble the electronic components.

,