首页 文章

Arduino以太网盾2无法正常工作

提问于
浏览
0

我目前正试图让以太网盾在我的Mega上工作 . 我试图运行Webserver示例,但程序似乎停留在某一点,所以我试图从头开始 .

这是我的测试代码:

#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");
}

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

Etrted
Ethernet started

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

另外我不明白,为什么它输出第一行 .

谢谢你的提示!

3 回答

  • 0

    Arduino.cc和Arduino.org不一样......销售以太网盾2的Arduino.org有自己的IDE和正确的库!你可以在http://www.arduino.org/downloads下载它,源代码可以在https://github.com/arduino-org/Arduino/tree/1.7.4/libraries找到

  • 1

    试试这段代码表格(http://www.arduino.cc/en/Tutorial/DhcpAddressPrinter):

    #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

    试试这个:

    NB . 您可以重用为Arduino Ethernet Shield编写的代码,只需更换即可

    #include <Ethernet.h>  -->  #include <Ethernet2.h>
    #include <EthernetUdp.h>  -->  #include <EthernetUdp2.h>
    

    见:http://labs.arduino.org/Arduino+Ethernet+Shield+2

相关问题