X-Board使用问题
2014-07-161.4万
AI 快速预览详细
本文讨论了X-Board继电器板在启用网络功能后出现的串口监视器无输出和设备死机的问题。通过简单的测试程序,发现当启用网络功能时,设备会立刻死机。进一步测试表明,即使取消串口输出并使用固定IP地址,也无法通过浏览器访问设定的IP地址。文章提供了详细的故障排查步骤和解决方案,帮助用户解决这一常见问题,确保项目的顺利进行。
|
X-Board继电器板,https://www.dfrobot.com.cn/goods-686.html 运行样例程序时串口监视器上没有任何输出,不知何故? 为了测试,写了一段简单的程序,读模拟口的值然后在串口打印,不启用网络功能,一起正常,如果启用网络功能,立刻死机。 是不是Ethernet和串口冲突?但是把串口的输出全部取消,用mac地址加固定ip地址的方式启用Ethernet,在浏览器访问给X-Board设定的ip地址,提示无法访问。 请用过X-borad(继电器板)的大侠给点指导。 |





Serial.println("Serial is ok!");
delay(1000);
其实不加也是一样的,我加了只是想测试串口是否设置正常。
/*
DFRobot X-board V2 Sample Code
A simple web server with DHPC capbabilty.
1)Get IP address from router automatically
2)Show the value of the analog input pins
created 28 Sep 2012
by Ricky
*/
#include
#include
//EthernetServer server(80);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xCD, 0xAE, 0x0F, 0xFE, 0xED };
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
//IPAddress
//byte ip[] = {192, 168, 0, 169 };
IPAddress ip(192,168,1, 210);
//byte ip[] = {192, 168, 0, 167 };
void setup() {
delay(3000); // for debugging, a little delay makes things easier, for use, delete delay.
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Serial is ok!");
delay(1000);
// start the Ethernet connection:
/* if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
*/
Ethernet.begin(mac,ip);
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
// start the Ethernet connection and the server:
//server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
}
测试了你提供的代码,我在串口初始化成功后打印了一句“Serial is ok!”,然后继续初始化网口,结果显示:
My IP address: 0.0.0.0.
server is at 0.0.0.0
如果采用DHCP,输出了“Serial is ok!”后,就没有任何输出了。
我觉得即便是网络问题,设置固定IP也是应该可以设置的,有IP冲突等网络问题也应该只是影响通讯,但是现在是设置固定IP的时候会设置成0.0.0.0,而DHCP又没有任何响应。
有点要崩溃的感觉。用这块板子是要搭建一个很重要的应用原型测试,请尽快提供帮助,让我能继续下去。
测试过程中我发现,如果用我们网站上的样例代码,updown代码以后,需要拔掉断电或者Rset一下,等待一端时间,Arduino的串口才会出现IP Address。
一、采用Ethernet.begin(mac),也就是试图DHCP取得ip地址,如果连接DHCP服务器,系统将死机,串口没有输出
二、采用Ethernet.begin(mac),仍然用DHCP取得ip地址,如果没有DHCP服务器,串口输出提示“Failed to configure Ethernet using DHCP”,这个应该是正常的。
三、采用Ethernet.begin(mac, ip),自设置ip地址的话,然后立刻打印ip地址,结果如下:
这就是最奇怪的地方了,IP地址被设置成了255.255.255.255。
代码如下:
/*
DFRobot X-board V2 Sample Code
A simple web server with DHPC capbabilty.
1)Get IP address from router automatically
2)Show the value of the analog input pins
created 28 Sep 2012
by Ricky
*/
#include
#include
EthernetServer server(80);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xAE, 0x0F, 0xFE, 0xED };
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
//IPAddress ip(192,168,1,173);
byte ip[] = {192, 168, 0, 163 };
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
/*
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}*/
Ethernet.begin(mac, ip);
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Serial.println();
// start the Ethernet connection and the server:
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connnection: close");
client.println();
client.println("");
client.println("");
// add a meta refresh tag, so the browser pulls again every 5 seconds:
client.println("");
client.println("");
client.println("
client.println("
");
client.println("
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("
");
}
// output the value of each digital input pin
for (int digitalChannel = 2; digitalChannel < 10; digitalChannel++) {
int sensorReading = digitalRead(digitalChannel);
if(digitalChannel!=7&&digitalChannel!=8)
{
client.print("Digital input ");
client.print(digitalChannel);
client.print(" is ");
client.print(sensorReading);
client.println("
");
}
else
{
client.print("Relay ");
client.print(digitalChannel);
client.print(" is ");
client.print(sensorReading);
client.println("
");
}
}
client.println("
client.println("");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
测试无果后,到Arduino.cc上去看Ethernet.h的说明,在Ethernet.begin()说明中看到这么一句:
“mac: the MAC (Media access control) address for the device (array of 6 bytes). this is the Ethernet hardware address of your shield. Newer Arduino Ethernet Shields include a sticker with the device's MAC address. For older shields, choose your own.”
于是猜测,是不是我的板子是新的,MAC地址要用真实地址,不能自己设置?但是我已经找不到“sticker”了,不知道地址是什么?
然后,不明白的事情出现了,我仔细观察板子,发现5100芯片的引脚上有几处焊接粘连点,附照片如下,请DFRobot的人帮忙判断一下,图片中红色圈内的焊接粘连是正常的还是不正常的,5100下面的Atmel焊接就没有这种粘连。
然后串口会得到一个IP地址
在网页上输入IP地址以后会出现IO口的数据
[/font][font=微软雅黑]
[/font]
[font=微软雅黑]样例代码没有问题,请检测你的硬件连接[/font]
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
注释掉后结果是一样的。
这段代码在自己写的测试程序中用或不用,似乎对串口通信的影响不大,目前看还是网络功能问题。
DFROBOT的人能用X-Board板试试吗?