nathanielbelles
Member
Hello,
I'm currently working on a project where velocity commands for a robot are sent from a computer over USB Serial to a Teensy 4.1. On the computer side of things I am writing a short string (roughly 10 to 15 bytes ending with a '\n' character) to the serial port at 250Hz. On the Teensy I am continuously checking SerialUSB.available() and then get the characters using SerialUSB.read(). When I detect the '\n' I store the current time according to micros() and print that out. From my testing, the difference in time between detections of the '\n' character (indicating new message has arrived) ranges from 4ms (250Hz) to 10ms (100Hz) which is not the desired frequency.
I'm curious if this is something that is inherent to using serial over USB or if there is something I can do on the Teensy to get it up to the desired 250Hz?
Similar example Teensy code:
Similar example serial publishing shell script:
Thanks!
(Note: this is a simplified example of the code I am running on the Teensy and a simplified example of what I am running to write data to the serial line. Hopefully these simplifications don't introduce any unintended differences from what I am actually running.)
I'm currently working on a project where velocity commands for a robot are sent from a computer over USB Serial to a Teensy 4.1. On the computer side of things I am writing a short string (roughly 10 to 15 bytes ending with a '\n' character) to the serial port at 250Hz. On the Teensy I am continuously checking SerialUSB.available() and then get the characters using SerialUSB.read(). When I detect the '\n' I store the current time according to micros() and print that out. From my testing, the difference in time between detections of the '\n' character (indicating new message has arrived) ranges from 4ms (250Hz) to 10ms (100Hz) which is not the desired frequency.
I'm curious if this is something that is inherent to using serial over USB or if there is something I can do on the Teensy to get it up to the desired 250Hz?
Similar example Teensy code:
Code:
void setup()
{
SerialUSB1.println("Setting up");
}
void loop()
{
if (SerialUSB.available())
{
SerialUSB1.println(micros());
while (SerialUSB.available())
{
SerialUSB1.println((char)SerialUSB.read());
}
}
}
Similar example serial publishing shell script:
Code:
while :
do
echo "0.000 0.000" > /dev/ttyACM0
sleep 0.004
done
Thanks!
(Note: this is a simplified example of the code I am running on the Teensy and a simplified example of what I am running to write data to the serial line. Hopefully these simplifications don't introduce any unintended differences from what I am actually running.)