domingo, 13 de enero de 2013

Conexión ethernet

Para la comunicación ethernet usaremos la tarjeta ENC28J60 que no es la oficial de arduino, sin embargo es una mas económica y funciona bien.
Descargar las librerías  ethershield_v1.1_for_arduino_v1.0.zip , en la carpeta libraries de arduino existe una que se llama Ethernet, que la que se usa para la tarjeta ethernet oficial de arduino, ese directorio lo borraremos y descomprimiremos nuestras librerías que vienen con otro nombre ENC28J60  y las renombraremos a Ethernet.

Nota : cuando use 3.3v se perdía la señal, cuando subí a 5v trabajo perfectamente, pero el micro de la ethernet recalentaba

Ejemplo 1

#include "etherShield.h"
#include "ETHER_28J60.h"
static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};
static uint8_t ip[4] = {192, 168, 1, 15};                      
static uint16_t port = 80;                                    
ETHER_28J60 ethernet;
void setup()
{
  ethernet.setup(mac, ip, port);
}

void loop()
{
  if (ethernet.serviceRequest())
  {
    ethernet.print("<H1>Hello World</H1>");
    ethernet.respond();
  }
  delay(100);
}


Ejemplo 2



#include "etherShield.h"
#include "ETHER_28J60.h"

int outputPin = 6;

static uint8_t mac[6] = {0x54, 0x55, 0x58, 0x10, 0x00, 0x24};  
static uint8_t ip[4] = {192, 168, 1, 15};                      

static uint16_t port = 80;                                    

ETHER_28J60 e;

void setup()
{
  e.setup(mac, ip, port);
  pinMode(outputPin, OUTPUT);
}

void loop()
{
  char* params;
  if (params = e.serviceRequest())
  {
    e.print("<H1>Web Remote</H1>");
    if (strcmp(params, "?cmd=on") == 0)
    {
      digitalWrite(outputPin, HIGH);
      e.print("<A HREF='?cmd=off'>Turn off</A>");
    }
    else if (strcmp(params, "?cmd=off") == 0) // Modified -- 2011 12 15 # Ben Schueler
    {
      digitalWrite(outputPin, LOW);
      e.print("<A HREF='?cmd=on'>Turn on</A>");
    }
    e.respond();
  }
}





No hay comentarios:

Publicar un comentario