Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: teensy 3.6 'BUILTIN_SDCARD' was not declared in this scope using sdfat.h

  1. #1
    Junior Member
    Join Date
    Nov 2017
    Posts
    2

    teensy 3.6 'BUILTIN_SDCARD' was not declared in this scope using sdfat.h

    just tried to run the datalogger example for the sdfat.h library and the error came up 'BUILTIN_SDCARD' was not declared in this scope. how do i fix this problem?

    /*
    * Simple data logger.
    */
    #include <SPI.h>
    #include "SdFat.h"

    // SD chip select pin. Be sure to disable any other SPI devices such as Enet.
    const uint8_t chipSelect = BUILTIN_SDCARD;

    // Interval between data records in milliseconds.
    // The interval must be greater than the maximum SD write latency plus the
    // time to acquire and write data to the SD to avoid overrun errors.
    // Run the bench example to check the quality of your SD card.
    const uint32_t SAMPLE_INTERVAL_MS = 1000;

    // Log file base name. Must be six characters or less.
    #define FILE_BASE_NAME "Data"
    //------------------------------------------------------------------------------
    // File system object.
    SdFat sd;

    // Log file.
    SdFile file;

    // Time in micros for next data record.
    uint32_t logTime;

    //================================================== ============================
    // User functions. Edit writeHeader() and logData() for your requirements.

    const uint8_t ANALOG_COUNT = 4;
    //------------------------------------------------------------------------------
    // Write data header.
    void writeHeader() {
    file.print(F("micros"));
    for (uint8_t i = 0; i < ANALOG_COUNT; i++) {
    file.print(F(",adc"));
    file.print(i, DEC);
    }
    file.println();
    }
    //------------------------------------------------------------------------------
    // Log a data record.
    void logData() {
    uint16_t data[ANALOG_COUNT];

    // Read all channels to avoid SD write latency between readings.
    for (uint8_t i = 0; i < ANALOG_COUNT; i++) {
    data[i] = analogRead(i);
    }
    // Write data to file. Start with log time in micros.
    file.print(logTime);

    // Write ADC data to CSV record.
    for (uint8_t i = 0; i < ANALOG_COUNT; i++) {
    file.write(',');
    file.print(data[i]);
    }
    file.println();
    }
    //================================================== ============================
    // Error messages stored in flash.
    #define error(msg) sd.errorHalt(F(msg))
    //------------------------------------------------------------------------------
    void setup() {
    const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1;
    char fileName[13] = FILE_BASE_NAME "00.csv";

    Serial.begin(9600);

    // Wait for USB Serial
    while (!Serial) {
    SysCall::yield();
    }
    delay(1000);

    Serial.println(F("Type any character to start"));
    while (!Serial.available()) {
    SysCall::yield();
    }

    // Initialize at the highest speed supported by the board that is
    // not over 50 MHz. Try a lower speed if SPI errors occur.
    if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
    sd.initErrorHalt();
    }

    // Find an unused file name.
    if (BASE_NAME_SIZE > 6) {
    error("FILE_BASE_NAME too long");
    }
    while (sd.exists(fileName)) {
    if (fileName[BASE_NAME_SIZE + 1] != '9') {
    fileName[BASE_NAME_SIZE + 1]++;
    } else if (fileName[BASE_NAME_SIZE] != '9') {
    fileName[BASE_NAME_SIZE + 1] = '0';
    fileName[BASE_NAME_SIZE]++;
    } else {
    error("Can't create file name");
    }
    }
    if (!file.open(fileName, O_CREAT | O_WRITE | O_EXCL)) {
    error("file.open");
    }
    // Read any Serial data.
    do {
    delay(10);
    } while (Serial.available() && Serial.read() >= 0);

    Serial.print(F("Logging to: "));
    Serial.println(fileName);
    Serial.println(F("Type any character to stop"));

    // Write data header.
    writeHeader();

    // Start on a multiple of the sample interval.
    logTime = micros()/(1000UL*SAMPLE_INTERVAL_MS) + 1;
    logTime *= 1000UL*SAMPLE_INTERVAL_MS;
    }
    //------------------------------------------------------------------------------
    void loop() {
    // Time for next record.
    logTime += 1000UL*SAMPLE_INTERVAL_MS;

    // Wait for log time.
    int32_t diff;
    do {
    diff = micros() - logTime;
    } while (diff < 0);

    // Check for data rate too high.
    if (diff > 10) {
    error("Missed data record");
    }

    logData();

    // Force data to SD and update the directory entry to avoid data loss.
    if (!file.sync() || file.getWriteError()) {
    error("write error");
    }

    if (Serial.available()) {
    // Close file and stop.
    file.close();
    Serial.println(F("Done"));
    SysCall::halt();
    }
    }

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,428
    My guess is you have an old version of SDfat sitting around that is being used.

    It was good that you posted code. Which if other things fail some of us can try to build it. Hint, when you post code please put it into code tags.
    You can do that by pressing the # button in the edit tool bar. This puts the code in where it still shows the indents...

    Back to issue. Would help if you posted the actual error messages. Example did it say something like duplicate copies of SDFat and one not used...

    My guess is that you have a version in your <Arduino Sketch folder>/libraries. try removing that version and try again.

  3. #3
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,200
    I think you are mixing the SD libraries. The teensy SD library uses BUILTIN_SDCARD, but SdFat uses SdFatSdio sd;, look at SdFat example TeensySdioDemo

  4. #4
    Junior Member
    Join Date
    Nov 2017
    Posts
    2
    Quote Originally Posted by KurtE View Post
    My guess is you have an old version of SDfat sitting around that is being used.

    It was good that you posted code. Which if other things fail some of us can try to build it. Hint, when you post code please put it into code tags.
    You can do that by pressing the # button in the edit tool bar. This puts the code in where it still shows the indents...

    Back to issue. Would help if you posted the actual error messages. Example did it say something like duplicate copies of SDFat and one not used...

    My guess is that you have a version in your <Arduino Sketch folder>/libraries. try removing that version and try again.
    thanks for the tips, will use the # button next time.
    this is the error messages

    Arduino: 1.8.2 (Windows 10), TD: 1.39, Board: "Teensy 3.6, Serial, 180 MHz, Faster, US English"

    dataLogger:31: error: 'BUILTIN_SDCARD' was not declared in this scope
    const uint8_t ANALOG_COUNT = BUILTIN_SDCARD;

    ^

    dataLogger: In function 'void logData()':
    dataLogger:45: error: size of array 'data' is not an integral constant-expression
    uint16_t data[ANALOG_COUNT];

    ^

    'BUILTIN_SDCARD' was not declared in this scope

  5. #5
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,200
    Quote Originally Posted by manitou View Post
    I think you are mixing the SD libraries. The teensy SD library uses BUILTIN_SDCARD, but SdFat uses SdFatSdio sd;, look at SdFat example TeensySdioDemo
    More specifically to use the T3.6 built-in microSD card, your sketch in post #1 should compile if you make these changes
    Code:
    //const uint8_t chipSelect = BUILTIN_SDCARD;
    
    // File system object.
    SdFatSdio sd;
    
    // Initialize at the highest speed supported by the board that is
      // not over 50 MHz. Try a lower speed if SPI errors occur.
      if (!sd.begin()) {

  6. #6
    Junior Member
    Join Date
    Jan 2018
    Posts
    1

    I think I have a similar problem. I'm trying to use the Timestamp example

    I have a similar problem and I am not seeing a solution posted in this thread. I'm trying to learn about the timestamp and how it works with the File names when creating a file on the SD card. I'm using a teensy 3.6. I posted the timestamp code below. All of the previous examples that I have used that work use
    Code:
    const int chipSelect = BUILTIN_SDCARD;
    for the teensy. But this Timestamp example uses
    Code:
    const uint8_t chipSelect = SS;
    The example compiles and runs but the Serial monitor says
    Type any character to start (I then type a character and below is the result)
    Can't access SD card. Do not reformat.
    No card, wrong chip select pin, or SPI problem?
    SD errorCode: 0X20,0XFF

    So I changed the chipSelect to
    Code:
    const int chipSelect = BUILTIN_SDCARD;
    Now the code does not compile and I get this error
    Code:
    Timestamp:13: error: 'BUILTIN_SDCARD' was not declared in this scope
     const int chipSelect = BUILTIN_SDCARD;
    
                            ^
    
    'BUILTIN_SDCARD' was not declared in this scope
    I tried to replace the
    Code:
    #include <SPI.h>
    #include "SdFat.h"
    libraries with the libraries from other examples that work such as
    Code:
    #include <SD.h>
    #include <SD_t3.h>
    #include <Wire.h>
    #include <TimeLib.h>
    But this just created more problems. If someone can point me to a thread that explain what I am doing wrong I would be greatfull.

    This is the Timestamp example code
    Code:
    /*
     * This program tests the dateTimeCallback() function
     * and the timestamp() function.
     */
    #include <SPI.h>
    #include "SdFat.h"
    
    SdFat sd;
    
    SdFile file;
    
    // Default SD chip select is SS pin
    const uint8_t chipSelect = SS;
    
    // create Serial stream
    ArduinoOutStream cout(Serial);
    //------------------------------------------------------------------------------
    // store error strings in flash to save RAM
    #define error(s) sd.errorHalt(F(s))
    //------------------------------------------------------------------------------
    /*
     * date/time values for debug
     * normally supplied by a real-time clock or GPS
     */
    // date 1-Oct-14
    uint16_t year = 2014;
    uint8_t month = 10;
    uint8_t day = 1;
    
    // time 20:30:40
    uint8_t hour = 20;
    uint8_t minute = 30;
    uint8_t second = 40;
    //------------------------------------------------------------------------------
    /*
     * User provided date time callback function.
     * See SdFile::dateTimeCallback() for usage.
     */
    void dateTime(uint16_t* date, uint16_t* time) {
      // User gets date and time from GPS or real-time
      // clock in real callback function
    
      // return date using FAT_DATE macro to format fields
      *date = FAT_DATE(year, month, day);
    
      // return time using FAT_TIME macro to format fields
      *time = FAT_TIME(hour, minute, second);
    }
    //------------------------------------------------------------------------------
    /*
     * Function to print all timestamps.
     */
    void printTimestamps(SdFile& f) {
      dir_t d;
      if (!f.dirEntry(&d)) {
        error("f.dirEntry failed");
      }
    
      cout << F("Creation: ");
      f.printFatDate(d.creationDate);
      cout << ' ';
      f.printFatTime(d.creationTime);
      cout << endl;
    
      cout << F("Modify: ");
      f.printFatDate(d.lastWriteDate);
      cout <<' ';
      f.printFatTime(d.lastWriteTime);
      cout << endl;
    
      cout << F("Access: ");
      f.printFatDate(d.lastAccessDate);
      cout << endl;
    }
    //------------------------------------------------------------------------------
    void setup(void) {
      Serial.begin(9600);
      // Wait for USB Serial
      while (!Serial) {
        SysCall::yield();
      }
      cout << F("Type any character to start\n");
      while (!Serial.available()) {
        SysCall::yield();  
      }
      // Initialize at the highest speed supported by the board that is
      // not over 50 MHz. Try a lower speed if SPI errors occur.
      if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) {
        sd.initErrorHalt();
      }
    
      // remove files if they exist
      sd.remove("callback.txt");
      sd.remove("default.txt");
      sd.remove("stamp.txt");
    
      // create a new file with default timestamps
      if (!file.open("default.txt", O_CREAT | O_WRITE)) {
        error("open default.txt failed");
      }
      cout << F("\nOpen with default times\n");
      printTimestamps(file);
    
      // close file
      file.close();
      /*
       * Test the date time callback function.
       *
       * dateTimeCallback() sets the function
       * that is called when a file is created
       * or when a file's directory entry is
       * modified by sync().
       *
       * The callback can be disabled by the call
       * SdFile::dateTimeCallbackCancel()
       */
      // set date time callback function
      SdFile::dateTimeCallback(dateTime);
    
      // create a new file with callback timestamps
      if (!file.open("callback.txt", O_CREAT | O_WRITE)) {
        error("open callback.txt failed");
      }
      cout << ("\nOpen with callback times\n");
      printTimestamps(file);
    
      // change call back date
      day += 1;
    
      // must add two to see change since FAT second field is 5-bits
      second += 2;
    
      // modify file by writing a byte
      file.write('t');
    
      // force dir update
      file.sync();
    
      cout << F("\nTimes after write\n");
      printTimestamps(file);
    
      // close file
      file.close();
      /*
       * Test timestamp() function
       *
       * Cancel callback so sync will not
       * change access/modify timestamp
       */
      SdFile::dateTimeCallbackCancel();
    
      // create a new file with default timestamps
      if (!file.open("stamp.txt", O_CREAT | O_WRITE)) {
        error("open stamp.txt failed");
      }
      // set creation date time
      if (!file.timestamp(T_CREATE, 2014, 11, 10, 1, 2, 3)) {
        error("set create time failed");
      }
      // set write/modification date time
      if (!file.timestamp(T_WRITE, 2014, 11, 11, 4, 5, 6)) {
        error("set write time failed");
      }
      // set access date
      if (!file.timestamp(T_ACCESS, 2014, 11, 12, 7, 8, 9)) {
        error("set access time failed");
      }
      cout << F("\nTimes after timestamp() calls\n");
      printTimestamps(file);
    
      file.close();
      cout << F("\nDone\n");
    }
    
    void loop() {}

  7. #7
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,200
    read post #5 more carefully. you need to change 2 lines in your sketch to

    SdFatSdio sd;

    if (!sd.begin()) {

  8. #8
    Junior Member
    Join Date
    Jun 2015
    Location
    Cambridge, UK
    Posts
    5
    Quote Originally Posted by manitou View Post
    read post #5 more carefully. you need to change 2 lines in your sketch to

    SdFatSdio sd;

    if (!sd.begin()) {
    Thank you this fixed my problem with TeensySdioInfo running on the Teensy3.5. Looks like this program really needs some edits to make it compatible with all Teensys including the v3.5. I was getting very confused as I assumed that it would work on *all* Teensys.
    BTW I have no idea how to do this (pls advise? #ifdef teensy3.5 ...???) or even who to send the modified code back to.

  9. #9
    Was there a fix for this issues, I am trying to get a ST7735 working with an Teensy 3.6. I am getting the same error and have modified the code as above, but still having the same problem.

    What/if is the fix for this issue?

    Name:  Screenshot 2019-09-16 at 09.24.39.png
Views: 135
Size:  20.3 KB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •