以太网盾Arduinio SD不工作 [英] Arduinio sd on Ethernet shield not working at all

查看:189
本文介绍了以太网盾Arduinio SD不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Arduino,我有在顶部的SD插槽以太网盾,但它不似乎是工作。
我只是试图运行从SD采取简单草图库的例子,以获取有关卡的相关信息,但card.init(SPI_HALF_SPEED,片选)的一部分总是失败。

I am new to Arduino, and I have an ethernet shield with an SD socket on top, but it not seems to be working. I am just trying to run a simple sketch taken from the SD libraries example to get infos about the card, but the "card.init(SPI_HALF_SPEED, chipSelect)" part always fails.

我的片选引脚10引脚设置为4,并设置为输出,仍然一无所获。

I have set the ChipSelect pin to 4, and set pin 10 to output, still nothing.

我的code:

#include <SD.h>

Sd2Card card;
SdVolume volume;
SdFile root;

const int chipSelect = 4;    

void setup() {
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("\nInitializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
  pinMode(10, OUTPUT);     // change this to 53 on a mega


  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card is inserted?");
    Serial.println("* Is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    return;
  } else {
   Serial.println("Wiring is correct and a card is present."); 
  }

  // print the type of card
  Serial.print("\nCard type: ");
  switch(card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

}


void loop(void) {

}

我得到什么:

初​​始化SD卡...初始化失败。检查事项:
*是卡插入?
*是您的接线是否正确?
*你改变片选引脚来匹配你的盾牌或模块?

Initializing SD card...initialization failed. Things to check: * is a card is inserted? * Is your wiring correct? * did you change the chipSelect pin to match your shield or module?

我使用Arduino的乌诺R3,以太网盾(不是官方的)。
我曾尝试与一些的SD卡:SD / SDHC,16年2月4日GB,晟碟/金士顿,支持FAT16 / FAT32格式化

I am using Arduino Uno R3, Ethernet Shield (not the official one). I have tried with several SD cards: SD/SDHC, 2/4/16 Gb, Sandisk/Kingston, formatted with FAT16/FAT32

我害怕的东西是坏与屏蔽本身(尽管以太网的部分工作)。我怎样才能找出问题的根源?请帮助!

I am afraid something is bad with the shield itself (though the ethernet part is working). How can I identify the source of the problem? Please Help!

推荐答案

我跑你code和通过初始化固定它 SD.begin()前行 Serial.print(\\ n初始化SD卡...);

I ran your code and fixed it by initializing SD.begin() before the line Serial.print("\n Initializing SD card...");

事情是这样的:

SD.begin();
Serial.print("\nInitializing SD card..."); 

这篇关于以太网盾Arduinio SD不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