SIMPLE FAT FS example for Teensy 3.6

Status
Not open for further replies.

starfire151

Active member
First, I apologize if this has been asked 1000 times before...

I'm just starting with the Teensy 3.6 module. I've created simple programs to exercise input, output, light LEDs, etc, so I know my software-to-hardware interface is working correctly.

I would like to create a simple data logging application to record the analog voltages of 3 or 4 points in a separate test circuit every 15 or 20 minutes and record the values to a file on the integrated uSD card on the Teensy 3.6. I can then move the card to my PC later for analysis of the data.

I'm getting totally overwhelmed by the amount of information on SD FAT file systems out there. I'm really looking for a ---SIMPLE--- example targeted for the Teensy 3.6 with file open, close, read, write, etc.

Can someone help point me in the right direction? :confused:

Thanks...
 
Just posted this on another thread - see if it helps

// Teensy 3.5 & 3.6 on-board: BUILTIN_SDCARD
const int chipSelect = BUILTIN_SDCARD;

To confirm card function select "chipSelect = BUILTIN_SDCARD" here to see if the card list of files can be read : ...\hardware\teensy\avr\libraries\SD\examples\listfiles\listfiles.ino

Doing that here on a FAT32 formatted card works.

With that done perhaps in the sample can this be made to work : ...\hardware\teensy\avr\libraries\SD\examples\Datalogger\Datalogger.ino
 
Just posted this on another thread - see if it helps

Thanks for responding so quickly.

If I understand you and the SD example files, it appears I have to wire an external uSD/SD card slot using the SPI0 interface of the Teensy 3.6? I would then put the const int chipSelect = BUILTIN_SDCARD; line at the top of the file?

How do I access the built-in uSD card slot on the module?

Thanks, again.
 
For the hardware with the T_3.6 an SD card goes into the socket on the T_3.6 PCB - nothing else is wired or needed.

For the software that value for const int chipSelect = BUILTIN_SDCARD; is then set in software, like in the indicated examples included with TeensyDuino.
 
I loaded the Sdinfo.ino example file, modified the line stating #define USE_SDIO 0 to #define USE_SDIO 1, compiled, downloaded, and ran. I get the following response:

SdFat version: 10102



type any character to start



init time: 16 ms



Card type: SD2



Manufacturer ID: 0X3

OEM ID: SD

Product: SU02G

Version: 8.0

Serial number: 0X89947CA0

Manufacturing date: 8/2009



cardSize: 1977.61 MB (MB = 1,000,000 bytes)

flashEraseSize: 32 blocks

eraseSingleBlock: true

OCR: 0X80FF8000



SD Partition Table

part,boot,type,start,length

1,0X0,0X6,135,3858489

2,0X0,0X0,0,0

3,0X0,0X0,0,0

4,0X0,0X0,0,0



Volume is FAT16

blocksPerCluster: 64

clusterCount: 60281

freeClusters: 4294967295

freeSpace: 140737488.00 MB (MB = 1,000,000 bytes)

fatStartBlock: 136

fatCount: 2

blocksPerFat: 236

rootDirStart: 608

dataStartBlock: 640

So it appears the card is accessing correct information. The line toward the beginning of the program is const uint8_t SD_CHIP_SELECT = SS;

Where would I look for additional open, close, read, write, etc, commands?

.
 
post #2 noted ...\hardware\teensy\avr\libraries\SD\examples\Data logger\Datalogger.ino

Under files \ examples \ SD datalogger will be there

Or follow the indicated path in the Arduino install directory ( that is windows )
 
Hi wcalvert -

The example your pointing to appears to require an external SPI interface, not the built-in uSD card interface.

I was looking for an example to read/write (as the example you pointed to) but using the built-in uSD card.

This is all very confusing... There is a mix of different .h files called, setup requirements, etc.

As I'm just starting with the Arduino/Teensy environment (I had been programming PICs with the CCS envrionment prior to this), I'd just like a consistent starting point to explain how to get access to the uSD card included with the Teensy 3.6 to do simple analog port reads periodically and write summary information to file(s) on the uSD card....
 
To minimize confusion perhaps start with the supplied PJRC SD library indicated examples in post #2.

That alternate library is usable and good if using the current version AFAIK - and is compatible and supports the T_3.6 SD socket - and the examples ideally work and has documentation beyond the examples on github.
 
Hi wcalvert -

The example your pointing to appears to require an external SPI interface, not the built-in uSD card interface.

I was looking for an example to read/write (as the example you pointed to) but using the built-in uSD card.

This is all very confusing... There is a mix of different .h files called, setup requirements, etc.

As I'm just starting with the Arduino/Teensy environment (I had been programming PICs with the CCS envrionment prior to this), I'd just like a consistent starting point to explain how to get access to the uSD card included with the Teensy 3.6 to do simple analog port reads periodically and write summary information to file(s) on the uSD card....

The thing to keep in mind is that a well written library will expose the exact same API (open, read, write, close, etc) no matter what interface (SPI, SDIO, built-in SD card or external) is being used.

To further complicate things, the examples I mistakenly linked you to were for a community SdFat library by Greiman, and I suppose you are using the "official" SD library.

I agree with defragster - it is best to start with the example he's referring to. Sorry to confuse you. PS, the examples for the "official" SD library are here: https://github.com/PaulStoffregen/SD/tree/master/examples
 
OK. So I loaded the listfiles.ino program from my C:\Users\starf\Documents\Arduino\libraries\SD\examples\listfiles directory.

When I compile it, it compiles OK. When I download it and try to run it I get:

Initializing SD card...initialization failed!

I tried to go to the source file and add the line from Post #2: const int chipSelect = BUILTIN_SDCARD; I added it after the
#include <SPI.h>
#include <SD.h>

When I tied to compile, I get the following error messages:

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

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

^

Multiple libraries were found for "SD.h"
Used: C:\Users\starf\Documents\Arduino\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SD
Not used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
'BUILTIN_SDCARD' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

-------------

What am I doing wrong?
 
You can:

#define BUILTIN_SDCARD 254

Or:

#include "Sd2Card.h"

I suppose the examples are somewhat out of sync with the development that has occurred. Also, just in case it's not clear, BUILTIN_SDCARD is just referring to the chip select, which on lower-spec boards was any old IO pin. The 3.x and 4.0 have dedicated chip select built into the SPI interface. That is why you can define BUILTIN_SDCARD to a dummy value when you are compiling for the 3.x and 4.x boards.
 
This 'local/private' library needs to be removed :: Used: C:\Users\starf\Documents\Arduino\libraries\SD

It is being used instead of the needed :: Not used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
 
That's a good catch too, I didn't realize he had a conflicting Arduino vs Teensy situation happening.
 
Many thanks for helping get me through this ---trying--- times!!!

It appears most of my issues were related to older versions... When I removed the C:\Users\starf\Documents\Arduino\ directory, loaded the C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD\examples\listfiles\listfiles.ino file, replaced the line const int chipSelect = 4; with const int chipSelect = BUILTIN_SDCARD;, successfully compiled, downloaded, and ran, it came back with:

Initializing SD card...initialization done.
SYSTEM~1/
WPSETT~1.DAT 12
INDEXE~1 76
done!

YEA!!!

It looks like I may be off to the races!

Thanks, again, to all who responded...
 
Status
Not open for further replies.
Back
Top