Restarting Teensy LC everytime to establish connection with raspberry pi 4

I am using Teensy LC to send data (continuous sensor values) to raspberry pi 4 through serial communication, I'm using the raspberry pi only to run a GUI, that displays graph from Teensy. I'm using pyserial in rpi to read from Teensy.

But each time I start/restart the raspberry pi I also have to restart the Teensy LC to establish the serial connection and the data transfer. (Teensy is powered through rpi USB)

I suspect this might be due to the differences in the booting speeds of teensy LC and raspberry pi4. Is there any way to solve this issue without having to restart Teensy every time?

Thank you
 
Yes, the Teensy LC will be fully booted and executing its program earlier than the RPI will.
A possible solution could be to have the Teensy wait for the RPI by means of the Serial.available() function. The RPI, after being fully booted, will have to transmit some byte over the serial interface to the Teensy before listening to the serial port for sensor data from the Teensy.
Sequence: Teensy boots > Teensy waits for byte from RPI > RPI boots > RPI sends byte > Teensy starts transmitting data > RPI receives data.

Paul
 
Adding this piece of code to the setup worked fine,

while (!Serial){
;
}

this makes the teensy wait until the rpi establishes the serial connection.
 
Back
Top