Arduino以太网盾无法正常工作

时间:2014-05-25 17:51:48

标签: arduino ip ethernet

我有一个arduino以太网盾,我正在尝试运行" Webserver"例子就可以了。我把盾牌放在arduino的顶部,arduino通过USB连接到我的电脑,屏蔽连接到我的电脑以及RJ45以太网电缆。我正在使用我大学的无线网络连接到互联网,无法访问任何路由器。所以这是我的问题:当我在命令行输入ipconfig时,我看到我的计算机的IP地址是143.215.98.213。所以在" Webserver"在arduino IDE中给出的示例代码,我做的唯一更改是将IP地址设置为:   IPAddress ip(143,215,98,2); (我把地址143.215.98.2,它没用过,所以我觉得很好)。 Web服务器代码应该从arduino读取模拟输入并在html页面上打印。当我将代码上传到arduino并在我的浏览器中输入地址143.215.98.2时,浏览器无法连接到任何页面。 TX和RX LED不亮。此外,我尝试在代码运行时ping t143.215.98.2并且我没有得到响应(arduino上的LED也没有闪烁)。这是我正在使用的网络服务器示例代码:

#include <SPI.h>
#include <Ethernet.h>

// 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, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(143,215,98,2); 
//IPAddress ip(128,61,79,1); 
//IPAddress ip(192,168,1,1);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

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 and the server:
  Ethernet.begin(mac, ip);
  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("Connection: close");  
      client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // 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("<br />");       
          }
          client.println("</html>");
          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");
  }
}

那么可能是什么问题?

3 个答案:

答案 0 :(得分:0)

我认为问题是IP地址。是否有可能从DHCP获得自动IP?如果是这样,您应该删除IP地址,然后使用Ethernet.begin(mac)启动服务器。

如果无法获得自动IP ..您可以向网络管理员询问网络上的免费IP部分。 (如果他提供那种信息)

无论如何,祝你好运!

答案 1 :(得分:0)

正确检查您的IP地址。无论您使用静态还是动态类型。

转到INTERNET协议。选择以下IP地址amd configure as和include in Program

IPAddress ip(192,168,1, 177);
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 0, 0);

答案 2 :(得分:0)

延迟很多,但我写在这里是为了帮助有类似问题的人。

我要为中国的 Arduino Ethernet Shield 疯狂了: 使用某些开关它可以工作,而使用其他开关则不起作用。 然后在网上大量搜索后,我发现了这个: https://reedpaper.wordpress.com/2018/09/17/arduino-ethernet-w5100-how-to-fix-the-wrong-board/ 问题就解决了!

在某些中文板中,以太网连接器附近的 49.9 欧姆电阻存在错误。 他们没有安装 510 阵列电阻器,而是使用 511 阵列电阻器,因此有 51ohm 有一个 510ohm 电阻器,连接结果是不可预测的。

相关问题