Using Teensy 3.5 SD Card Port with Existing Code

Status
Not open for further replies.

Ryan Klimek

New member
Hello,

I am pretty inexperienced with programming anything on the Teensy. The code I attached is designed to run on the Teensy 3.5, and it records data from two temperature sensors, a humidity sensor, and a pressure sensor. The code works and prints the readings from the sensors on the serial monitor. I want this data to record to an SD Card in the SD Port on the Teensy 3.5. I have seen several different forums about using the SD Port, but I have not been able to get it to work with my code yet. Can you show me the code and libraries that I need to integrate into this code to make it work? Thank you.

View attachment Basic_Sensor_Package_Test_2.ino
 
In file->examples->SD <-- the one under teensy if you have more than one showing up

there is various examples, including read/write
At the top of that there is
Code:
// 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
// Teensy audio board: pin 10
// Teensy 3.5 & 3.6 on-board: BUILTIN_SDCARD
// Wiz820+SD board: pin 4
// Teensy 2.0: pin 0
// Teensy++ 2.0: pin 20
const int chipSelect = 4;
Saying that you need to change the chipselect =4 to chipSelect =BUILTIN_SDCARD
See also
https://www.arduino.cc/en/Reference/SD
Note that this is for the default Arduino library that uses SPI only, not the higher performance one needed on a Teensy 3.5. This should all just work even if more than one is installed but if you hit problems that would be the first things to check.
 
Hello,

Thank you for your help. I got the program to write to the SD Card and I posted what I have now at the bottom of this message. However, I need the program to write to the SD Card independently of my computer. I have a battery setup that supplies power to the Teensy while it is not plugged into my computer. But, I have not been able to get this program to run and write data to the SD Card while it is not plugged into my computer. Do you know what I should do to accomplish this? Do I need to add several lines of code to the program for the data to write to the card independently of my computer?

View attachment Basic_Sensor_Package_Test.ino
 
This would be your problem:

while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

It is waiting for a serial port to connect, and that will not happen on battery
 
Status
Not open for further replies.
Back
Top