samm_flynn
Active member
Hey everyone,
I have a Teensy 4.1 controlling two motors, and I need a way to disarm them if the USB serial connection is lost. Right now, in my control loop, which runs every 1ms, I check Serial.dtr() before sending any commands to the motors.
However, I was wondering if there’s a way to avoid polling Serial.dtr() every cycle and instead have an event-based approach, like setting a variable to true or false automatically when the USB serial is opened or closed.
The main reason for this is safety. My PC app (written in Python) sends commands over USB, and a USB disconnection is a major concern. If the USB disconnects unexpectedly, I need the motors to immediately stop without waiting for the next loop iteration to check Serial.dtr().
Is there a way to achieve this using USB events or interrupts instead of polling? Maybe something in the USB stack that I can hook into? Any guidance would be greatly appreciated!
I swear I saw a thread discussing this, but can't find it. Sorry if this post is a duplicate.
I have a Teensy 4.1 controlling two motors, and I need a way to disarm them if the USB serial connection is lost. Right now, in my control loop, which runs every 1ms, I check Serial.dtr() before sending any commands to the motors.
However, I was wondering if there’s a way to avoid polling Serial.dtr() every cycle and instead have an event-based approach, like setting a variable to true or false automatically when the USB serial is opened or closed.
The main reason for this is safety. My PC app (written in Python) sends commands over USB, and a USB disconnection is a major concern. If the USB disconnects unexpectedly, I need the motors to immediately stop without waiting for the next loop iteration to check Serial.dtr().
Is there a way to achieve this using USB events or interrupts instead of polling? Maybe something in the USB stack that I can hook into? Any guidance would be greatly appreciated!
I swear I saw a thread discussing this, but can't find it. Sorry if this post is a duplicate.