My project for the PiRack Challenge is just a simple consolidation of what I'm currently using two Raspberry Pi's to perform: control office lighting using doorbell buttons mounted on the side of my desk (ala the hidden button in spy movies), to manage Z-wave lighting controllers via the RaZberry (Z-Wave controller) and PiFace (interface) daughter boards for the RPi.  I mounted the doorbell buttons to the side of my desk and connected them to the external switch inputs on the PiFace. 

 

I then installed the WiringPi toolkit and modified the buttons.c program (found in wiringPi/examples/PiFace/) so that it would make a system calls using wget to the RaZberry's Javascript API (see below).  I won't include the code here because it's just too ugly to share (though it works).

 

This project took me about 8 hours to get working.  This was mostly because I'm very rusty at coding in C and assembly required a little troubleshooting (e.g., docs for the PiRack jumpers appear to be backwards) and I had to visit Radio Shack to acquire a 5 volt power supply with the proper size barrel plug.

 

The whole project is built on top of the RaZberry board's Javascript API, which allows you turn turn lamp controllers on and off (also dim) via web-based calls.  Example: I'm able to turn the floor lamp (device [3]) on and off by pointing a browser or wget at the URLs below (wget example given):

 

  wget -q -O /dev/null "http://127.0.0.1:8083/ZWaveAPI/Run/devices[3].instances[0].SwitchMultilevel.Set(255)"

  wget -q -O /dev/null "http://127.0.0.1:8083/ZWaveAPI/Run/devices[3].instances[0].SwitchMultilevel.Set(0)"

 

Pluses:

  • For some reason, the aggregated design works better than the two-Pi design, in that polling the buttons have a slightly less load on the CPU (tradeoff is polling speed vs CPU load).
  • The nice thing about using the above wget calls is that you can make them via multiple devices and multiple means.  I also have the first one in a cron job, to turn the office lights on at a specific time, and  I have the second one on my home page, scripted with a delay that allows me a couple minutes to exit the room.  There's also a set of icons on my desktop which control the office lights by making the same calls.

 

Drawbacks:

  • Input polling the buttons is finicky at best.  You have to find the sweet spot for polling which doesn't hog the CPU processes, yet doesn't miss you pressing the external button.  Then there's the issue where you tend to press a button for different lengths of time at various times of day.  It works but it's a bit too finicky for my satisfaction, so I'll be experimenting with using interrupts instead of polling (as described at http://blog.oddbit.com/post/interrupts-on-the-piface).
  • Any long term use of the PiRack dictates that you find some way to mount it so that it minimizes the mechanical stress on the Pi's GPIO pins.  I imagine a fully loaded PiRack could bend pins or crack solder joints, given enough time.

 

Pending:

  • I plan on adding an Infrared control by adding the IRToy, infrared receiver, or infrared transciever.  It'll probably be the third form as my floor fan has an infrared interface and I'd love to turn it on/off from across the room.
  • I'm also planning on adding an app to my Android phone and tablet to turn the lights on and off, control the fan, etc.

 

Below is a picture of my project.  From the bottom up, it shows the PiPan (holding the RPi and the breadboard), the Raspberry Pi, the PiFace board, and the RaZBerry board.  Below the picture are the steps I used to assemble the project.

 

pirack.JPG

 

1) Install Raspbian on the SD card using

 

  dd if=2013-02-09-wheezy-raspbian.img of=/dev/sdb bs=1M

 

2) Boot from the SD and switch to root

 

3) Figure out IP address of Pi (may need to power cycle)

 

   nmap -r -v -n -sP 192.168.2.2-30

 

Above assumes that your DHCP range starts at .2.

 

Alternative: look at the "Connected Devices" tab on your router (if it has one).

 

4) Log onto the Pi and set a static interface by editing /etc/network/interfaces

 

  see http://askubuntu.com/questions/143819/how-do-i-configure-my-static-dns-in-interfaces

 

5) Reboot the Pi, log in, switch to root, and run

 

  apt-get update

  apt-get upgrade

 

Note: this takes a very long time to run.

 

6) Install Razberry software

 

  wget -q -O - http://razberry.z-wave.me/install |sudo bash

 

7) Download PiFace software

 

  wget http://pi.cs.man.ac.uk/download/install.txt

 

8) Install the PiFace software

 

  bash install.txt

 

This will create a directory called "piface" in the folder where you ran the above.

 

9) Install the Python common core modules for the Pi by running:

 

  apt-get install python{,3}-pifacecommon

 

10) Run raspi-config and navigate to "Advanced Options/SPI" and select "yes".

 

11) The PiFace needs the spi-bcm2708 module.  By default, it's on the Pi's blacklist.  To remove it from the blacklist (if it's not already), edit /etc/modprobe.d/raspi-blacklist.conf and comment out the line (i.e., add a "#" character to the start of the line).

 

12) Shutdown the Pi by running

 

  shutdown -h now

 

13) When only the red LED is lit, remove power from the Pi.

 

14) Install the PiRack and the desired daughterboards.  For my setup, which had a PiFace board on the bottom row and a Razberry board on the next one up, I had to switch the SPI CE lines for the PiFace.

 

15) Restore power to the Pi.  The LEDs on the Pi should give you an idea if it's booting or not (i.e., look for activity).  If there is none, then you'll likely need to add external power to the PiRack (I did).  If this is the case, while the Pi is off, add the external power supply to the PiRack and turn the power on to both power supplies.

 

16) Point a browser at port 8083 at the static IP (configured above).  It should list the various available interface for the Z-wave interface.  (Mine worked withe no additional fuss as I moved the already-paired Razberry card from my second PI onto the PiRack.  You'll likely need to pair you lamp controller to the Razberry before it'll work.  This can be done via the "Expert UI" interface on port 8083.)

 

17) Write your code (mine was too horrible to share) to control sense the button presses.  Note: the first four input ports are in parallel to the four buttons on the board, so you can experiment without having to add the external buttons.  I recommend starting with one of the examples provided with the PiFace or WiringPi installs and tweaking it to meet your needs.  I used the WiringPi code (link above).

 

- Tim (aka joat)