Ai pessoal problema besta pra os feras ai. Esse código aqui  oque  o autor errou foi no pino 2 do Arduíno. todas as saídas funcionam perfeitas inclusive a saída 1  mostra ON No Navegador, mais o pino não sai tensão alguma,,,

/* Äìèòðèé Îñèïîâ. https://www.youtube.com/user/d36073?feature=watch
v.01 Óïðàâëÿåì Arduino ñ Web ñòðàíèöû Webserver Ethernet ENC28J60 Enternet HR911105A Pin ON OF Relays.
-----
×òî íàì ïîíàäîáèòñÿ:
1). ENC28J60 Ethernet LAN / Network Module.
http://www.ebay.com/sch/i.html?_from=R40&_sacat=0&_nkw=ENC2...

2). Áèáëèîòåêà / Library - "ethercard".
EtherCard is a driver for the ENC28J60 chip, compatible with Arduino IDE.
https://github.com/jcw/ethercard
èëè áåðåì çäåñü. https://yadi.sk/d/R57sVoglbhTRN
3).
Ñêà÷àòü sketch.
v.01 Óïðàâëÿåì Arduino ñ Web ñòðàíèöû Webserver Ethernet ENC28J60 Enternet HR911105A Pin ON OF Relays.

-----------------------

Ïîäêëþ÷àåì Pins "ENC28J60 Module" ê Arduino Uno.
VCC - 3.3V
GND - GND
SCK - Pin 13
SO - Pin 12
SI - Pin 11
CS - Pin 10 Ìîæíî âûáðàòü ëþáîé.

Ïîäêëþ÷àåì "ENC28J60 Module" íàïðèìåð ê Router, çàãðóæàåì sketch, îòêðûâàåì ñòðàíèöó
â áðàóçåðå íàïðèìåð 192.168.1.222 , íà ñòðàíèöå ìîæåì âêëþ÷àòü âûêëþ÷àò Pins / ðåëå.
---------
Ïðèìå÷àíèå: "ENC28J60 Module" ïèòàåòñÿ îò 3.3 volts, è ïîòðåáëÿåò ïî äîêóìåíòàöèè 250mA.
Arduino Uno Ìàêñèìàëüíûé äîïóñòèìûé òîê, ïîëó÷àåìûé ñ 3V3 êîíòàêòà — 50 ìÀ.
Ó ìåíÿ ïðåêðàñíî âñ¸ ðàáîòàåò ñ 3V3 êîíòàêòà Arduino Uno.
Íà âñÿêèé ñëó÷àé, ïðåäóïðåæäàþ.
------------------
*/

#include <EtherCard.h> // Ïîäêëþ÷àåì ñêà÷àííóþ áèáëèîòåêó. https://yadi.sk/d/R57sVoglbhTRN

// MAC Address äîëæåí áûòü óíèêàëüíûì â âàøåé ñåòè. Ìîæíî ìåíÿòü.
static byte mymac[] = {
0x5A,0x5A,0x5A,0x5A,0x5A,0x5A };

// ip ñòàòè÷åñêèé / ïîñòîÿííûé Address íàøåé Web ñòðàíèöû.
static byte myip[] = {
192,168,1,222 };

// Áóôåð, ÷åì áîëüøå äàííûõ íà Web ñòðàíèöå, òåì áîëüøå ïîíàäîáèòñÿ çíà÷åíèÿ áóôåðà.
byte Ethernet::buffer[900];
BufferFiller bfill;

// Ìàññèâ çàäåéñòâîâàííûõ íîìåðîâ Pins Arduino, äëÿ óïðàâëåíèÿ íàïðèìåð 8 ðåëå.
int LedPins[] = {
2,3,4,5,6,7,8,9};

// Ìàññèâ äëÿ ôèêñàöèè èçìåíåíèé.
boolean PinStatus[] = {
1,2,3,4,5,6,7,8};

//-------------

const char http_OK[] PROGMEM =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n\r\n";

const char http_Found[] PROGMEM =
"HTTP/1.0 302 Found\r\n"
"Location: /\r\n\r\n";

const char http_Unauthorized[] PROGMEM =
"HTTP/1.0 401 Unauthorized\r\n"
"Content-Type: text/html\r\n\r\n"
"<h1>401 Unauthorized</h1>";

//------------

// Äåëàåì ôóíêöèþ äëÿ îôîðìëåíèÿ íàøåé Web ñòðàíèöû.
void homePage()
{
bfill.emit_p(PSTR("$F"
"<title>ArduinoPIN Webserver</title>"
"ArduinoPIN 1: <a href=\"?ArduinoPIN1=$F\">$F</a><br />"
"ArduinoPIN 2: <a href=\"?ArduinoPIN2=$F\">$F</a><br />"
"ArduinoPIN 3: <a href=\"?ArduinoPIN3=$F\">$F</a><br />"
"ArduinoPIN 4: <a href=\"?ArduinoPIN4=$F\">$F</a><br />"
"ArduinoPIN 5: <a href=\"?ArduinoPIN5=$F\">$F</a><br />"
"ArduinoPIN 6: <a href=\"?ArduinoPIN6=$F\">$F</a><br />"
"ArduinoPIN 7: <a href=\"?ArduinoPIN7=$F\">$F</a><br />"
"ArduinoPIN 8: <a href=\"?ArduinoPIN8=$F\">$F</a>"),

http_OK,
PinStatus[1]?PSTR("off"):PSTR("on"),
PinStatus[1]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
PinStatus[2]?PSTR("off"):PSTR("on"),
PinStatus[2]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
PinStatus[3]?PSTR("off"):PSTR("on"),
PinStatus[3]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
PinStatus[4]?PSTR("off"):PSTR("on"),
PinStatus[4]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
PinStatus[5]?PSTR("off"):PSTR("on"),
PinStatus[5]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
PinStatus[6]?PSTR("off"):PSTR("on"),
PinStatus[6]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
PinStatus[7]?PSTR("off"):PSTR("on"),
PinStatus[7]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"),
PinStatus[8]?PSTR("off"):PSTR("on"),
PinStatus[8]?PSTR("<font color=\"green\"><b>ON</b></font>"):PSTR("<font color=\"red\">OFF</font>"));
}

