Arduino 使用SD卡的以太网屏蔽出现故障

Arduino 使用SD卡的以太网屏蔽出现故障,arduino,sd-card,Arduino,Sd Card,我买了一个Arduino以太网屏蔽,但我的web服务器使用SD卡上的文件时遇到了问题。有一个服务器运行在端口80上提供数据,但当我加载它时,我似乎得到了如下数据 找到文件 找不到文件 找不到文件 找不到文件 标题>04非ÁFhundž标题>404非F·und 或者它开始下载与上面类似的内容(我假设标题像实际内容一样损坏) 如果我不使用SD卡,只提供写入草图的预写网页,那么只要SD卡不在插槽中,网页就会正确显示。此外,SD库表示,当“index.html”存在时,它无法看到它 我正在Arduino

我买了一个Arduino以太网屏蔽,但我的web服务器使用SD卡上的文件时遇到了问题。有一个服务器运行在端口80上提供数据,但当我加载它时,我似乎得到了如下数据

找到文件

找不到文件

找不到文件

找不到文件

标题>04非ÁFhundž标题>404非F·und

或者它开始下载与上面类似的内容(我假设标题像实际内容一样损坏)

如果我不使用SD卡,只提供写入草图的预写网页,那么只要SD卡不在插槽中,网页就会正确显示。此外,SD库表示,当“index.html”存在时,它无法看到它

我正在Arduino Uno上使用超越Micro SDHC 4GB(FAT32)和以太网屏蔽R3,我尝试格式化Micro SD卡。下面是我的素描

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

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 130); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

File webFile;

void setup()
{
  Ethernet.begin(mac, ip);  // initialize Ethernet device
  server.begin();           // start to listen for clients
  Serial.begin(9600);       // for debugging

  // initialize SD card
  Serial.println("Initializing SD card...");
  if (!SD.begin(4)) {
      Serial.println("ERROR - SD card initialization failed!");
      return;    // init failed
  }
  Serial.println("SUCCESS - SD card initialized.");
  // check for index.htm file
  if (!SD.exists("index.html")) {
      Serial.println("ERROR - Can't find index.html!");
  }      
  Serial.print("Running on ");
  Serial.println(Ethernet.localIP());
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                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();
                    client.println("<html><head><title>404 Not Found</title></head><body><p>File not found</p></body></html>");
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}
#包括
#包括
#包括
//板下以太网屏蔽贴纸的MAC地址
字节mac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
ip地址ip(192、168、1130);//IP地址,可能需要根据网络进行更改
EthernetServer服务器(80);//在端口80创建服务器
文件webFile;
无效设置()
{
Ethernet.begin(mac,ip);//初始化以太网设备
server.begin();//开始侦听客户端
Serial.begin(9600);//用于调试
//初始化SD卡
Serial.println(“初始化SD卡…”);
如果(!SD.begin(4)){
Serial.println(“错误-SD卡初始化失败!”);
return;//初始化失败
}
Serial.println(“成功-SD卡初始化”);
//检查index.htm文件
如果(!SD.exists(“index.html”)){
println(“错误-找不到index.html!”);
}      
串行打印(“正在运行”);
Serial.println(Ethernet.localIP());
}
void循环()
{
EthernetClient=server.available();//尝试获取客户端
如果(客户机){//got客户机?
布尔currentLineIsBlank=true;
while(client.connected()){
if(client.available()){//可读取的客户端数据
char c=client.read();//从客户端读取1字节(字符)
//客户端请求的最后一行为空,以\n结尾
//仅在收到最后一行后响应客户端
如果(c='\n'&¤tLineIsBlank){
//发送标准http响应头
client.println(“HTTP/1.1200ok”);
client.println(“内容类型:text/html”);
client.println(“连接:关闭”);
client.println();
client.println(“404未找到文件未找到”;
打破
}
//从客户端接收的每一行文本都以\r\n结尾
如果(c=='\n'){
//接收文本行上的最后一个字符
//在读取下一个字符时开始新行
currentLineIsBlank=true;
} 
如果(c!='\r'),则为else{
//从客户端接收到一个文本字符
currentLineIsBlank=false;
}
}//如果(client.available())结束
}//结束时(client.connected())
延迟(1);//给web浏览器接收数据的时间
client.stop();//关闭连接
}//如果结束(客户端)
}

我使用SD卡的经验是,从SD卡上读取数据比向SD卡上写入数据更稳定。因此,如果你有一个SDHC-USB转换器可以插入你的电脑(和许多供应商/型号存在),然后格式化和初始化你的电脑上的SD卡

有一个名为SDFormatter V3.1的免费软件包,它可以很好地使用FAT32格式化SDHC卡。在SD插槽中多次使用磁盘后,请不要相信磁盘已正确格式化

使用8.3文件命名约定,并将文件格式化为FAT32设备。最后,将要交付的网页加载到SD卡的根目录中

现在,将SD卡插入Arduino插槽,并尝试从SD卡读取数据。不要在Arduino上初始化或格式化卡。只需分配或启动SDHC设备并读取卡的根目录文件即可

请张贴您的测试程序。带有以太网内容的程序似乎无法正确“开始”SD卡。这就是为什么在以太网连接开始工作之前,您应该先读取卡并将文件打印到显示器上(看起来是这样的,所以一旦文件测试程序开始工作,您就应该完成!)


使用FAT32格式的卡,编写一个测试程序,该程序将打开一个文件,并将其内容写在
串行
行上,返回到您的PC。在使用无线/以太网连接之前调试此功能。

有两个问题需要查找:1)您的屏蔽没有修复5100芯片错误,2)SPI总线要求两个设备的SS(从机选择)不同时处于激活(低)状态,5100的SS=数字引脚10,SD的SS=数字引脚4(包括在屏蔽中)。

看起来您添加了一些新信息。我更新了我的答案,也提供了一些更多的细节。为了解决这个问题,我们可能需要来回几次。好的,谢谢你的建议。我会尝试一下,更新我的问题