Ciao a tutti, non riesco a far andare il modulo ecn28j60 con la mio genuino micro, ho fatto svariate prove ma niente non riesco neanche a pingarlo, qualche dritta??
Di seguito vi metto il codice che sto utilizzando
#include <SPI.h>
#include <EtherCard.h>
static byte mymac[] = {0xDA,0xDB,0xDC,0x01,0x02,0x03}; //definizione dei parametri base per la connessione alla rete
static byte myip[] = {192,168,0,25};
static byte gwip[] = {192,168,0,1};
static byte dnsip[] = {132,332,81,9};
static byte netmask[] = {255,255,255,0};
byte Ethernet::buffer[700];
const int ledPin = 2;
boolean ledStatus;
//char *on = "ON";
//char *off = "OFF";
//char *tot = "bello";
char *statusLabel;
char *buttonLabel;
void setup () {
Serial.begin(9600);
Serial.println("Controllo Luci");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller"); //avviso via seriale di eventuali errori (solo per debug)
ether.staticSetup(myip, gwip); //configurazione IP statico (no DHCP) e IP del gateway
ether.hisport = 80; // porta default HTTP
Serial.println();
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
ledStatus = false;
}
void loop() {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if(pos) {
if(strstr((char *)Ethernet::buffer + pos, "GET /?status=ON") != 0) {
Serial.println("Received ON command");
ledStatus = true;
}
if(strstr((char *)Ethernet::buffer + pos, "GET /?status=OFF") != 0) {
Serial.println("Received OFF command");
ledStatus = false;
}
/*if(ledStatus) {
digitalWrite(ledPin, HIGH);
statusLabel = on;
buttonLabel = off;
} else {
digitalWrite(ledPin, LOW);
statusLabel = off;
buttonLabel = on;
}*/
BufferFiller bfill = ether.tcpOffset();
bfill.emit_p(PSTR("HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\nPragma: no-cache\r\n\r\n"
"<html><head><title>Controllo Luci</title></head>"
"<body>Stato Luci: $S "
"<a href=\"/?status=$S\"><input type=\"button\" value=\"$S\"></a>"
"</body></html>"
), statusLabel, buttonLabel, buttonLabel);
ether.httpServerReply(bfill.position());
}
}
il mio dubbio è che la libreria non sia adeguata al microcontrollore ATmega32u4.
ma poi ci sono due cose che proprio nn mi capacito perché non stampa nemmeno sul serial monitor la frase Controllo Luci, non capisco, e poi perché quando verifico lo sketch mi da erorre sulla stringa dove dichiaro le variabili char (per quello le ho messe come commento e anche la parte di programma che le utilizzava)
Vi ringrazio anticipatamente per l'attenzione