Help needed on how to print the number of samples per second in Teensy board

New_bee

Active member
I am new to Teensy board. I was trying to run my first code to count the number of samples per second . the same code ran very well on ESP8266 but nothing on the Teensy board.

HTML:
unsigned long startTime;
uint32_t helloWorldCount = 0;

void setup() {
  // put your setup code here, to run once:
Serial.begin(115000);
startTime = millis();
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.println("hello, world");

helloWorldCount++;

if (millis() - startTime >1000){
  Serial.print("printed per second: ");
  Serial.println(helloWorldCount);
  startTime = millis();
  helloWorldCount = 0;
}
}

HTML:
hello, world
hello, world
hello, world
printed per second: 823
hello, world
hello, world
hello, world
 
Try adding this line after Serial.begin(115200);
while (!Serial && millis() < 5000){} // waits for connection to PC

It's possible that the Teensy is SO fast that it has "printed" the data before comms are set up with the PC.
 
Try adding this line after Serial.begin(115200);
while (!Serial && millis() < 5000){} // waits for connection to PC

It's possible that the Teensy is SO fast that it has "printed" the data before comms are set up with the PC.

Thanks for your code and it is working now. I replaced {} from your line of code with ;
 
Back
Top