Loving, Graceful Machines to Watch Your Chickens With

It’s gotten cold in Detroit again, and the chickens need the usual TLC: more food, more straw, heated water dispensers, and active heating inside the coop. In previous years we’ve used a single incandescent lightbulb to keep the coop at a hospitable temperature, but this year, we’re trying something different: we’ll use an infrared heat lamp along with a daylight-simulating incandescent lamp. The heat lamp can stay on all night and not bother the birds — inconsistent lighting might have a bad impact on the birds’ health. The incandescent lamp should turn on at the pre- and post-crepuscular hours at dusk and dawn to add a bit of daylight and keep egg production up.

You may remember last year when I posted about the chicken sensor, an arduino with a temperature sensor and an ethernet shield that attached to a wireless mesh node. After the weather got warm enough, I decommissioned the chicken sensor and haven’t touched the arduino platform since. Now it is time for me to jump back into the open source embedded systems fray: either I hack together a system to toggle these lamps and monitor temperature, or my neighbors and I are going to have to run out to the coop during those crepuscular hours and fumble around with electrical switches while getting our hands pecked off by feisty young hens.

So, in the interest of avoiding bloody pecked-up hands, I’ve planned out an upgraded chicken sensor: one could call it v0.2.0 or one could call it by the codename “All Watched Over By Machines of Loving Grace.” I chose this codename because it describes how the chickens will feel.

Remote Control

JeeLink (left) and JeeNode (on breadboard, right) with FTDI (hanging off the side)This year, instead of using an Arduino with Ethernet wired to a mesh node that posts directly to Pachube, I’m going to use a JeeNode that polls a computer in my house that handles all of the posting. The JeeNodes are very cool, and JeeLabs is doing all sorts of neat things with physical computing.

I’m glad that I have taken my time with the JeeNode: while searcing through the wiki I came across a few shiny gems of projects. The shiniest by far is JeeMon. I was initially planning on writing a little node.js server to listen for temperature packets and post them somewhere on the internet, but JeeMon is a much more full and exciting solution… and an excuse to improve my tcl skills (I’ve done some quick expect scripts before but that’s it). This blog post at jeelabs has a good introduction and quickstart.

So far, JeeMon seems like a winner of a platform for DIY network physical computing projects. It’s backed by a great programmer who develops great hardware. Tcl has some nice text processing features — so much of the work in this type of project is sucking information out of sometimes-garbled strings. Its event-driven-ness makes sense with random bursts of radio-transmitted information. Finally, although it has a lot of examples dealing with the jeenode world of things, it is not at all tied to a specific platform or network technology.

Toolchains

The Arduino IDE is very, very integrated: all of the required libraries for compiling are included within the distribution. This makes it nice and easy for people to get started with Arduino, and it also makes it easier to run multiple virtual environments of different versions of the IDE. It has some built-in features to let you use your own text editor, but it’s still pretty clumsy. For past projects I’ve had to run avrdude with non-standard options to flash a device; I ended up finding where the IDE would put the compiled .hex file during the build and upload it manually. This was a pain.

I started looking around the internet for alternative build methods for arduino programs and didn’t really come up with much; there are a lot of one-off projects (see links below) but all of them rely on a forked version of the Arudino libraries, or even a partial set of those libraries. This makes development really tricky, especially if you’re including non-standard libraries.

I’d love to see the Arduino IDE expose some of the development processes via the commandline. Another option might be to do an scons setup that uses the arduino IDE’s hardware/arduino/boards.txt as a reference.

What’s next

I’m going to continue tinkering with this stuff. Expect more posts as I learn.

One experiment I’m anxious to try out is to hook a JeeLink to an OpenWRT router and run jeemon right from the router. This might make a good addition to the community wireless toolkit we’re building at The Work Department.

Notes

When using the arduino sdk to push code to a jeenode, you generally need to set serial.debug_rate to 57600 in your ~/.arduino/preferences.txt

Check your soldering on the jeenode using the voltages listed in the link below. I messed up the RST -> capacitor connection which caused unreliable uploads but didn’t interfere with anything else… kinda hard to track that one down :)

Links

Toolchain (your mileage may vary)

“create your own arduino ide!”: http://pragprog.com/magazines/2011-04/create-your-own-arduino-ide

forum topic about makefiles: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1284144128

arduino-makefile fork on github: https://github.com/pix/arduino-makefile

fix math.h compile error: http://forums.reprap.org/read.php?146,107925,107925,quote=1 (in short, add an #undef round before round is defined in avr’s math.h)

oh, this is nice: http://www.tmpsantos.com.br/en/2010/12/arduino-uno-ubuntu-cmake/

JeeNode

check board voltages against these values: http://forum.jeelabs.net/comment/3728#comment-3728

random weird project: http://engin1000.pbworks.com/w/page/37615506/RF%20Locator

Thermometers

library to read DS1820 sensors: http://milesburton.com/Dallas_Temperature_Control_Library#Example

a nice DS18B20 setup that I’m using: http://www.makershed.com/Waterproof_DS18B20_Digital_Temperature_Sensor_Ex_p/mkad37.htm

JeeMon

home: http://jeelabs.net/projects/cafe/wiki/jeemon

intro: http://jeelabs.org/2011/11/25/jeemon-for-early-birds/

Garden sensors: crow’s nest chicken coop thermometer

Clockwise from top: Fonera, Mess of cat5 cable, Arduino

The chicken sensor is in full operation.

It’s a yogurt container filled to the brim with:

  • an Arduino Duemilanove
  • an ethernet shield
  • a Fonera 2100 running OpenWRT/olsrd
  • …and a 10k thermistor sticking out the side

