Problem Using An 9 degree of freedom IMU with Ubuntu terminal

arduinoatmegaimu

I am using an IMU from sparkfun that posses an atmega328p.
I upload the source code and everything works fine when using the Arduino IDE.
I created a .sh script to read from the terminal in ubuntu.

When I read the scripts to initialize the communication with the arduino using the stty command it works, but when I try to retrieve the data the process keeps running until I hit ctrl+z to stop the process and I get trash data.
In order for the scripts to work I need to open the serial monitor in arduino and send one command. Then I can use the .sh file that I created to run and read the data from the IMU from the terminal without problem. I want to be able to run everything without having to use the arduino since the system is going to be running in a computer and everything will be called from a Linux terminal.

If someone has an idea and can help me to solve this problem I will be grateful.

Best Answer

Arduino sends a bunch of NUL bytes after it resets. Also the buffers of your PC will probably have data from previous sessions in them, you have to flush these. Also I chose to start using frames with a preamble for communication between PC and Arduino. That way you can easily lock onto the data stream. I've written a couple of Perl scripts for this: cat_ttyUSB