Datalogger + Datum + Tijd + EthernetW5100 + SD

Arduino specifieke Software
Berichten: 2
Geregistreerd: 13 Jul 2013, 22:50

Re: Datalogger + Datum + Tijd + EthernetW5100 + SD

Berichtdoor pajbootsma » 14 Jul 2013, 17:35

Dat ging hier precies zo. Ging pas beter toen in de code van het Cardinfo example probeerde. Die card.init maakt het verschil denk ik. Zie ook http://forum.arduino.cc/index.php?topic=140401.0:
The sd card and the Ethernet stuff (...) They do not run independently on my mega2560. They are both SPI devices, and if not disabled or initialized correctly, they will cause failures in the other device.
En op http://stackoverflow.com/questions/17566328/communication-with-sd-card-arduino: "
the solution is to set high the digital pin 10 to stop the SPI connection with ethernet shield in order to speak to the card.
".

Stukje uit mijn setup():

Code: Alles selecteren
// SD-card - code derived from Cardinfo example
  Serial.print("\nProbing SD card...");
  pinMode(53, OUTPUT);     // change this to 53 on a mega
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("FAILED.");
    return;
  } else {
    Serial.println("OK.");
  }
  // print the type of card
  Serial.print("  Card 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");
  }
  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    eventLog("  Could not find FAT16/FAT32 partition. Card formatted?");
  }
  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("  Volume type: FAT");
  Serial.println(String(volume.fatType(), DEC));
  volumesize  = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();        // we'll have a lot of clusters
  volumesize *= 512;                          // SD card blocks are always 512 bytes
  Serial.print("  Volume size (bytes): ");
  Serial.println(String(volumesize));
  Serial.println("  Files found on the card (name, date and size in bytes): ");
  root.openRoot(volume);
  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
  Serial.print("Initializing SD-card...");
  if (!SD.begin(chipSelect)) {
    Serial.println("FAILED.");
  } else {
    Serial.println("OK.");
  }
 
  // Ethernet
  // Open serial communications and wait for port to open:
  Serial.print("Configuring Ethernet...");
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("FAILED.");
    lineError = "Ethernet";
  } else {
    Serial.println("OK.");
  }
  // print the local IP address:
  Serial.print("Thermix IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(String(Ethernet.localIP()[thisByte], DEC));
    Serial.print(".");
  } 
  Serial.println();

Advertisement

Vorige

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 36 gasten