I was so proud when I had my little prototype all put together… but then I did a test run with the USB unplugged and, lo and behold, nothing worked.  After a solid hour or two of sifting through the internet, I found this gem-of-a-page at Pachube!  This was doubly lucky:  first off, the pachube crew concisely explained the problem I’d run into and secondly, I’d forgotten about pachube’s web service… and I promptly rewrote my code to use it instead of my janky homemade web API.  Pachube’s site is totally awesome… what a great showcase for Drupal as a web application framework.  I love purl.

lead-flavored yogurt mmmm!So in the end, I re-programed the Arduino with a special bootloader customiezd by Ladyada.  I’ve gotta say, this was a very steep learning curve for me.  I didn’t really catch on at first that, after programming the new bootloader, the Arduino wouldn’t work with the default IDE:  to trigger the bootloader, you have to send a special message over the serial line.  I did this with a little python script written by Johannes Hoff.

Another issue:  I tried to figure out the arduino IDE toolchain, but wasn’t able to.  So I ended up compiling from within the IDE and uploading the created hexfile manually, via this command:

pulsedtr.py /dev/ttyUSB0 && /usr/bin/avrdude -V -F -p m328p -P /dev/ttyUSB0 -c avrisp -b 19200 -U flash:w:Pachube_client.cpp.hex

This worked like a charm.

Also worth noting: the sample code posted on the Pachube page I linked above is a bit out-of-date.  I modified it to, among other things, only post once per minute and use the v2 API:

diff --git a/Pachube_client.pde b/Pachube_client.pde
index 1f7bd1c..d3da9bc 100644
--- a/Pachube_client.pde
+++ b/Pachube_client.pde
@@ -30,9 +30,7 @@ byte mac[] = {
   0xDA, 0xAD, 0xCA, 0xEF, 0xFE,  byte(ID) };
 
 
-byte server [] = {  //www.pachube.com
-  209, 40, 205, 190
-};
+byte server [] = { 173, 203, 98, 29 };
 
 boolean ipAcquired = false;
@@ -100,7 +92,7 @@ void loop(){
   //main function is here, at the moment it will only connect to pachube every 10 sec
   if ((millis() - previousEthernetMillis) > ethernetInterval) {
     previousEthernetMillis = millis();
-    ethernetInterval = 10000; //10 sec
+    ethernetInterval = 60000; //10 sec
     wdt_reset();
     Serial.println("wdt reset");
     updateLocalSensor();
diff --git a/functions.pde b/functions.pde
index 3b559bd..329aba8 100644
--- a/functions.pde
+++ b/functions.pde
@@ -33,38 +82,35 @@ void useEthernet(){
   if (client.connect()) {
 
     Serial.println("connected");
-    int content_length = length(analog1) + length(analog2) + length(analog3) + 2 ; 
-    //this line is to count the lenght of the content = lenght of each local sensor data + ","
-    //in this case we have 3 data so we will need 2 commas 
+    int content_length = length(analog1); 
 
-    client.print("GET /api/feeds/");
+    client.print("GET /v2/feeds/");
     client.print(REMOTEFEED);
     client.println(".csv HTTP/1.1");
-    client.println("Host: www.pachube.com");
+    client.println("Host: api.pachube.com");
     client.print("X-PachubeApiKey: ");
     client.println(APIKEY);
-    client.println("User-Agent: Arduino (Natural Fuse v`1.1)");
+    client.println("User-Agent: Arduinonioni");
     client.println();
 
-    client.print("PUT /api/feeds/");
+    client.print("PUT /v2/feeds/");
+    client.print(REMOTEFEED);
+    client.print("/datastreams/");
     client.print(LOCALFEED);
     client.println(".csv HTTP/1.1");
-    client.println("Host: www.pachube.com");
+    client.println("Host: api.pachube.com");
     client.print("X-PachubeApiKey: ");
     client.println(APIKEY);
 
-    client.println("User-Agent: Arduino (Natural Fuse v1.1)");
+    client.println("User-Agent: Arduinonioni");
     client.print("Content-Type: text/csvnContent-Length: ");
     client.println(content_length);
     client.println("Connection: close");
     client.println();

And finally, some less-geeky perspective:  This device is indeed serving a purpose as a temperature sensor for my chicken coop, but mostly I’m using it as a learning platform to experiment with outdoor sensors.  I’ll eventually be deploying similar sensors in hoop-houses to help my farmer friends monitor efficiency and better plan their growing.

I forgot one other thing:  there was a third benefit to stumbling upon Pachube:  I found another garden sensor experimentor!!!  They really had it figured out, and it drastically shifted my plans.  See their sensor system here: http://www.pachube.com/feeds/12401 with photos here:http://picasaweb.google.com/ryanferreri/HoopHouses#.  I’d never heard of the JeeNode equipment before, and it seems to be absolutely perfect for low-cost wireless sensors… and they’re so nice and skinny… could just stick em right in some PVC pipe… oh the possibilities!  The U.S. JeeNodes transmit in the 900ish-MHZ spectrum.  I can’t wait to set up a test system… the rough plan would be a network of a few JeeNodes, each placed on the edge of a hoop house with one sensor inside and one outside.  They would transmit back to a wifi router that would serve as the web uplink.  I have to find a low-power wifi router with an on-board USB chip…

But for now, my only sensor resides in that chicken coop.  Future plans: a relay switch for the coop’s light, for remote control / timer capabilities.  Gotta maximize that layer productivity.

Vote for FACT Social Justice Challenge projects!

The public voting period for this year’s FACT Social Justice Challenge ends this Friday!  Read about how to vote on projects — unfortunately it’s a bit complicated.  I should’ve written up a grant to improve their website.

There are two interesting Detroit projects, as well as a few other cool ones, that I would like to promote:

Thanks for voting!