Serial Command Window stops working

Dear all,
I am working on a project using the Sparkfun Razor IMU sensor and an Arduino Uno. I managed to get some data from the IMU sensor to the Arduino Uno by doing serial prints on the screen. I have edited the code provided by the Sparkfun tutorial https://github.com/Razor-AHRS/razor-9dof-ahrs/wiki/Tutorial However, the serial command window just freezes inconsistently. Sometimes, it freezes in the start and sometimes it runs for a few seconds. Therefore, please reply to this post if you have encountered similar problems. Thank you in advance!

Hello there!

Can you please post the modified code that you are currently using, remembering to use the code tags?

These are the code that i used. Only look at RazorIMUCode and IMUArduino. The others are just files provided by the tutorial. Output is where the output functions are. Thanks in advance!

Compass.ino (595 Bytes)

DCM.ino (4.56 KB)

Math.ino (2.14 KB)

RazorIMUCode.ino (9.9 KB)

Sensors.ino (6.62 KB)

IMUArduino.ino (6.15 KB)

Output.ino (2.67 KB)

junpun95:
These are the code that i used. And what do you mean by code tags?

When you use quote tags put {code] Enter code here {/code](Use all square brackets)
Then it will look like this

if 7==3:
    enter the castle.

It can help with confusing codes

This is my loop for the Arduino:

void loop() {
  if (Serial.available() > 0){
      /* This is to get just the rotation value */
      outgoingByte = 1;
      read_angle();
      get_data(outgoingByte);
      // Output angles from IMU
      output_angles();
  }
  else Serial.println("No response from IMU.");
}

This is my loop for the IMU:

void loop()
{
  if ((millis() - timestamp) >= OUTPUT__DATA_INTERVAL)
  {
    timestamp_old = timestamp;
    timestamp = millis();
    // This is for drift correction
    if (timestamp > timestamp_old)
      G_Dt = (float) (timestamp - timestamp_old) / 1000.0f; // Real time of loop run. We use this on the DCM algorithm (gyro integration time)
    else G_Dt = 0;
    // Update sensor readings
    read_sensors();
  }
  // Read incoming control messages
  if (Serial.available() > 0)
  {
    // read angle
    if (Serial.read() == '1') // Start of new control message
    {
      // Apply sensor calibration
      compensate_sensor_errors();
      
      Compass_Heading(); // Calculate magnetic heading
      Matrix_update();
      Normalize();
      Drift_correction();
      Euler_angles();
      
      outgoingByte[0] = yaw;
      outgoingByte[1] = pitch;
      outgoingByte[2] = roll;
    }
    // read accel
    else if (Serial.read() == '2')
    {
      for (int i = 0; i < 3; i++) {
        outgoingByte[i] = accel[i];
      }
    }
    outgoingByte[3] = '\n';
    Serial.write(outgoingByte, sizeof(outgoingByte));
    Serial.flush();
  }
}

I see your code tags problem. use {code] ENTER YOUR CODE HERE {/code]
^ but make it square ^make it square

It may help to lookup and html reference. html tags are like this:

(opens a paragraph)

YOU TYPE YOU PARAGRAPH HERE

(closes paragraph) in the end it looks like this

Hello world

or in the webpage Hello World

Instead you put your code inside the tag not between them.

Also there is a preview button click it and make sure your post looks good.

Thank you. I've used code tags. Please feel free to comment on this if any of you encountered this

In Reply #2 you posted several programs. Which one do you want help with?

In Reply #4 you seem to have posted parts of 2 programs - why?

Always post complete programs, not snippets.

…R

I am trying to get data from the Sparkfun Razor IMU sensor using serial communication. However, the serial monitor just freezes randomly. Therefore, I posted the complete code in Reply #2. In Reply #4, that is a snippet of the loop function which i thought is useful if readers don't want to look through the complete code.

Sorry. I had not realized that all of the files in Reply #2 represent a single program.

And, sorry again, but I am too lazy to struggle through all of that.

...R