unnessary serial output SD

Status
Not open for further replies.

Gerald36

New member
My Teensy 3.6 is connected to a separate SD card reader. It reads text data. When I run this sketch on an Arduino UNO is runs fine. But on a Teensy 3.6 it won't start. When I start the serial monitor I get an empty serial message and the sketch starts running immediatly. This prevents using my Teensy 3.6 stand alone. Who kwows what I can do to use the Teensy stand alone? Thanks!

// Teensy 3.6 hangs on unnessary serial output on PC
//SD: 13=CK 12=DO 11=DI 4=CS
#include <SPI.h>
#include <SD.h>
#include <LiquidCrystal.h>
char inbyte;
const int chipSelect = 4;
LiquidCrystal lcd(9,8,6,5,3,2);
File myFile;
void setup() {
lcd.begin (20,4);
Serial.begin(9600);
while (!Serial) { ; }
lcd.print ("init SD card");delay(2000);
if (!SD.begin(chipSelect)) {
lcd.print ("init failed");delay(2000);
return; }
lcd.clear();lcd.print ("init done");delay(2000);
myFile = SD.open("test.txt",FILE_READ);
if (!myFile){lcd.print("error opening SD");delay(2000);}
else {
while (myFile.available()) {
inbyte = myFile.read();
lcd.print(inbyte);lcd.print(" ");delay(100); // show data
if (inbyte == '/'){break;} // end of data
}
lcd.print ("all done");
}
}
void loop()
{}
-----------
 
the line
Code:
while(!Serial) {;}
waits for serial terminal to be connected.
either remove line ans all Serial lines
or modify
Code:
while(!Serial & millis()<1000) {;}

also use
HTML:
[CODE] your code [/CODE]
to better format your code on forum (so we can read it better)
 
FYI - IIRC: Serial.begin(9600); was changed a build or so back to wait for some time over 1 second for serial to appear before it returns. This gives a short built in wait until connected. I don't find the code behind it though.
 
Status
Not open for further replies.
Back
Top