我一直在玩一个arduino以太网盾,试图让基本的例子工作,但无济于事 . 这是我的设置:
Arduino Mega 2560通过usb连接到计算机,并且以太网屏蔽层堆叠在其上 . 我尝试了arduino软件附带的各种示例,但似乎都没有正常工作 . 经过wirehark的大量调试,我认为:
-
我无法使用DHCP,因为它只是在
Ethernet.begin(mac)
调用时挂起 . -
当我尝试使用静态IP时,
Ethernet.localIP()
函数返回0.0.0.0 . 但是,我可以使用我设置的ip从我的计算机ping我的设备,并且设备似乎正确地接收和发送数据包 . 现在的问题是由于某种原因它丢弃了tcp连接 . 这里是我运行的代码离工作最近的:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,27);
IPAddress server(192,168,2,52);
EthernetClient client;
void setup() {
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// 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("a");
delay(1000);
Serial.println("connecting...");
if (client.connect(server, 23)) {
Serial.println("connected");
}
else {
Serial.println("connection failed");
}
Serial.println(Ethernet.localIP());
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// as long as there are bytes in the serial queue,
// read them and send them out the socket if it's open:
while (Serial.available() > 0) {
char inChar = Serial.read();
if (client.connected()) {
client.print(inChar);
}
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing:
while(true);
}
}
它基本上是Ethernet / TelnetClient示例 . 我在我的电脑上设置了一个telnet服务器 . 现在这是arduino /计算机交换:
arduino发送一个RST数据包,但我的服务器继续发送问候语和登录提示 . 我尝试使用arduino uno,并尝试断开usb并使用另一个电源 . 那么,可能是什么问题呢?
1 回答
问题在于与屏蔽的连接,如果是中文版,有时也会出现屏蔽,可能会有短暂的短路 .
我尝试断开屏蔽并连接电线,如arduino website indicate for arduino uno(与arduino mega的连接不正确,所以你需要连接像arduino uno)
如果它不起作用,请尝试更改arduino盾牌 . 我有相同盾牌的类似问题,通常问题是与arduino的连接 . 如果arduino正确连接,该示例应该有效