12/04 Status update: XBee Communication

Our forward progress on the smoker project has been a little slower than we were hoping, but we’re back on it now and have all the parts assembled to make it happen!

Today we got the critical wireless communications between the Arduino and the Mac up and running:

Here’s the perl code for the Mac side:

#!/usr/bin/perl

use warnings;
use strict;
use Device::SerialPort;

$|++;

my $port = init_serial();

my $lines = 0;
while(1) {
    my $str = $port->lookfor();
    next unless $str;
    print "$str\n";
    $lines++;
    if($lines > 5) {
        $port->write("Got 5\n");
        $lines = 0;
    }
}

sub init_serial {
    my @devs = qw(/dev/tty.usbserial-FTELR4YH /dev/tty.usbserial-A7006SAd);

    my $port = undef;
    for my $port_dev (@devs) {
        $port = Device::SerialPort->new($port_dev);
        last if $port;
    }
    if(!$port) {
        die "No known devices found to connect to serial: $!\n";
    }

    $port->databits(8);
    $port->baudrate(9600);
    $port->parity("none");
    $port->stopbits(1);

    return $port;
}

And here’s the very simple Arduino code to exercise it:

void setup() {
  Serial.begin(9600);
}

int quiet_count = 0;
void loop()
{
  if(quiet_count > 10) {
    Serial.println("ALIVE");
    quiet_count = 0;
  }
  else {
    quiet_count++;
  }
  // otherwise echo anything else sent to us
  while(Serial.available()) {
    Serial.print((char)Serial.read());
  }
  delay(100);
}

Nate will post in a bit about his threading work.

Next up is getting the Arduino-controlled power outlet built, which is the scariest portion of this project — playing with high current, high voltage AC is always fun, with a side order of adrenaline.

Leave a comment