Teensy 4.1 SD Card use

Status
Not open for further replies.
Hi All,

I am trying to read a file from the onboard SD card reader and I am struggling to get it working, I notice on this forum many posts saying that using the SD.h and SPI.h and then having a const like so:

Code:
const int chipSelect = BUILTIN_SDCARD;

This I have and then in my

Code:
// see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");

But I get an error of:

error: 'BUILTIN_SDCARD' was not declared in this scope
const int chipSelect = BUILTIN_SDCARD;

So what am I missing? I installed the LIBs for Teensyduino and I am certain I am using the correct ones but it's got me puzzled so any help would be great.

Thanks

Cliff.
 
Hi Cliff, where do you declare chipSelect? It should be declared in the first part of your program before anything that needs it. If that is not it, post a more complete example of your code so that we can better help.

Len
 
So what am I missing?

Arduino is using a non-Teensy copy of the SD library.

First, check that Teensy is selected in Tools > Boards.

Next, scroll up from the error message and look for info about duplicate libraries. If you've got a copy of SD in Documents/Arduino/libraries, it will override all other copies. The duplicate lib message is should tell you the full path of the lib is used and others it ignore. Delete or move the non-Teensy version, so Arduino uses the SD lib meant for Teensy.

If that doesn't solve it, turn on verbose output in File > Preferences. Then you'll get a similar message about the full path of each library used, even if Arduino didn't detect any conflicts. Make sure the SD being used is in {Arduino}/hardware/teensy/avr/libraries/SD.
 
Ok I can see what I think is happening and your right @Paul the compiler is picking up the wrong version of SD.h.

Problem is within the Arduino / VSMicro IDE (Tried both!) SD isn't showing as a Lib for Teensy in fact there are a lot of them missing as if they are not being read in correctly I have tried re-installing Teensyduino but that hasn't worked either.

The folder is on the HD of my machine:

C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries

but isn;t listed in the Arduino or VSMicro IDE's as being there...
 
Status
Not open for further replies.
Back
Top