Wednesday, May 28, 2008

Breath Progress

Here is the Arduino BBB connected with the Adafruit Ethernet shield:

Arduino BBB and Ethernet Shield

One important issue if you get the Adafruit Ethernet shield, it will be much more useful if you have an Arduino with an ATmega168, since then it can use the AF SoftSerial library.

You see, the ATmega only has one hardware serial port, and you are generally busy using that to upload programs and monitor Arduino operation during testing.  Lady Ada has put together a software serial library that doesn't suck (unlike the standard Arduino software serial library), but it depends on having an ATmega168 rather than an ATmega8.

If you have an old Arduino (like the NG), you can pick up a pre-programmed ATmega168 from Adafruit to swap for your old ATmega8.

Here is my simplified version of a Lady Ada Xport example, creating a general "httpget" example.  And yes, it works!

#include "AFSoftSerial.h"
#include "AF_XPort.h"
#include
#include

char linebuffer[256];
int lines = 0;

#define XPORT_RXPIN 2
#define XPORT_TXPIN 3
#define XPORT_RESETPIN 4
#define XPORT_DTRPIN 0  // I'm not using DTR
#define XPORT_CTSPIN 6
#define XPORT_RTSPIN 7

AF_XPort xport = AF_XPort(XPORT_RXPIN, XPORT_TXPIN, XPORT_RESETPIN, XPORT_DTRPIN, XPORT_RTSPIN, XPORT_CTSPIN);

uint8_t errno,ret;
uint32_t laststatus = 0, currstatus = 0;

void setup() {

Serial.begin(57600);
xport.begin(9600);
}

void loop()
{


ret = httpget("64.233.183.104",80,"www.google.com","/"); 

if (ret)
Serial.println("get successful");
else
Serial.println("not successful");
delay(10000);
}

uint8_t httpget(char *ipaddr,
int port,
char *hostname,
char *httppath) {
uint8_t ret;
uint8_t success = 0;

ret = xport.reset();
Serial.print("Ret: "); Serial.print(ret, HEX);

switch (ret) {
case ERROR_TIMEDOUT: {
Serial.println("Timed out on reset!");
return 0;
}
case ERROR_BADRESP: {
Serial.println("Bad response on reset!");
return 0;
}
case ERROR_NONE: {
Serial.println("Reset OK!");
break;
}
default:
Serial.println("Unknown error");
return 0;
}


// time to connect...

ret = xport.connect(ipaddr, port);
switch (ret) {
case ERROR_TIMEDOUT: {
Serial.println("Timed out on connect");
return 0;
}
case ERROR_BADRESP: {
Serial.println("Failed to connect");
return 0;
}
case ERROR_NONE: {
Serial.println("Connected..."); break;
}
default:
Serial.println("Unknown error");
return 0;
}

xport.print("GET ");
xport.print(httppath);
xport.println(" HTTP/1.1");
xport.print("Host: "); xport.println(hostname);
xport.println("");

success=0;
while (1) {
// read one line from the xport at a time
ret = xport.readline_timeout(linebuffer, 255, 3000); // 3s timeout
// if we're using flow control, we can actually dump the line at the same time!
Serial.println(linebuffer);
if (strstr(linebuffer, "HTTP/1.1 200 OK") == linebuffer)
success = 1;

if (errno == ERROR_TIMEDOUT)
Serial.println("ERROR_TIMEDOUT");

if (xport.disconnected())
Serial.println("xport.disconnected");

if (((errno == ERROR_TIMEDOUT) && xport.disconnected()) ||
((XPORT_DTRPIN == 0) &&
(linebuffer[0] == 'D') && (linebuffer[1] == 0))) {
Serial.println("\nDisconnected...");
return success;
}
}
}





Sunday, May 11, 2008

BBB for Breath-to-Breath

I am working on a breath-to-breath phy2phy project. I already had one Arduino NG around, so I purchased an Adafruit Ethernet Shield, and also a Modern Device Bare-Bones Board Arduino clone with a USB-to-TTL serial cable.

"Arduino" Bare-Bones Board

The BBB board had a couple of holes that were still filled with solder, so I had to solder wick them and then heat up a little piece of lead snipped from a resistor and used the soldering iron to heat up the lead and push through the solder-filled holes to open them up.

BBB versus Arduino


Just to be clear, standard Arduino shields do not fit on the Bare-Bones Board (so I probably should have purchased a Really Bare-Bones Board), but you can always hook it up with wires.

I am developing for the Arduino and BBB on a MacBook using the USB to TTL serial cable fro FDTI. Make sure you follow the OS X instructions on how to install the FDTI drivers. These will allow you to use either a USB cable to a Arduino or the FDTI USB to TTL cable for the BBB/RBBB. Also make sure you choose the correct ATMEGA chip from the Arduino software menu. And since there isn't much indication that the BBB works (unlike the flashing LEDs on the Arduino), so try a serial example on the BBB to convince yourself that you are uploading and running a program.

Here is the Ethernet shield on an Arduino NG:

Xport Shield on Arduino

I am awaiting two Xport directs in the post, then I can really get to business.