Hi, I bought a Wiznet ethernet shield, and I'm trying to run this code:
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0x90, 0xA2, 0xDA, 0x00, 0x9B, 0x36 }; //physical mac address
byte ip[] = { 192,168,1, 9 }; // ip in lan assigned to arduino
IPAddress dns1(192, 168, 1, 1);
IPAddress gg(192, 168, 1, 1);
IPAddress smask(255, 255, 255, 0);
unsigned int localPort = 12345;
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
EthernetUDP Udp;
void setup() {
// start the Ethernet and UDP:
//Ethernet.begin(mac, ip, gg, smask);
Ethernet.begin(mac,ip);
Udp.begin(localPort);
Serial.begin(9600);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
}
void abrir_pchica(void)
{
digitalWrite(7, LOW);
delay(500);
digitalWrite(7, HIGH);
return;
}
void abrir_pcorredera(void) //COREGIR
{
digitalWrite(6, LOW);
delay(1000);
digitalWrite(6, HIGH);
return;
}
void loop() {
// if there's data available, read a packet
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
int packetSize = Udp.parsePacket();
if (packetSize) {
// read the packet into packetBufffer
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
if(strcmp(packetBuffer,"a1")==0) abrir_pchica(); //PUERTA CHICA
if(strcmp(packetBuffer,"a2")==0) abrir_pcorredera(); //PUERTA CORREDERA
}
delay(10);
}
Explanation: I'm giving an IP and MAC to the shield, but it doesn't work: although the shield has a IP, when I try to ping from my pc to the shield, it fails. The code is simple: it receives a message via UDP, and activates two relays.
The funny thing is that it works when I send a broadcast packet, but it fails when sending to the specific IP the shield has.
I have already tried to do the Ethernet.begin with only MAC argument, with MAC and IP, with DNS, gateway and subnet, I have also tried to begin with DHCP instead, nothing.
When I read the shield's IP trough the serial port, the IP is the one I gave, but the shield is invisible in the network. Help please.