Slow Serial

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
CedricM
 
Posts: 6
Joined: Wed May 03, 2023 8:24 am

Slow Serial

Post by CedricM »

Hello,

I am making my first steps with an Itsy Bitsy 32u4. I wrote a test program that reads a string from Serial but it looks very slow compared to other devices. Using the Arduino IDE Serial monitor, I have to wait approximately 1 second to get the answer. Am I doing something wrong ?

Code: Select all

// Testing the Itsy bitsy 5V
#define TEST_PIN 9

String s;
bool on;

void setup() {
  Serial.begin(115200);
  pinMode(13, OUTPUT);
  delay(3000);
  Serial.println("Program start");
  digitalWrite(13, HIGH);
}

void loop() {
//to look at the frequency on a scope
on = !on ;
digitalWrite(TEST_PIN, on);

  if ( Serial.available() > 0) {
    s = Serial.readString();
    Serial.print("You wrote: ");    
    Serial.println(s);
  }
}
I also set an output on and off every loop (commenting the rest of the loop). it changes every 6us. corresponding to a 32KHz frequency if I'm correct. Is it not supposed to run at 16MHz ? Do I have to change registers to obtain that speed ?

Thank you in advance,
Cedric

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: Slow Serial

Post by adafruit_support_bill »

I wrote a test program that reads a string from Serial but it looks very slow compared to other devices.
USB serial is not the same as a real serial port. The characters are collected into a buffer and periodically sent in packets. The device drivers on your computer may use different packetizing parameters that affect the timing.
t changes every 6us. corresponding to a 32KHz frequency if I'm correct. Is it not supposed to run at 16MHz ?
16MHz is the basic clock frequency of the processor. It takes multiple cycles for each machine instruction, and there will be multiple machine instructions per line of code - not to mention all the code in the Arduino libraries that you are calling from your program.

User avatar
CedricM
 
Posts: 6
Joined: Wed May 03, 2023 8:24 am

Re: Slow Serial

Post by CedricM »

Hi Bill, thanks for the reply

I found out why the answering was so slow. I forgot to write: "Serial.setTimeout(0);"

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”