No SD Init, Ultimate GPS logger + Thermocouple Multiplexer

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
aeromechie
 
Posts: 4
Joined: Tue Aug 12, 2014 8:12 am

No SD Init, Ultimate GPS logger + Thermocouple Multiplexer

Post by aeromechie »

Hi all. I am fairly new to arduino, so please excuse any ignorance I might display. I am attempting to combine an Arduino Uno, an Adafruit Ultimate GPS logger, and a Ocean Controls Thermocouple Multiplexer Shield in a single stack, and while I've found a number of different posts on this topic, (both on this forum and others) I'm still having some trouble getting the SD card to initialize.

In the code I wrote to read temperatures and GPS and store it to the SD card, I implemented the SD.begin(SDPINCS, 11, 12, 13) change that seems to have fixed the problems for other people, but it did not for me. As a troubleshooting step, I attempted to use the "CardInfo" sketch in the "Examples" folder of the Adafruit SD library, which was also unsuccessful. I believe it is some sort of conflict between the two boards, but I'm not sure what is different between the ultimate GPS board I'm attempting to use, and the logger board without GPS that is mentioned in other threads.

For completeness, here is the "CardInfo" code from the examples folder that doesn't seem to work for me:

Code: Select all

/*
  SD card test 
   
 This example shows how use the utility libraries on which the'
 SD library is based in order to get info about your SD card.
 Very useful for testing a card when you're not sure whether its working or not.
 	
 The circuit:
 * SD card attached to SPI bus as follows:
 ** UNO:  MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 4 (CS pin can be changed)
  and pin #10 (SS) must be an output
 ** Mega:  MOSI - pin 51, MISO - pin 50, CLK - pin 52, CS - pin 4 (CS pin can be changed)
  and pin #52 (SS) must be an output
 ** Leonardo: Connect to hardware SPI via the ICSP header
 		Pin 4 used here for consistency with other Arduino examples

 
 created  28 Mar 2011  by Limor Fried 
 modified 9 Apr 2012   by Tom Igoe
 */
 // include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 10;    

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
  }


  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(chipSelect, OUTPUT);
  
  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  while (!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?");
  } 
  
  // 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");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    return;
  }


  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("\nVolume type is FAT");
  Serial.println(volume.fatType(), DEC);
  Serial.println();
  
  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(volumesize);
  Serial.print("Volume size (Kbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Mbytes): ");
  volumesize /= 1024;
  Serial.println(volumesize);

  
  Serial.println("\nFiles 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);
}


void loop(void) {
  
}
And here is the result when I execute that:

Code: Select all

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?
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?

(Repeating forever)

Does anyone have any insights as to why the addition of this thermocouple board would be causing issues? I've tested just the Uno and the adafruit board, and that seems to work fine, as does just the Uno and the thermocouple multiplexer. It also seems that the thermocouple board plays nicely with the older Adafruit logger shield (see here, so I'm thinking it must be some subtle different between the Ultimate GPS logger and the older logging shield that I'm not accounting for.)


One other thing. As mentioned here, it was suggested that I add digitalWrite(chipSelect,HIGH); right after pinMode(chipSelect, OUTPUT);. I get slightly better output, but it's still unreliable. (The output is repeated below by my pressing the reset button on the adafruit board multiple times.)

Code: Select all

Initializing SD card...
Card type: SDHC
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card

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?

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3896508416
Volume size (Kbytes): 3805184
Volume size (Mbytes): 3716

Files found on the card (name, date and size in bytes): 

Initializing SD card...
Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3896508416
Volume size (Kbytes): 3805184
Volume size (Mbytes): 3716

Files found on the card (name, date and size in bytes): 

Initializing SD card...
Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3896508416
Volume size (Kbytes): 3805184
Volume size (Mbytes): 3716

Files found on the card (name, date and size in bytes): 

Initializing SD card...
Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3896508416
Volume size (Kbytes): 3805184
Volume size (Mbytes): 3716

Files found on the card (name, date and size in bytes): 

Initializing SD card...
Card type: SDHC
Could not find FAT16/FAT32 partition.
Make sure you've formatted the card

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?

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3896508416
Volume size (Kbytes): 3805184
Volume size (Mbytes): 3716

Files found on the card (name, date and size in bytes): 
Does anyone have any ideas as to why there is this unreliable operation, and how I can correct it? I would really appreciate any help anyone could provide, and thanks!

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: No SD Init, Ultimate GPS logger + Thermocouple Multiplex

Post by Franklin97355 »

If you run the GPS logger by itself does it work?

User avatar
aeromechie
 
Posts: 4
Joined: Tue Aug 12, 2014 8:12 am

Re: No SD Init, Ultimate GPS logger + Thermocouple Multiplex

Post by aeromechie »

Thanks for the response- I probably should have included that in my original post. Yes, the adafruit shield appears to work fine without the thermocouple shield installed. Using cardinfo code I quoted above, with the addition of the digitalWrite(chipSelect,HIGH); line, this is the output:

