[已解决]enc28J60 网页控制LED灯
本帖最后由 dkm382638608 于 2015-4-11 23:51 编辑按照,大神翻译帖子:http://www.geek-workshop.com/thread-2257-1-1.html
arduino mega 2号数字线接LED灯
然后无法响应网页按钮(灯不亮),enc28J60串口也没任何信息
后来经过布列松的指点找到是MAC地址有问题,同时更加感谢弘毅大大一语道破问题所在!也感谢zoologist的热心回答。
把 MAC 地址修改为:0x74,0x69,0x69,0x2D,0x30,0xE8 即可
如图:
arduino:
网页:
enc28J60接线如下:
SO --- 50
SI ---51
SCK-- 52
CS --- 53
GND--GND
VCC--3.3V
RST--RST
Arduino 代码:
#include <EtherCard.h>
static byte mymac[] = {0xDD,0xDD,0xDD,0x00,0x00,0x01};//这里是问题所在
static byte myip[] = {192,168,2,1};
byte Ethernet::buffer;
const int ledPin = 2;
boolean ledStatus;
char* on = "ON";
char* off = "OFF";
char* statusLabel;
char* buttonLabel;
void setup () {
Serial.begin(57600);
Serial.println("WebLed Demo");
if (!ether.begin(sizeof Ethernet::buffer, mymac, 53))
Serial.println( "Failed to access Ethernet controller");
else
Serial.println("Ethernet controller initialized");
if (!ether.staticSetup(myip))
Serial.println("Failed to set IP address");
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>WebLed</title></head>"
"<body>LED Status: $S "
"<a><input type=\"button\" value=\"$S\" onClick=\"location.href='/?status=$S';\"></a>"
"</body></html>"
), statusLabel, buttonLabel, buttonLabel);
ether.httpServerReply(bfill.position());
}
}
查看debug信息哈
如果没有任何信息,那么还是你代码出问题了
另外,建议你去看原文,这个教程翻译的不错,只是太多年过去了库有一些变化,比如 mask的名称变了之类的
zoologist 发表于 2015-4-11 21:51 static/image/common/back.gif
查看debug信息哈
如果没有任何信息,那么还是你代码出问题了
debug信息?请问去哪里查看 dkm382638608 发表于 2015-4-11 21:52 static/image/common/back.gif
debug信息?请问去哪里查看
哦 就是串口信息
他的例子写的都很好 串口信息很全 zoologist 发表于 2015-4-11 21:58 static/image/common/back.gif
哦 就是串口信息
他的例子写的都很好 串口信息很全
是啊 这个就是问题,我郁闷的就是没有串口信息
除了一开始显示
WebLed Demo
Ethernet controller initialized
然后就再也没有信息了
http://image.geek-workshop.com/forum/201504/11/210144hhz4h3d0hlvhah2o.jpg 5v供电么? zoologist 发表于 2015-4-11 22:35 static/image/common/back.gif
5v供电么?
3.3V 外接电源 已共地 这个能不能控制多个LED的 布列松 发表于 2015-4-11 22:39 static/image/common/back.gif
这个能不能控制多个LED的
恩恩 我就是原原本本按照教程的 就是没法点亮LED 串口也没用反馈信息 我有代码,不用网页的,直接登陆enc28j60的ip地址就可以控制
#include <EtherCard.h>
static byte mymac[] = {0x74,0x69,0x69,0x2D,0x30,0x31}; ///不要修改这里,如果不行再试修改
static byte myip[] = {192,168,1,180};
byte Ethernet::buffer;
const int ledPin = 3;
boolean ledStatus;
char* on = "ON";
char* off = "OFF";
char* statusLabel;
char* buttonLabel;
void setup () {
Serial.begin(9600);
Serial.println("WebLed Demo");
if (!ether.begin(sizeof Ethernet::buffer, mymac, 10))
Serial.println( "Failed to access Ethernet controller");
else
Serial.println("Ethernet controller initialized");
if (!ether.staticSetup(myip))
Serial.println("Failed to set IP address");
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>WebLed</title></head>"
"<body>LED Status: $S "
"<a href=\"/?status=$S\"><input type=\"button\" value=\"$S\"></a>"
"</body></html>"
), statusLabel, buttonLabel, buttonLabel);
ether.httpServerReply(bfill.position());
}
}
dkm382638608 发表于 2015-4-11 22:37 static/image/common/back.gif
3.3V 外接电源 已共地
3.3v有供电不足的可能原文提过
另外,简易你先试试 hdcp获得ip的例子 布列松 发表于 2015-4-11 22:58 static/image/common/back.gif
我有代码,不用网页的,直接登陆enc28j60的ip地址就可以控制
#include
恩恩 我参考一下 谢谢
Good Job!
Congratulations !
最后发现是因为 mac 上面的limitation (好像是最头上的bit0必须是0?我隐隐约约记得哪里有这个限制
但是一时又找不到了) zoologist 发表于 2015-4-12 08:47 static/image/common/back.gif
最后发现是因为 mac 上面的limitation (好像是最头上的bit0必须是0?我隐隐约约记得哪里有这个限制
但是 ...
恩恩 就只mac的问题
页:
[1]
2