首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Arduino Ethernet Shield 2无法工作

Arduino Ethernet Shield 2无法工作
EN

Stack Overflow用户
提问于 2015-06-05 20:38:22
回答 3查看 3.9K关注 0票数 0

我目前正在尝试让以太网盾在我的Mega上工作。我试图运行was服务器示例,但程序似乎在某一点上卡住了,所以我尝试从头开始。

这是我的测试代码:

代码语言:javascript
复制
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0F, 0xF6, 0x3D
};
byte subnet[] = { 255,0,0,0 };
byte gateway[] = { 2,0,0,1 };
IPAddress ip(2, 0, 0, 1);

EthernetServer server(80);

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac, ip, gateway, subnet);
  Serial.println("Ethernet started");
  server.begin();
  Serial.println("Server started");
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Loop");
}

我从串行控制台得到的输出是:

代码语言:javascript
复制
Etrted
Ethernet started

所以我认为程序卡在EthernetServer::begin()函数中了。我知道有一些早期版本的以太网屏蔽与mega不兼容,但我的屏蔽的供应商说它是兼容的。

我也不明白,为什么它输出第一行。

谢谢你的提示!

EN

回答 3

Stack Overflow用户

发布于 2015-06-16 22:23:47

Arduino.cc和Arduino.org不是一回事...销售以太网盾2的Arduino.org有他们自己的集成开发环境和正确的库!您可以在https://github.com/arduino-org/Arduino/tree/1.7.4/libraries上找到它的源代码,您可以从http://www.arduino.org/downloads下载它

票数 1
EN

Stack Overflow用户

发布于 2015-06-23 21:10:35

尝试此代码表单(http://www.arduino.cc/en/Tutorial/DhcpAddressPrinter):

代码语言:javascript
复制
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
  // this check is only needed on the Leonardo:
   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(;;)
      ;
  }
  // 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();
}

void loop() {

}

并发布串行监视器的输出。

票数 0
EN

Stack Overflow用户

发布于 2015-11-03 19:28:50

试试这个:

注意:您可以重用为Arduino Ethernet Shield编写的代码,只需替换

代码语言:javascript
复制
#include <Ethernet.h>  -->  #include <Ethernet2.h>
#include <EthernetUdp.h>  -->  #include <EthernetUdp2.h>

看看这个:http://labs.arduino.org/Arduino+Ethernet+Shield+2

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30666783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档