Buenas.
Estoy intentado controlar el apagado y encendido de un Rele a través de un modulo Ethernet Arduino y no me funciona.
Material :
Arduino Micro
Ethernet Shield
Rele Songle
DC DC 12VDC- 3.3VDC
Libreria EtherCard Master .
Este es el codido usado .
#include <EtherCard.h>
#include <OneWire.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x00,0x1C,0xE1,0x00,0x90,0x02 };
//pines reservados 13,12,11,8
// ethernet interface ip address
static byte myip[] = { 192,2,1,203 };
// gateway ip address
static byte gwip[] = { 192,2,1,1 };
//RELE
int pin_rele=9;
int estado_rele=0;
//TEMPERATURA
int DS18S20_Pin=10; //DS18S20 Signal pin on digital 10
//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 10
byte Ethernet::buffer[700];
static uint32_t timer;
// called when a ping comes in (replies to it are automatic)
static void gotPinged (byte* ptr) {
ether.printIp(">>> ping from: ", ptr);
}
void setup () {
//RELE
pinMode(pin_rele, OUTPUT);
digitalWrite(pin_rele,LOW);
Serial.begin(57600);
Serial.println("\n[pings]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println(F("Failed to access Ethernet controller"));
/if (!ether.dhcpSetup())
Serial.println(F("DHCP failed"));/
ether.staticSetup(myip, gwip);
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
#if 1
// use DNS to locate the IP address we want to ping
if (!ether.dnsLookup(PSTR("www.google.com")))
Serial.println("DNS failed");
#else
ether.parseIp(ether.hisip, "74.125.77.99");
#endif
ether.printIp("SRV: ", ether.hisip);
// call this to report others pinging us
ether.registerPingCallback(gotPinged);
timer = -9999999; // start timing out right away
Serial.println();
}
void loop () {
word len = ether.packetReceive(); // go receive new packets
word pos = ether.packetLoop(len); // respond to incoming pings
// report whenever a reply to our outgoing ping comes back
if (len > 0 && ether.packetLoopIcmpCheckReply(ether.hisip)) {
Serial.print(" ");
Serial.print((micros() - timer) * 0.001, 3);
Serial.println(" ms");
if (estado_rele==0)
{
estado_rele=1;
digitalWrite(pin_rele,HIGH);
}
else
{
estado_rele=0;
digitalWrite(pin_rele,LOW);
}
}
// ping a remote server once every few seconds
if (micros() - timer >= 5000000) {
ether.printIp("Pinging: ", ether.hisip);
timer = micros();
ether.clientIcmpRequest(ether.hisip);
}
}
Una vez conectado todo , Pin OUT entre Arduino Micro y Modulo Ethernet :
Veis algún problema ?
Gracias.