Data in the port monitor is no longer displayed

Good afternoon! I am implementing a project on Arduino Uno and faced the following problem. I have an MPU6050 module, and I read data from it and calculate the angle (along the Y axis). I also have a micro vibration motor in my circuit, which is triggered when the angle values fall into the range I need:

if ((angle_fy > -20) && (angle_fy < 20)) 
{
  digitalWrite(motorPin, HIGH); 
} 
else 
{ 
  digitalWrite(motorPin, LOW);
}

And everything would be fine, but there was a problem. The program calculates the angle correctly and the motor is triggered at the right time, but sometimes there is a problem displaying the angle data in the port monitor. That is, I change the orientation of the MPU6050 module, the angle changes in the port monitor, and at one point the data stops updating in the port monitor, the data freezes. And, for example, if this happened in the range: (angle_fy > -20) && (angle_fy < 20), then the motor constantly continues to vibrate, even if I change the orientation of the layout. What could this be related to?

Welcome to the forum

As your problem is probably not with the IDE itself your topic has been moved to the Programming category of the forum

Please post your sketch (use code tags when you do) and a schematic of your project. A photo of a hand drawn circuit is good enough

to the rest of the code we did not see may be ?

#include “I2Cdev.h”
#include “MPU6050.h”

#define TO_DEG 57.2957f
#define TIME_GYRO 2000 
MPU6050 accgyro;

int16_t ax_raw, ay_raw, az_raw, gx_raw, gy_raw, gz_raw; 
long int time_timer; 
int motorPin = 3; 


float ax, ay, az; //  g
float angle_ax, angle_ax1, angle_ay, angle_az;

float gx, gx0, gy, gz; 
float angle_gx, angle_gx0, angle_gy, angle_gz; 
float gyro_x_zero, gyro_y_zero, gyro_z_zero; 


float angle_fx, angle_fy, angle_fz; 

void setup() {
Serial.begin(9600);
isCrash = true;
// 115200
pinMode(motorPin, OUTPUT);
accgyro.initialize();
calibrateMPU();
}

void loop() {
if( time_timer < micros() )
{
time_timer = micros() + TIME_GYRO;
accgyro.getMotion6(&ax_raw, &ay_raw, &az_raw, &gx_raw, &gy_raw, &gz_raw);
getAngleAcsel();
getAngleGyro();
getAngleFiltr();
Serial.println(angle_fy);

if ((angle_fy > -20) && (angle_fy < 20)) 
{
  digitalWrite(motorPin, HIGH); 
} 
else 
{ 
  digitalWrite(motorPin, LOW);
}

}

}

#define FK 0.99 

void getAngleFiltr() { / angle
angle_fx = angle_fx + gx * TIME_GYRO/1000000.0;
angle_fy = angle_fy + gy * TIME_GYRO/1000000.0;
angle_fz = angle_fz + gz * TIME_GYRO/1000000.0;

angle_fx = angle_fx*FK + angle_ax*(1-FK);
angle_fy = angle_fy*FK + angle_ay*(1-FK);
angle_fz = angle_fz*FK + angle_az*(1-FK);

}

Does this freeze seem to happen about an hour and ten minutes into the run?

This timing code will fail at that point.

Change:

long int time_timer; 

to

uint32_t time_timer; 

and

if( time_timer < micros() )

to

if( micros() - time_timer > TIME_GYRO )

Oh I missed that the variable wasn't unsigned. Let me correct my previous post. The timing code in the OP will fail at a little over half an hour. Not one hour as previously stated.

The data is transmitted to be updated in less than 30 minutes. I can't figure out what the problem is.

It doesn't help. A program malfunction occurs when data falls within this range

if ((angle_fy > -20) && (angle_fy < 20))

The data stops being updated and the motor constantly vibrates.

How are you powering the motor? You're not trying to power the motor from the Arduino pin are you?


I use the classic connection scheme

The motor may require it's own power supply. The Arduino board is not built to supply power to motors, despite so many pictures all over the internet like the one you posted. They're even on this site. But it's still not a good idea.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.