Incorrect operation of Arduino paired with MPU6050 and HC-05

Good afternoon I've been trying to figure out what the problem is with the program for a long time now, but I can't figure out the reason, I hope someone will have some ideas. The text will be quite large, please be patient =)

There are two Arduinos:
1 arduino (sending side NANO 168): arduino + HC-05 + MPU6050, arduino takes data from the MPU and sends the processed data via bluetooth
2 arduinos (receiving side UNO 328): arduino + HC-05, accepts data from 1 arduino and simply outputs them

Problem
1 arduino sends data to 2 arduinos, 2 arduinos show 4 float values in the COM port and everything seems to be fine, but here 2 paths appear:

Path 1 (90% chance of occurrence): after 5-20 seconds Arduino 2 stops receiving data and stops outputting new values, also after this the bluetooths are disconnected from each other and bluetooth 2 arduino again enters the device search (it is master), and Bluetooth 1 Arduino's LEDs turn off and that's it!
IMPORTANT OBSERVATION OF THE OPERATION OF THE LEDS OF TWO HC-05: when the system just turns on, the LEDs of the two bluetooths are in search (frequent blinking red LED), when they are connected, the master does not blink at all, and the slave blinks once every 3 seconds, the system works, but after what time - time, if the master blinks the LED at least once, then the data transfer stops completely and what I described above happens when they are disconnected

Way 2 (10% chance of occurrence): by some miracle this system works completely, nothing is disconnected and outputs the values as needed

In the code for Arudino 1 (see below), I thought that when the MPU sensor is quickly polled, the HC-05 cannot cope with such a speed and some kind of desynchronization occurs, I tried adding a separate loop where it sends more than once every 2 µs the main loop, and gave it more time, then it does not send anything at all and does not receive any values from the MPU, as if it had blocked the MPU and is not receiving anything.
Separately, I checked both the operation of the HC-05 (everything is fine, they transmit data) and only the MPU6050 (everything is also fine, it works), but as soon as I add data transmission to the code, a problem arises.

I also noticed (maybe it should be) that when I decided to look at what Arudino 1 outputs without a data transfer code, it outputs normal values

And when with a data transfer code

Installation diagram:

P.S. When I worked with bluetooth version 3.0, if they connect to each other and there is normal data transfer, then they blink synchronously with the red LED, now I’m working with version 5.0, it seems that after connection the master does not blink, and the slave blinks once every 3 seconds

**1 ARDUINO CODE **

#include "I2Cdev.h"
#include "MPU6050.h"

#include <EasyTransfer.h>


  #define TO_DEG 57.2957f
  #define TIME_GYRO 2000 // период опроса mpu6050 в микросекундах
MPU6050 accgyro;


// ------------------------ BLUETOOTH ----------------------------
struct SEND_DATA_STRUCTURE {
  float tax;
  float tay;
  float tgx;
  float tgy;
};

SEND_DATA_STRUCTURE data;
EasyTransfer ETin, ETout; // 2 объекта ИзиТрансфера 1 для отправки и 1 получения информации

// ----------------------------------------------------


int16_t ax_raw, ay_raw, az_raw, gx_raw, gy_raw, gz_raw; // сырые данные в кодах АЦП (3 ускорения и 3 скорости)
long int time_timer=0; // переменная таймера для опроса
long int timerBT=1000;

// ------------------------ АКСЕЛЕРОМЕТР ----------------------------
float ax, ay, az; // значения ускорения в единицах гравитации g
float angle_ax, angle_ax1, angle_ay, angle_az; // углы, рассчитанные по акселерометру


// ------------------------ ГИРОСКОП ----------------------------
float gx, gy, gz; // значения угловой скорости в градусах в секунду
float angle_gx, 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(19200); // скорость общения арудино с компьютером (нужно гораздо больше 9600)
  Serial.println("x, y, gx, gy");
  ETout.begin(details(data), &Serial);
  delay(5000);
  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(); // функция получения углов angle_ax, angle_ay, angle_az по акселерометру
    getAngleGyro(); // функция получения углов angle_gx, angle_gy, angle_gz по гироскопу
    getAngleFiltr(); // функция получения углов angle_fx, angle_fy, angle_fz с применением фильтра (по сути суммирует углы акселерометра и гироскопа)
    
    data.tax=angle_fx;
    data.tay=angle_fy;
    data.tgx=gx;
    data.tgy=gy;
    ETout.sendData();
    }

}
   /* if(timerBT < micros()) {
      timerBT= micros() + 8000;
      
    
    }*/
    /*data.tax=angle_fx;
    data.tay=angle_fy;
    data.tgx=gx;
    data.tgy=gy;
    ETout.sendData();*/

2 ARDUINO CODE

#include <EasyTransfer.h>

struct RECEIVE_DATA_STRUCTURE {
  float tax;
  float tay;
  float tgx;
  float tgy;
};

RECEIVE_DATA_STRUCTURE data;
EasyTransfer ETin,ETout;

void setup() {
  Serial.begin(19200);
  Serial.println("ax, ay, gx, gy");
  ETin.begin(details(data), &Serial);
  delay(4000);
  //Serial.flush();
  
}

void loop() {
  
  if(ETin.receiveData()) {

    Serial.print(data.tax);
    Serial.print(' ');
    Serial.print(data.tay);
    Serial.print(' ');
    Serial.print(data.tgx);
    Serial.print(' ');
    Serial.println(data.tgy);
  }
 }

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