//------------------------

void setup()
{
Serial.begin(9600);

// Ïî óìîë÷àíèþ â Áèáëèîòåêå "ethercard" (CS-pin) = ¹ 8.
// if (ether.begin(sizeof Ethernet::buffer, mymac) == 0).
// and change it to: Ìåíÿåì (CS-pin) íà 10.
// if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0).

if (ether.begin(sizeof Ethernet::buffer, mymac,10) == 0);

if (!ether.dhcpSetup());

// Âûâîäèì â Serial ìîíèòîð IP àäðåñ êîòîðûé íàì àâòîìàòè÷åñêèé ïðèñâîèë íàø Router.
// Äèíàìè÷åñêèé IP àäðåñ, ýòî íå óäîáíî, ïåðèîäè÷åñêèé íàø IP àäðåñ áóäåò ìåíÿòüñÿ.
// Íàì ïðèä¸òñÿ êàæäûé ðàç óçíàâàòü êîé àäðåñ ó íàøåé ñòðàíèöû.
ether.printIp("My Router IP: ", ether.myip); // Âûâîäèì â Serial ìîíèòîð IP àäðåñ êîòîðûé íàì ïðèñâîèë Router.

// Çäåñü ìû ïîäìåíÿåì íàø äèíàìè÷åñêèé IP íà ñòàòè÷åñêèé / ïîñòîÿííûé IP Address íàøåé Web ñòðàíèöû.
// Òåïåðü íå âàæíî êàêîé IP àäðåñ ïðèñâîèò íàì Router, àâòîìàòè÷åñêèé áóäåì ìåíÿòü åãî, íàïðèìåð íà "192.168.1.222".
ether.staticSetup(myip);

ether.printIp("My SET IP: ", ether.myip); // Âûâîäèì â Serial ìîíèòîð ñòàòè÷åñêèé IP àäðåñ.
//-----

for(int i = 0; i <= 8; i++)
{
pinMode(LedPins[i],OUTPUT);
PinStatus[i]=false;
}
}

// --------------------------------------

void loop()
{

delay(1); // ĸðãàåì ìèêðîêîíòðîëëåð.

word len = ether.packetReceive(); // check for ethernet packet / ïðîâåðèòü ethernet ïàêåòû.
word pos = ether.packetLoop(len); // check for tcp packet / ïðîâåðèòü TCP ïàêåòû.

if (pos) {
bfill = ether.tcpOffset();
char *data = (char *) Ethernet::buffer + pos;
if (strncmp("GET /", data, 5) != 0) {
bfill.emit_p(http_Unauthorized);
}
else {

data += 5;
if (data[0] == ' ') {
homePage(); // Return home page Åñëè îáíàðóæåíî èçìåíåíèÿ íà ñòàíèöå, çàïóñêàåì ôóíêöèþ.
for (int i = 0; i <= 7; i++)digitalWrite(LedPins[i],PinStatus[i+1]);
}

// "16" = êîëè÷åñòâî ñèìâîëîâ "?ArduinoPIN1=on ".
else if (strncmp("?ArduinoPIN1=on ", data, 16) == 0) {
PinStatus[1] = true;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN2=on ", data, 16) == 0) {
PinStatus[2] = true;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN3=on ", data, 16) == 0) {
PinStatus[3] = true;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN4=on ", data, 16) == 0) {
PinStatus[4] = true;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN5=on ", data, 16) == 0) {
PinStatus[5] = true;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN6=on ", data, 16) == 0) {
PinStatus[6] = true;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN7=on ", data, 16) == 0) {
PinStatus[7] = true;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN8=on ", data, 16) == 0) {
PinStatus[8] = true;
bfill.emit_p(http_Found);
}


//------------------------------------------------------


else if (strncmp("?ArduinoPIN1=off ", data, 17) == 0) {
PinStatus[1] = false;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN2=off ", data, 17) == 0) {
PinStatus[2] = false;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN3=off ", data, 17) == 0) {
PinStatus[3] = false;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN4=off ", data, 17) == 0) {
PinStatus[4] = false;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN5=off ", data, 17) == 0) {
PinStatus[5] = false;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN6=off ", data, 17) == 0) {
PinStatus[6] = false;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN7=off ", data, 17) == 0) {
PinStatus[7] = false;
bfill.emit_p(http_Found);
}
else if (strncmp("?ArduinoPIN8=off ", data, 17) == 0) {
PinStatus[8] = false;
bfill.emit_p(http_Found);
}


//---------------------------


else {
// Page not found
bfill.emit_p(http_Unauthorized);
}
}
ether.httpServerReply(bfill.position()); // send http response
}
}

Exibições: 569

Responder esta

Respostas a este tópico

Tá russo entender isso...

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço