Hoje vamos apresentar um projeto básico de automação remota com o ethernet shield Enc28j60. O arduino Nano será configurado como WebServer disponibilizando uma página html para visualização e acionamento dos IOs da placa.
Pagina html para acionamento dos comandos e visualização dos status das chaves.
Antes de começar a apresentação do projeto vamos ressaltar algumas limitações do Enc28j60.
Buffer para resposta do html
A cada request, apenas uma variável de buffer para o response pode ser retornada, o Arduino Uno e Nano possuem apenas 2Kb de memória para utilização por todo o programa, dessa forma, limitamos em 1Kb a variável para criação do html de resposta, se excedermos 1Kb, o Arduino irá travar. É importante durante o desenvolvimento do projeto com Enc28j60 verificar a quantidade de caracteres que está sendo atribuída e nunca exceder 1Kb. A pagina html do projeto possui 900 caracteres, está no limite para montagem de um html de resposta. Como alternativa, podemos montar apenas a resposta no formato Json com os status dos IOs, e criar uma página html que realiza o acesso via Javascript e Ajax, dessa forma não teremos restrição para montagem do html de apresentação dos dados, mas teremos que manter e abrir o arquivo html para acessarmos a placa de automação.
Instabilidade
Verificamos alguns problemas de instabilidade e travamento do Arduino quando usamos em um mesmo projeto com outras comunicações, principalmente seriais ou com RTC, A principal diferença entre o Enc28j60 e o W5100 é que o Enc28j60 executa a a pilha TCP/IP no Arduino, enquanto que o W5100 isola em seu próprio shield, permitindo que o Arduino execute apenas o código implementado para o projeto. Existem inúmeras bibliotecas criadas para o Enc28j60 que podem ser avaliadas e testadas, mas a recomendação é usar um shield com o W5100 para criação de projetos complexos e com múltiplos dispositivos.
Mesmo com as limitações acima, o Enc28j601 pode ser usado para desenvolvimento projetos de WebServer com acionamento de saídas e leitura de sinais analógicos e digitais.
Lista de componentes
1 - Arduino NANO V3.0
1 - Placa Nano Automation Shield, a venda em nossa loja virtual.
1 - Fonte 12V
1 - Shield Enc28j60, a venda em nossa loja virtual.
3 - Chaves liga/desliga
3 - Resistores 10K
10 - Fios com conectores MODU para conexão do projeto
Conexões do projeto
Esquema elétrico de ligações
Alimentação do Enc38j60
Verifique o modelo do shield Enc28j60. As novas versões vem com 12 pinos, e possui um regulador de tensão para 5V, nesse caso, podemos ligar direto na saída 5V da placa. algumas versões do Enc28j60 são alimentadas com 3,3V e não podem ser alimentadas com 5V. A recomendação para essas versões é utilizar um LM1115 3,3V para alimentação. Algumas versões clone do Arduino não conseguem fornecer a corrente necessária para o funcionamento do módulo, ocasionando mal funcionamento e travamentos.
Esquema de ligação das chaves
Watchdog e EEPROM
Um projeto de automação, é fundamental que seja persistido em memória não volátil os comandos enviados pelo usuário, se o Arduino travar ou ocorrer interrupção da alimentação, o Arduino deve preservar nas saídas as últimos comandos enviados pelo usuário. No nosso projeto usamos o método EEPROM.write para gravar o ultimo comando para cada saída e o método EEPROM.read no setup para ler o último comando e iniciar a placa em um eventual travamento ou interrupção por falta de energia.
O projeto implementa um watchdog time com um timer de 8 segundos. Um watchdog timer é um dispositivo eletrônico temporizado que dispara um reset ao sistema se o programa principal, deixar de fazer reset no watchdog timer.
Código fonte do projeto
#include <EtherCard.h>
Vídeo de funcionamento do projeto
Verifique o modelo do shield Enc28j60. As novas versões vem com 12 pinos, e possui um regulador de tensão para 5V, nesse caso, podemos ligar direto na saída 5V da placa. algumas versões do Enc28j60 são alimentadas com 3,3V e não podem ser alimentadas com 5V. A recomendação para essas versões é utilizar um LM1115 3,3V para alimentação. Algumas versões clone do Arduino não conseguem fornecer a corrente necessária para o funcionamento do módulo, ocasionando mal funcionamento e travamentos.
Esquema de ligação das chaves
Watchdog e EEPROM
Um projeto de automação, é fundamental que seja persistido em memória não volátil os comandos enviados pelo usuário, se o Arduino travar ou ocorrer interrupção da alimentação, o Arduino deve preservar nas saídas as últimos comandos enviados pelo usuário. No nosso projeto usamos o método EEPROM.write para gravar o ultimo comando para cada saída e o método EEPROM.read no setup para ler o último comando e iniciar a placa em um eventual travamento ou interrupção por falta de energia.
O projeto implementa um watchdog time com um timer de 8 segundos. Um watchdog timer é um dispositivo eletrônico temporizado que dispara um reset ao sistema se o programa principal, deixar de fazer reset no watchdog timer.
Código fonte do projeto
#include <EtherCard.h>
#include <EEPROM.h> #include <avr/wdt.h> #define PIN_RED 6 #define PIN_GREEN 5 #define PIN_BLUE 3 #define PIN_ALARM 3 #define CHAVE_1 2 #define CHAVE_2 4 #define CHAVE_3 7 int MemSaveSaida1 = 1; int MemSaveSaida2 = 2; int MemSaveSaida3 = 3; int MemSaveSaida4 = 4; int ValueSaveSaida1 = 0; int ValueSaveSaida2 = 0; int ValueSaveSaida3 = 0; int ValueSaveSaida4 = 0; // Ip address static byte myip[] = { 192,168,1,200 }; // gateway ip address static byte gwip[] = { 192,168,1,1 }; static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; byte Ethernet::buffer[1000]; // tcp/ip send and receive buffer BufferFiller bfill; void setup(){ wdt_enable(WDTO_8S); //Watchdog 8 Segundos //Setup Inicial / descomentar build / comentar //EEPROM.write(MemSaveSaida1, 0); //EEPROM.write(MemSaveSaida2, 0); //EEPROM.write(MemSaveSaida3, 0); //EEPROM.write(MemSaveSaida4, 0); Serial.begin(57600); Serial.println("Iniciando Setup"); pinMode(A0, OUTPUT); pinMode(A1, OUTPUT); pinMode(A2, OUTPUT); pinMode(A3, OUTPUT); pinMode(PIN_ALARM, OUTPUT); ValueSaveSaida1 = EEPROM.read(MemSaveSaida1); ValueSaveSaida2 = EEPROM.read(MemSaveSaida2); ValueSaveSaida3 = EEPROM.read(MemSaveSaida3); ValueSaveSaida4 = EEPROM.read(MemSaveSaida4); digitalWrite(A0, ValueSaveSaida1); digitalWrite(A1, ValueSaveSaida2); digitalWrite(A2, ValueSaveSaida3); digitalWrite(A3, ValueSaveSaida4);
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) { Serial.println( "Failed to access Ethernet controller"); } ether.staticSetup(myip, gwip); ether.printIp("IP: ", ether.myip); ether.printIp("GW: ", ether.gwip); ether.printIp("DNS: ", ether.dnsip); analogWrite(6, 0); analogWrite(5, 0); analogWrite(3, 0); Serial.println("Finalizando Setup"); } static word homePage() { Serial.println("Gerando Home Page"); int S1 = digitalRead(A0); int S2 = digitalRead(A1); int S3 = digitalRead(A2); int S4 = digitalRead(A3); int Chave1 = digitalRead(CHAVE_1); int Chave2 = digitalRead(CHAVE_2); int Chave3 = digitalRead(CHAVE_3); int LedR = analogRead(6); int LedG = analogRead(5); int LedB = analogRead(3); int AL = digitalRead(PIN_ALARM); bfill = ether.tcpOffset(); bfill.emit_p(PSTR("<html><head>")); bfill.emit_p(PSTR("<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css' rel='stylesheet'></link>")); bfill.emit_p(PSTR("</head>")); bfill.emit_p(PSTR("<body>")); bfill.emit_p(PSTR("<div class='jumbotron'>")); bfill.emit_p(PSTR("<h2>Interface de comando</h2>")); bfill.emit_p(PSTR("<div class='row'>")); bfill.emit_p(PSTR("<div class='col-md-6'>")); bfill.emit_p(PSTR("<table class='table table-bordered'>")); bfill.emit_p(PSTR("<tbody>")); //SAIDA 1 bfill.emit_p(PSTR("<tr><td width=200px>Saida 1 - ")); if(S1 == HIGH) { bfill.emit_p(PSTR("On")); bfill.emit_p(PSTR("</td><td>")); bfill.emit_p(PSTR("<a class='btn btn-danger btn-lg' href='/S1/OFF' type='button'>Desligar</button>")); } else { bfill.emit_p(PSTR("Off")); bfill.emit_p(PSTR("</td><td>")); bfill.emit_p(PSTR("<a class='btn btn-success btn-lg' href='/S1/ON' type='button'>Ligar</button>")); } bfill.emit_p(PSTR("</td></tr>")); //SAIDA 2 bfill.emit_p(PSTR("<tr><td width=200px>Saida 2 - ")); if(S2 == HIGH) { bfill.emit_p(PSTR("On")); bfill.emit_p(PSTR("</td><td>")); bfill.emit_p(PSTR("<a class='btn btn-danger btn-lg' href='/S2/OFF' type='button'>Desligar</button>")); } else { bfill.emit_p(PSTR("Desligado")); bfill.emit_p(PSTR("</td><td>")); bfill.emit_p(PSTR("<a class='btn btn-success btn-lg' href='/S2/ON' type='button'>Ligar</button>")); } bfill.emit_p(PSTR("</td></tr>")); //SAIDA 3 bfill.emit_p(PSTR("<tr><td width=200px>Saida 3 - ")); if(S3 == HIGH) { bfill.emit_p(PSTR("Off")); bfill.emit_p(PSTR("</td><td>")); bfill.emit_p(PSTR("<a class='btn btn-danger btn-lg' href='/S3/OFF' type='button'>Desligar</button>")); } else { bfill.emit_p(PSTR("Desligado")); bfill.emit_p(PSTR("</b></td><td>")); bfill.emit_p(PSTR("<a class='btn btn-success btn-lg' href='/S3/ON' type='button'>Ligar</button>")); } bfill.emit_p(PSTR("</td></tr>")); //SAIDA 4 bfill.emit_p(PSTR("<tr><td width=200px>Saida 4 - ")); if(S4 == HIGH) { bfill.emit_p(PSTR("Ligado")); bfill.emit_p(PSTR("</td><td>")); bfill.emit_p(PSTR("<a class='btn btn-danger btn-lg' href='/S4/OFF' type='button'>Desligar</button>")); } else { bfill.emit_p(PSTR("Desligado")); bfill.emit_p(PSTR("</td><td>")); bfill.emit_p(PSTR("<a class='btn btn-success btn-lg' href='/S4/ON' type='button'>Ligar</button>")); } bfill.emit_p(PSTR("</td></tr>")); bfill.emit_p(PSTR("<tr><td colspan=2>Chave 1 - ")); if(Chave1 == HIGH) { bfill.emit_p(PSTR("On")); } else { bfill.emit_p(PSTR("Off")); } bfill.emit_p(PSTR("<br>")); bfill.emit_p(PSTR("Chave 2 - ")); if(Chave2 == HIGH) { bfill.emit_p(PSTR("On")); } else { bfill.emit_p(PSTR("Off")); } bfill.emit_p(PSTR("<br>")); bfill.emit_p(PSTR("Chave 3 - ")); if(Chave3 == HIGH) { bfill.emit_p(PSTR("On")); } else { bfill.emit_p(PSTR("Off")); } bfill.emit_p(PSTR("</td></tr>")); bfill.emit_p(PSTR("</tbody>")); bfill.emit_p(PSTR("</table>")); bfill.emit_p(PSTR("</div>")); bfill.emit_p(PSTR("</body>")); bfill.emit_p(PSTR("</html>")); return bfill.position(); } void loop(){ WebServer(); wdt_reset(); //diReset WatchDog } void WebServer() { word len = ether.packetReceive(); word pos = ether.packetLoop(len); // char* dados =(char *)Ethernet::buffer + pos; // if(pos >0) // { // Serial.println(dados); // } if(strstr((char *)Ethernet::buffer + pos, "GET /S1/ON") != 0) { Serial.println("Received ON command"); digitalWrite(A0, HIGH); EEPROM.write(MemSaveSaida1, 1); } if(strstr((char *)Ethernet::buffer + pos, "GET /S1/OFF") != 0) { Serial.println("Received OFF command"); digitalWrite(A0, LOW); EEPROM.write(MemSaveSaida1, 0); } if(strstr((char *)Ethernet::buffer + pos, "GET /S2/ON") != 0) { Serial.println("Received ON command"); digitalWrite(A1, HIGH); EEPROM.write(MemSaveSaida2, 1); } if(strstr((char *)Ethernet::buffer + pos, "GET /S2/OFF") != 0) { Serial.println("Received OFF command"); digitalWrite(A1, LOW); EEPROM.write(MemSaveSaida2, 0); } if(strstr((char *)Ethernet::buffer + pos, "GET /S3/ON") != 0) { Serial.println("Received ON command"); digitalWrite(A2, HIGH); EEPROM.write(MemSaveSaida3, 1); } if(strstr((char *)Ethernet::buffer + pos, "GET /S3/OFF") != 0) { Serial.println("Received OFF command"); digitalWrite(A2, LOW); EEPROM.write(MemSaveSaida3, 0); } if(strstr((char *)Ethernet::buffer + pos, "GET /S4/ON") != 0) { Serial.println("Received ON command"); digitalWrite(A3, HIGH); EEPROM.write(MemSaveSaida4, 1); } if(strstr((char *)Ethernet::buffer + pos, "GET /S4/OFF") != 0) { Serial.println("Received OFF command"); digitalWrite(A3, LOW); EEPROM.write(MemSaveSaida4, 0); } if(strstr((char *)Ethernet::buffer + pos, "GET /R/ON") != 0) { Serial.println("Received OFF command"); analogWrite(5, 255); } if(strstr((char *)Ethernet::buffer + pos, "GET /R/OFF") != 0) { Serial.println("Received OFF command"); analogWrite(5, 0); } if(strstr((char *)Ethernet::buffer + pos, "GET /G/ON") != 0) { Serial.println("Received OFF command"); analogWrite(6, 255); } if(strstr((char *)Ethernet::buffer + pos, "GET /G/OFF") != 0) { Serial.println("Received OFF command"); analogWrite(6, 0); } if(strstr((char *)Ethernet::buffer + pos, "GET /B/ON") != 0) { Serial.println("Received OFF command"); analogWrite(3, 255); } if(strstr((char *)Ethernet::buffer + pos, "GET /B/OFF") != 0) { Serial.println("Received OFF command"); analogWrite(3, 0); } if (pos) { ether.httpServerReply(homePage()); } }
Acessando pelo browser com o ip http://192.168.1.200 configurado no projeto a página de monitoramento é aberta.
Vídeo de funcionamento do projeto
Clique aqui para download da biblioteca EtherCad utilizada no projeto;
Atualização:
O código fonte abaixo adiciona na interface o comando de led RGB.
/* Sergio Mokshin Automação Livre Fev/2015 */ #include <EtherCard.h> #include <EEPROM.h> #include <avr/wdt.h> #define PIN_RED 6 #define PIN_GREEN 5 #define PIN_BLUE 3 #define PIN_ALARM 3 #define CHAVE_1 2 #define CHAVE_2 4 #define CHAVE_3 7 int MemSaveSaida1 = 1; int MemSaveSaida2 = 2; int MemSaveSaida3 = 3; int MemSaveSaida4 = 4; int MemSaveRed = 5; int MemSaveBlue = 6; int MemSaveGreen = 7; int ValueSaveSaida1 = 0; int ValueSaveSaida2 = 0; int ValueSaveSaida3 = 0; int ValueSaveSaida4 = 0; int ValueSaveRed = 0; int ValueSaveBlue = 0; int ValueSaveGreen = 0; // 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[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; byte Ethernet::buffer[1100]; // tcp/ip send and receive buffer BufferFiller bfill; void setup(){ wdt_enable(WDTO_8S); //Watchdog 8 Segundos //Setup Inicial / descomentar build / comentar //EEPROM.write(MemSaveSaida1, 0); //EEPROM.write(MemSaveSaida2, 0); //EEPROM.write(MemSaveSaida3, 0); //EEPROM.write(MemSaveSaida4, 0); Serial.begin(38400); Serial.println("Iniciando Setup"); pinMode(A0, OUTPUT); pinMode(A1, OUTPUT); pinMode(A2, OUTPUT); pinMode(A3, OUTPUT); pinMode(PIN_ALARM, OUTPUT); ValueSaveSaida1 = EEPROM.read(MemSaveSaida1); ValueSaveSaida2 = EEPROM.read(MemSaveSaida2); ValueSaveSaida3 = EEPROM.read(MemSaveSaida3); ValueSaveSaida4 = EEPROM.read(MemSaveSaida4); ValueSaveRed = EEPROM.read(MemSaveRed); ValueSaveBlue = EEPROM.read(MemSaveBlue); ValueSaveGreen = EEPROM.read(MemSaveGreen); digitalWrite(A0, ValueSaveSaida1); digitalWrite(A1, ValueSaveSaida2); digitalWrite(A2, ValueSaveSaida3); digitalWrite(A3, ValueSaveSaida4); analogWrite(5, ValueSaveRed); analogWrite(6, ValueSaveGreen); analogWrite(3, ValueSaveBlue); if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) { Serial.println( "Failed to access Ethernet controller"); } ether.staticSetup(myip, gwip); ether.printIp("IP: ", ether.myip); ether.printIp("GW: ", ether.gwip); ether.printIp("DNS: ", ether.dnsip); Serial.println("Finalizando Setup"); } static word homePage() { Serial.println("Gerando Home Page"); int S1 = digitalRead(A0); int S2 = digitalRead(A1); int S3 = digitalRead(A2); int S4 = digitalRead(A3); int Chave1 = digitalRead(CHAVE_1); int Chave2 = digitalRead(CHAVE_2); int Chave3 = digitalRead(CHAVE_3); int LedR = analogRead(6); int LedG = analogRead(5); int LedB = analogRead(3); int AL = digitalRead(PIN_ALARM); bfill = ether.tcpOffset(); bfill.emit_p(PSTR("<html><head>")); bfill.emit_p(PSTR("<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css' rel='stylesheet'></link>")); bfill.emit_p(PSTR("</head>")); bfill.emit_p(PSTR("<body>")); bfill.emit_p(PSTR("<div class='jumbotron'>")); bfill.emit_p(PSTR("<h2>Interface de comando</h2>")); bfill.emit_p(PSTR("<div class='row'>")); bfill.emit_p(PSTR("<div class='col-md-6'>")); //SAIDA 1 if(S1 == HIGH) { bfill.emit_p(PSTR("<a class='btn btn-success btn-lg' href='/S1/OFF' type='button'>S1 - ON -> Desligar</button></a>")); } else { bfill.emit_p(PSTR("<a class='btn btn-danger btn-lg' href='/S1/ON' type='button'>S1 - OFF -> Ligar</button></a>")); } bfill.emit_p(PSTR("<br><br>")); //SAIDA 2 if(S2 == HIGH) { bfill.emit_p(PSTR("<a class='btn btn-success btn-lg' href='/S2/OFF' type='button'>S2 - ON -> Desligar</button></a>")); } else { bfill.emit_p(PSTR("<a class='btn btn-danger btn-lg' href='/S2/ON' type='button'>S2 - OFF -> Ligar</button></a>")); } bfill.emit_p(PSTR("<br><br>")); //SAIDA 3 if(S3 == HIGH) { bfill.emit_p(PSTR("<a class='btn btn-success btn-lg' href='/S3/OFF' type='button'>S3 - ON -> Desligar</button></a>")); } else { bfill.emit_p(PSTR("<a class='btn btn-danger btn-lg' href='/S3/ON' type='button'>S3 - OFF -> Ligar</button></a>")); } bfill.emit_p(PSTR("<br><br>")); //SAIDA 4 if(S4 == HIGH) { bfill.emit_p(PSTR("<a class='btn btn-success btn-lg' href='/S4/OFF' type='button'>S4 - ON -> Desligar</button></a>")); } else { bfill.emit_p(PSTR("<a class='btn btn-danger btn-lg' href='/S4/ON' type='button'>S4 - OFF -> Ligar</button></a>")); } bfill.emit_p(PSTR("<br><br>")); //RGB Red if(ValueSaveRed == 255) { bfill.emit_p(PSTR("<a class='btn btn-success btn-lg' href='/R/OFF' type='button'>Red - ON -> Desligar</button></a>")); } else { bfill.emit_p(PSTR("<a class='btn btn-danger btn-lg' href='/R/ON' type='button'>Red - OFF -> Ligar</button></a>")); } bfill.emit_p(PSTR("<br><br>")); //RGB Green if(ValueSaveGreen == 255) { bfill.emit_p(PSTR("<a class='btn btn-success btn-lg' href='/G/OFF' type='button'>Green - ON -> Desligar</button></a>")); } else { bfill.emit_p(PSTR("<a class='btn btn-danger btn-lg' href='/G/ON' type='button'>Green - OFF -> Ligar</button></a>")); } bfill.emit_p(PSTR("<br><br>")); //RGB Blue if(ValueSaveBlue == 255) { bfill.emit_p(PSTR("<a class='btn btn-success btn-lg' href='/B/OFF' type='button'>Blue - ON -> Desligar</button></a>")); } else { bfill.emit_p(PSTR("<a class='btn btn-danger btn-lg' href='/B/ON' type='button'>Blue - OFF -> Ligar</button></a>")); } bfill.emit_p(PSTR("<br><br>")); bfill.emit_p(PSTR("Chave 1 - ")); if(Chave1 == HIGH) { bfill.emit_p(PSTR("On")); } else { bfill.emit_p(PSTR("Off")); } bfill.emit_p(PSTR("<br>")); bfill.emit_p(PSTR("Chave 2 - ")); if(Chave2 == HIGH) { bfill.emit_p(PSTR("On")); } else { bfill.emit_p(PSTR("Off")); } bfill.emit_p(PSTR("<br>")); bfill.emit_p(PSTR("Chave 3 - ")); if(Chave3 == HIGH) { bfill.emit_p(PSTR("On")); } else { bfill.emit_p(PSTR("Off")); } bfill.emit_p(PSTR("</div>")); bfill.emit_p(PSTR("</body>")); bfill.emit_p(PSTR("</html>")); return bfill.position(); } void loop(){ WebServer(); wdt_reset(); //diReset WatchDog } void WebServer() { word len = ether.packetReceive(); word pos = ether.packetLoop(len); // char* dados =(char *)Ethernet::buffer + pos; // if(pos >0) // { // Serial.println(dados); // } if(strstr((char *)Ethernet::buffer + pos, "GET /S1/ON") != 0) { Serial.println("Received ON command"); digitalWrite(A0, HIGH); EEPROM.write(MemSaveSaida1, 1); } if(strstr((char *)Ethernet::buffer + pos, "GET /S1/OFF") != 0) { Serial.println("Received OFF command"); digitalWrite(A0, LOW); EEPROM.write(MemSaveSaida1, 0); } if(strstr((char *)Ethernet::buffer + pos, "GET /S2/ON") != 0) { Serial.println("Received ON command"); digitalWrite(A1, HIGH); EEPROM.write(MemSaveSaida2, 1); } if(strstr((char *)Ethernet::buffer + pos, "GET /S2/OFF") != 0) { Serial.println("Received OFF command"); digitalWrite(A1, LOW); EEPROM.write(MemSaveSaida2, 0); } if(strstr((char *)Ethernet::buffer + pos, "GET /S3/ON") != 0) { Serial.println("Received ON command"); digitalWrite(A2, HIGH); EEPROM.write(MemSaveSaida3, 1); } if(strstr((char *)Ethernet::buffer + pos, "GET /S3/OFF") != 0) { Serial.println("Received OFF command"); digitalWrite(A2, LOW); EEPROM.write(MemSaveSaida3, 0); } if(strstr((char *)Ethernet::buffer + pos, "GET /S4/ON") != 0) { Serial.println("Received ON command"); digitalWrite(A3, HIGH); EEPROM.write(MemSaveSaida4, 1); } if(strstr((char *)Ethernet::buffer + pos, "GET /S4/OFF") != 0) { Serial.println("Received OFF command"); digitalWrite(A3, LOW); EEPROM.write(MemSaveSaida4, 0); } if(strstr((char *)Ethernet::buffer + pos, "GET /R/ON") != 0) { Serial.println("Received OFF command"); analogWrite(5, 255); EEPROM.write(MemSaveRed, 255); ValueSaveRed = 255; } if(strstr((char *)Ethernet::buffer + pos, "GET /R/OFF") != 0) { Serial.println("Received OFF command"); analogWrite(5, 0); EEPROM.write(MemSaveRed, 0); ValueSaveRed = 0; } if(strstr((char *)Ethernet::buffer + pos, "GET /G/ON") != 0) { Serial.println("Received OFF command"); analogWrite(6, 255); EEPROM.write(MemSaveGreen, 255); ValueSaveGreen = 255; } if(strstr((char *)Ethernet::buffer + pos, "GET /G/OFF") != 0) { Serial.println("Received OFF command"); analogWrite(6, 0); EEPROM.write(MemSaveGreen, 0); ValueSaveGreen = 0; } if(strstr((char *)Ethernet::buffer + pos, "GET /B/ON") != 0) { Serial.println("Received OFF command"); analogWrite(3, 255); EEPROM.write(MemSaveBlue, 255); ValueSaveBlue = 255; } if(strstr((char *)Ethernet::buffer + pos, "GET /B/OFF") != 0) { Serial.println("Received OFF command"); analogWrite(3, 0); EEPROM.write(MemSaveBlue, 0); ValueSaveBlue = 0; } if (pos) { ether.httpServerReply(homePage()); } }
Guias de referência / apoio
http://www.tweaking4all.com/hardware/arduino/arduino-enc28j60-ethernet/
http://nathanhein.com/2013/02/getting-arduino-online-with-an-enc28j60/
https://github.com/jcw/ethercard/blob/master/README.md
Fantástico trabalho. Parabéns.
ResponderExcluirBoa noite, pq as saídas são analogicas? E pq a troca para saídas digitais não funcionam?
ResponderExcluir