Monday, December 26, 2016

Barebone arduino ethernet.

Notice: use at your own risk.

If you have an Arduino with a removable chip, then you can use that to program the chip. Otherwise there are circuits to program the standalone Arduino. See "" for more details".


The bare Arduino setup.

You need a power source not shone. We used a 4 D size battery setup. Barebones setup before adding ethernet:


 Downloaded the latest Arduino and Ethercard software. Loaded both of them on the computer. Imported code for a simple web server.

// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <>

#include <EtherCard.h>

#define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)

// ethernet interface ip address
static byte myip[] = { 192,168,1,200 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x28 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
    "Service Temporarily Unavailable"
    "<h3>This service is currently unavailable</h3>"
      "The main server is currently off-line.<br />"
      "Please try again later."

void setup(){
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
    Serial.println( "Failed to access Ethernet controller");
  ether.staticSetup(myip, gwip);
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip); 
  ether.printIp("DNS: ", ether.dnsip); 

void loop(){
  // wait for an incoming TCP packet, but ignore its contents
  if (ether.packetLoop(ether.packetReceive())) {
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);

Finished setup:

No comments:

Post a Comment