Code: Select all


Initializing SD card...
Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3896508416
Volume size (Kbytes): 3805184
Volume size (Mbytes): 3716

Files found on the card (name, date and size in bytes): 
TEST.TXT      2000-01-01 01:00:00 234
F0.CSV        2000-01-01 01:00:00 0
F1.CSV        2000-01-01 01:00:00 262

Initializing SD card...
Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3896508416
Volume size (Kbytes): 3805184
Volume size (Mbytes): 3716

Files found on the card (name, date and size in bytes): 
TEST.TXT      2000-01-01 01:00:00 234
F0.CSV        2000-01-01 01:00:00 0
F1.CSV        2000-01-01 01:00:00 262

Initializing SD card...
Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3896508416
Volume size (Kbytes): 3805184
Volume size (Mbytes): 3716

Files found on the card (name, date and size in bytes): 
TEST.TXT      2000-01-01 01:00:00 234
F0.CSV        2000-01-01 01:00:00 0
F1.CSV        2000-01-01 01:00:00 262
The code no longer returns intermittent results, and functions reliably as expected.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: No SD Init, Ultimate GPS logger + Thermocouple Multiplex

Post by adafruit_support_mike »

You may be seeing a pin conflict. The SD card is an SPI device, and your thermocouple shield also seems to use SPI. I'm not entirely sure what pins it's using though, so check to make sure there are no hardware or software conflicts.

User avatar
aeromechie
 
Posts: 4
Joined: Tue Aug 12, 2014 8:12 am

Re: No SD Init, Ultimate GPS logger + Thermocouple Multiplex

Post by aeromechie »

Hi Mike, thanks for the help!

Last night, I also heard back from the folks at ocean controls, who also pointed to SPI being the issue. They said, "I suspect the problem is that you are using the Arduino SPI library to talk to the SD card, while the thermocouple shield example sketch uses bit-banged SPI.

The ocean controls FAQ for the device says this about the topic: "You can't use SPI and Bit-Banging at the same time. The Adafruit SD library supports Bit-Banging for SD card like this SD.begin(chipSelect, 11, 12, 13); so you will need to download Adafruit's SD library...."

I am already using the adafruit SD library. If I use the above code for SD.begin, the sketch compiles, but does not work as expected- SD.init fails about 1/2 the time I attempt it. Otherwise, when I use the above code for SD.begin and comment out #include <SPI.h> to attempt to avoid the conflict, I get a compilation error that looks like this:

Code: Select all

C:\Program Files (x86)\Arduino\libraries\SD\utility\Sd2Card.cpp: In function 'void spiSend(uint8_t)':
C:\Program Files (x86)\Arduino\libraries\SD\utility\Sd2Card.cpp:54: error: 'SPI' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\SD\utility\Sd2Card.cpp: In function 'uint8_t spiRec()':
C:\Program Files (x86)\Arduino\libraries\SD\utility\Sd2Card.cpp:81: error: 'SPI' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\SD\utility\Sd2Card.cpp: In member function 'uint8_t Sd2Card::init(uint8_t, uint8_t, int8_t, int8_t, int8_t)':
C:\Program Files (x86)\Arduino\libraries\SD\utility\Sd2Card.cpp:326: error: 'SPI' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\SD\utility\Sd2Card.cpp: In member function 'uint8_t Sd2Card::setSckRate(uint8_t)':
C:\Program Files (x86)\Arduino\libraries\SD\utility\Sd2Card.cpp:585: error: 'SPI' was not declared in this scope
So, I think my question is, is SPI required for the adafruit SD library? Is there a way to avoid using it so that the thermocouple device and the SD logger will play nicely with each other?

User avatar
aeromechie
 
Posts: 4
Joined: Tue Aug 12, 2014 8:12 am

Re: No SD Init, Ultimate GPS logger + Thermocouple Multiplex

Post by aeromechie »

And Mike, to answer the other part of your questions, this thread mentions that there is a conflict on pin 13 between the two boards. That said, that poster addressed it by sending the adafruit board into bit-banging mode with the command SD.begin(SDPINCS, 11, 12, 13). I keep seeing this command mentioned as a solution, but it doesn't seem to work for me. Do I have any other options?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: No SD Init, Ultimate GPS logger + Thermocouple Multiplex

Post by adafruit_support_mike »

aeromechie wrote:So, I think my question is, is SPI required for the adafruit SD library?
SD cards communicate with the world using SPI, so yeah, you need to have some version of SPI to make the card work.
aeromechie wrote:Is there a way to avoid using it so that the thermocouple device and the SD logger will play nicely with each other?
SPI is a shared bus protocol (multiple devices can be connected to the same set of signal wires) and our SD library does give you the option to bit-bang the signals by selecting the pins you want.

I'm not sure what's causing the problems you're seeing at this point, but this thread goes into the gory details: http://forums.adafruit.com/viewtopic.php?f=31&t=39699

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”