Learning about the Arduino Ethernet Board
- Finally got around the other day to trying the Arduino Ethernet board I got sent a while back.
- Used a 6V 1A DC power plug to power the board. Used a cross-over cable (didn't need to be) to connect to an OS X machine.
- Visited the IP address in a browser and received:
Ciao da SmartProjects
Input 0 = 483
GET / HTTP/1.1
Host: 192.168.0.2
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.16) Gecko/20080803 Camino/1.6.3 (like Firefox/2.0.0.16)
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-US,en;q=0.9,ja;q=0.8,fr;q=0.7,de;q=0.6,es;q=0.5,it;q=0.4,pt;q=0.3,pt-PT;q=0.2,nl;q=0.1
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cache-Control:
- The Input 0 section changes on each refresh.
- Arduino IDE 0012 is supplied with the Ethernet library and three example sketches: ChatServer , WebClient and WebServer
- The WebServer sketch compiles to a binary sketch size of 8866 bytes (of a 14336 byte maximum) out of the box. (I modified the IP address to match the one in the original firmware.)
- I uploaded the binary to the board via a USBtinyISP device which I had configured previously.
- The resulting output is similar to:
analog input 0 is 399
analog input 1 is 393
analog input 2 is 382
analog input 3 is 396
analog input 4 is 389
analog input 5 is 377
- I was able to get the server to drop the connection by refreshing too rapidly.
- I modified the WebServer example to serve up a Adobe Flash binary file. I used a quickly hacked together Python script bin2c.py to convert the binary file into a C byte array so it could be included into the sketch. Here is the modified sketch:
/*
* Web Server
*
* A simple web server that shows the value of the analog input pins.
*/
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 2 };
Server server(80);
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
}
#include "content.h"
void loop()
{
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == '\n' && current_line_is_blank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
//client.println("Content-Type: text/html");
client.println("Content-Type: application/x-shockwave-flash");
client.println();
// output the content
for (int i = 0; i < sizeof(content); i++) {
client.print(content[i], BYTE);
}
break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = true;
} else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
client.stop();
}
}
- Put together a rough demo which provides an interface to read (and in theory write) the pins by responding to URLs of the form: http://192.168.0.2/r/a/0 (Which in this example would return the value of the Analog Pin 0.)
- Extended the demo with a Flash application that calls the URLs repeatedly and graphs the results. For various unknown reasons it seems to max out at 2 results per second. This can probably be improved with streaming and/or buffering.
- The Arduino Ethernet board I have seems to not always be reliable in starting up.