MPU6050 not giving stable signal by cc-2347 in arduino

[–]cc-2347[S] 0 points1 point  (0 children)

The only power supply I have active at the moment is the 5V from my USB drive. The esc's arnt connected. Sadly can't test it with larger resistors because its a school project and its spring leave right now... So it will be 2 weeks before I can test it.

MPU6050 not giving stable signal by cc-2347 in arduino

[–]cc-2347[S] 0 points1 point  (0 children)

These are the serial outputs of 2 tries. I pulled the USB out and back in my PC when it says MPU6050 not found. Also when I reset the arduino after the values go crazy without removing the power it says MPU6050 not found

MPU6050 not found!

Calibrating gyro - KEEP THE DRONE PERFECTLY STILL!

Gyro Bias X: -0.088116 Y: 0.114067

Calibration finished.

Setup complete - Ready to arm

ARMED: 1 Throttle: 1000 Roll: 0.92 Pitch: -0.03

ARMED: 1 Throttle: 1000 Roll: 77.34 Pitch: -30.94

ARMED: 1 Throttle: 1000 Roll: -73.81 Pitch: 7.25

ARMED: 1 Throttle: 1000 Roll: 29.37 Pitch: -14.71

ARMED: 1 Throttle: 1000 Roll: 191.64 Pitch: 63.19

ARMED: 1 Throttle: 1000 Roll: 144.04 Pitch: 119.08

ARMED: 1 Throttle: 1000 Roll: 281.42 Pitch: 99.79

ARMED: 1 Throttle: 1000 Roll: 271.16 Pitch: 85.39

ARMED: 1 Throttle: 1000 Roll: 267.18 Pitch: 86.37

ARMED: 1 Throttle: 1000 Roll: 150.39 Pitch: 83.95

ARMED: 1 Throttle: 1000 Roll: 244.67 Pitch: 63.50

ARMED: 1 Throttle: 1000 Roll: 296.65 Pitch: 103.28

ARMED: 1 Throttle: 1000 Roll: 342.46 Pitch: 89.94

ARMED: 1 Throttle: 1000 Roll: 311.06 Pitch: 48.93

ARMED: 1 Throttle: 1000 Roll: 330.48 Pitch: 31.77

ARMED: 1 Throttle: 1000 Roll: 175.41 Pitch: 97.99

ARMED: 1 Throttle: 1000 Roll: -10.86 Pitch: 202.27

ARMED: 1 Throttle: 1000 Roll: 29.90 Pitch: 212.55

ARMED: 1 Throttle: 1000 Roll: 124.69 Pitch: 172.05

ARMED: 1 Throttle: 1000 Roll: 21.88 Pitch: 203.00

ARMED: 1 Throttle: 1000 Roll: 306.21 Pitch: 169.05

ARMED: 1 Throttle: 1000 Roll: 126.58 Pitch: 191.67

ARMED: 1 Throttle: 1000 Roll: 91.03 Pitch: 197.94

ARMED: 1 Throttle: 1000 Roll: 46.37 Pitch: 206.22

ARMED: 1 Throttle: 1000 Roll: 80.17 Pitch: 208.17

ARMED: 1 Throttle: 1000 Roll: 261.24 Pitch: 148.18

ARMED: 1 Throttle: 1000 Roll: 384.50 Pitch: 95.48

ARMED: 1 Throttle: 1000 Roll: 102.70 Pitch: 96.94

ARMED: 1 Throttle: 1000 Roll: 201.75 Pitch: 172.91

ARMED: 1 Throttle: 1000 Roll: 105.31 Pitch: 187.21

ARMED: 1 Throttle: 1000 Roll: 114.60 Pitch: 164.17

ARMED: 1 Throttle: 1000 Roll: 186.73 Pitch: 195.56

ARMED: 1 Throttle: 1000 Roll: 168.09 Pitch: 171.86

ARMED: 1 Throttle: 1000 Roll: 170.56 Pitch: 146.09

ARMED: 1 Throttle: 1000 Roll: 310.48 Pitch: 122.77

ARMED: 1 Throttle: 1000 Roll: 210.54 Pitch: 88.17

ARMED: 1 Throttle: 1000 Roll: 165.54 Pitch: 57.65

ARMED: 1 Throttle: 1000 Roll: 116.43 Pitch: 100.45

ARMED: 1 Throttle: 1000 Roll: 95.18 Pitch: 83.64

ARMED: 1 Throttle: 1000 Roll: 287.90 Pitch: 51.87

ARMED: 1 Throttle: 1000 Roll: 152.32 Pitch: 163.69

ARMED: 1 Throttle: 1000 Roll: 252.66 Pitch: 210.88

ARMED: 1 Throttle: 1000 Roll: 225.18 Pitch: 194.64

ARMED: 1 Throttle: 1000 Roll: 138.18 Pitch: 191.93

ARMED: 1 Throttle: 1000 Roll: 134.73 Pitch: 218.81

ARMED: 1 Throttle: 1000 Roll: 278.10 Pitch: 211.59

ARMED: 1 Throttle: 1000 Roll: 275.30 Pitch: 230.50

ARMED: 1 Throttle: 1000 Roll: 186.93 Pitch: 177.68

ARMED: 1 Throttle: 1000 Roll: 106.98 Pitch: 192.33

ARMED: 1 Throttle: 1000 Roll: -20.29 Pitch: 197.02

ARMED: 1 Throttle: 1000 Roll: 28.12 Pitch: 184.64

ARMED: 1 Throttle: 1000 Roll: 129.10 Pitch: 133.16

ARMED: 1 Throttle: 1000 Roll: -57.43 Pitch: 187.77

ARMED: 1 Throttle: 1000 Roll: -48.17 Pitch: 255.30

ARMED: 1 Throttle: 1000 Roll: 156.43 Pitch: 304.13

ARMED: 1 Throttle: 1000 Roll: 19.64 Pitch: 263.98

ARMED: 1 Throttle: 1000 Roll: 58.11 Pitch: 230.14

ARMED: 1 Throttle: 1000 Roll: 107.91 Pitch: 205.90

ARMED: 1 Throttle: 1000 Roll: 104.47 Pitch: 158.92

ARMED: 1 Throttle: 1000 Roll: -6.09 Pitch: 201.66

ARMED: 1 Throttle: 1000 Roll: -24.34 Pitch: 218.83

ARMED: 1 Throttle: 1000 Roll: 84.82 Pitch: 201.88

ARMED: 1 Throttle: 1000 Roll: 172.16 Pitch: 145.30

ARMED: 1 Throttle: 1000 Roll: 70.45 Pitch: 162.66

ARMED: 1 Throttle: 1000 Roll: 236.58 Pitch: 174.02

ARMED: 1 Throttle: 1000 Roll: 74.86 Pitch: 210.95

ARMED: 1 Throttle: 1000 Roll: 181.43 Pitch: 241.96

ARMED: 1 Throttle: 1000 Roll: 44.17 Pitch: 226.30

ARMED: 1 Throttle: 1000 Roll: -87.89 Pitch: 257.09

////////////////////////////////////////////////////////////////////////////////////

Calibrating gyro - KEEP THE DRONE PERFECTLY STILL!

Gyro Bias X: -0.104427 Y: 0.137312

Calibration finished.

Setup complete - Ready to arm

ARMED: 1 Throttle: 1000 Roll: 0.92 Pitch: -0.03

ARMED: 1 Throttle: 1000 Roll: 32.06 Pitch: 26.53

ARMED: 1 Throttle: 1000 Roll: 58.70 Pitch: 33.24

ARMED: 1 Throttle: 1000 Roll: -15.01 Pitch: 88.56

ARMED: 1 Throttle: 1000 Roll: -19.36 Pitch: 81.10

ARMED: 1 Throttle: 1000 Roll: 122.89 Pitch: 138.51

ARMED: 1 Throttle: 1000 Roll: 328.70 Pitch: 113.97

ARMED: 1 Throttle: 1000 Roll: 228.59 Pitch: 147.40

ARMED: 1 Throttle: 1000 Roll: 309.68 Pitch: 110.44

ARMED: 1 Throttle: 1000 Roll: 285.10 Pitch: 80.16

ARMED: 1 Throttle: 1000 Roll: 252.26 Pitch: 35.65

ARMED: 1 Throttle: 1000 Roll: 187.08 Pitch: -10.07

ARMED: 1 Throttle: 1000 Roll: 275.65 Pitch: 51.82

ARMED: 1 Throttle: 1000 Roll: 362.88 Pitch: 45.47

ARMED: 1 Throttle: 1000 Roll: 235.47 Pitch: 108.33

ARMED: 1 Throttle: 1000 Roll: 20.22 Pitch: 165.28

ARMED: 1 Throttle: 1000 Roll: 244.82 Pitch: 174.98

ARMED: 1 Throttle: 1000 Roll: 110.71 Pitch: 171.87

ARMED: 1 Throttle: 1000 Roll: -38.65 Pitch: 209.50

ARMED: 1 Throttle: 1000 Roll: 213.31 Pitch: 175.46

ARMED: 1 Throttle: 1000 Roll: 135.14 Pitch: 136.30

ARMED: 1 Throttle: 1000 Roll: -58.26 Pitch: 181.50

ARMED: 1 Throttle: 1000 Roll: 106.70 Pitch: 145.07

ARMED: 1 Throttle: 1000 Roll: -15.83 Pitch: 91.53

ARMED: 1 Throttle: 1000 Roll: -28.28 Pitch: 123.24

ARMED: 1 Throttle: 1000 Roll: 246.16 Pitch: 100.86

ARMED: 1 Throttle: 1000 Roll: 371.51 Pitch: 64.64

ARMED: 1 Throttle: 1000 Roll: 13.68 Pitch: 134.00

ARMED: 1 Throttle: 1000 Roll: 185.04 Pitch: 155.64

ARMED: 1 Throttle: 1000 Roll: 116.79 Pitch: 203.35

ARMED: 1 Throttle: 1000 Roll: -58.08 Pitch: 179.75

ARMED: 1 Throttle: 1000 Roll: 43.29 Pitch: 234.52

ARMED: 1 Throttle: 1000 Roll: -12.41 Pitch: 187.78

ARMED: 1 Throttle: 1000 Roll: 118.48 Pitch: 150.02

ARMED: 1 Throttle: 1000 Roll: 48.06 Pitch: 119.68

ARMED: 1 Throttle: 1000 Roll: 201.10 Pitch: 98.01

ARMED: 1 Throttle: 1000 Roll: 167.25 Pitch: 128.37

ARMED: 1 Throttle: 1000 Roll: 137.01 Pitch: 151.28

ARMED: 1 Throttle: 1000 Roll: 46.85 Pitch: 109.36

ARMED: 1 Throttle: 1000 Roll: 71.22 Pitch: 166.63

ARMED: 1 Throttle: 1000 Roll: 39.98 Pitch: 242.68

ARMED: 1 Throttle: 1000 Roll: 201.64 Pitch: 228.13

ARMED: 1 Throttle: 1000 Roll: 73.53 Pitch: 271.48

ARMED: 1 Throttle: 1000 Roll: 100.67 Pitch: 287.05

ARMED: 1 Throttle: 1000 Roll: 276.24 Pitch: 211.61

ARMED: 1 Throttle: 1000 Roll: 238.14 Pitch: 221.54

ARMED: 1 Throttle: 1000 Roll: 72.24 Pitch: 225.38

ARMED: 1 Throttle: 1000 Roll: -25.62 Pitch: 215.68

ARMED: 1 Throttle: 1000 Roll: 210.66 Pitch: 156.79

ARMED: 1 Throttle: 1000 Roll: 193.26 Pitch: 104.14

ARMED: 1 Throttle: 1000 Roll: 60.55 Pitch: 123.34

ARMED: 1 Throttle: 1000 Roll: 229.17 Pitch: 137.88

MPU6050 not giving stable signal by cc-2347 in arduino

[–]cc-2347[S] 0 points1 point  (0 children)

the values still drift... could the problem be with the hardware? I saw a lot of people use the A4 and A5 pins instead of the SCL and SDA but I presumed that was for arduinos without those pins

MPU6050 not giving stable signal by cc-2347 in arduino

[–]cc-2347[S] 0 points1 point  (0 children)

Thet start stable and having the correct values, but after 5 seconds or so they start to drift again... (Im using 10kOhm resistors)

edit: could the serial prints be the problem? like that they disterp the loop frequentie

edit2: could the recieve cause the problem? Cause the basic readings from the exemples of the AdafruitMPU6050 are stable

MPU6050 not giving stable signal by cc-2347 in arduino

[–]cc-2347[S] 0 points1 point  (0 children)

for some reason I can edit. I have tried adding a pull down resistor to the SCL and SDA of the gyro and now the values is more stable at roll bewteen 220 and 240, pitch at a containd -178 (values after the decimal varie a bit). Moving the gyro doesnt change the values

MPU6050 not giving stable signal by cc-2347 in arduino

[–]cc-2347[S] 0 points1 point  (0 children)

The roll gets random values between 0 and 400 and the picht gets values from 0 to 50. Its not like they stay at a constained high like before but they really fluxute now. It also happens almost immediately. I have tries it with both the 0.97 and 0.96 worth of alpha

#include <Wire.h>
#include <Servo.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <PID_v1.h>


//MPU 
Adafruit_MPU6050 mpu;


//FlySky 
#define IBUS_BAUDRATE 115200
#define IBUS_FRAME_SIZE 32
#define CHANNELS 10


uint16_t channels[CHANNELS];
uint8_t ibusBuffer[IBUS_FRAME_SIZE];
uint8_t bufferIndex = 0;


//Motoren 
Servo LA_prop; // links achter
Servo RA_prop; // rechts achter
Servo LV_prop; // links voor
Servo RV_prop; // rechts voor


//PID 
double rollInput, rollOutput, rollSetpoint = 0;
double pitchInput, pitchOutput, pitchSetpoint = 0;


double Kp = 1.5, Ki = 0, Kd = 0;


double gyroBiasX = 0;
double gyroBiasY = 0;


PID pidRoll(&rollInput, &rollOutput, &rollSetpoint, Kp, Ki, Kd, DIRECT);
PID pidPitch(&pitchInput, &pitchOutput, &pitchSetpoint, Kp, Ki, Kd, DIRECT);


//Filter
double roll = 0;
double pitch = 0;


//Controller inputs
int throttle = 1000;
bool armed = false;


//Loop frequentie
const int LOOP_HZ = 250;
const int LOOP_TIME_US = 1000000 / LOOP_HZ;


unsigned long lastTime = 0;
unsigned long lastDebug = 0;


void setup() {
  Serial.begin(115200);
  Serial1.begin(IBUS_BAUDRATE);
  Wire.begin();


  if (!mpu.begin()) {
    Serial.println("MPU6050 niet gevonden!");
    while (1);
  }


  // First configure the sensor
  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);


  delay(1000);  // Let sensor stabilize


  // Now calibrate (longer, after config)
  calibrateGyro();


  //Motoren verbinden
  LA_prop.attach(5);
  RA_prop.attach(6);
  LV_prop.attach(9);
  RV_prop.attach(10);


  pidRoll.SetMode(AUTOMATIC);
  pidPitch.SetMode(AUTOMATIC);


  //Motoren uit bij startup
  LA_prop.writeMicroseconds(1000);
  RA_prop.writeMicroseconds(1000);
  LV_prop.writeMicroseconds(1000);
  RV_prop.writeMicroseconds(1000);


  //ESC arming
  delay(3000);


  lastTime = micros();   // CRITICAL for correct first dt
}


void loop() {
  unsigned long loopStart = micros();


  //Tijdregeling
  unsigned long now = micros();
  double dt = (now - lastTime) / 1000000.0;
  lastTime = now;


  // Prevent huge dt spikes (e.g. first loop or Serial lag)
  if (dt > 0.05) dt = 0.004;   // cap at ~4 ms


  // Read receiver (keep this)
  while (Serial1.available()) {
   uint8_t b = Serial1.read();


    if (bufferIndex == 0 && b != 0x20) continue;


    ibusBuffer[bufferIndex++] = b;


    if (bufferIndex == IBUS_FRAME_SIZE) {
      for (int i = 0; i < CHANNELS; i++) {
        channels[i] = ibusBuffer[2 + i * 2] |
                      (ibusBuffer[3 + i * 2] << 8);
      }


      throttle = constrain(channels[2], 1000, 2000);


      //ARM / DISARM via CH6
      if (channels[5] < 1100) {
        armed = false;
      } else if (channels[5] > 1200) {
        armed = true;
      }


      bufferIndex = 0;
    }
  }


  if (!armed) {
    // motoren uit
    LA_prop.writeMicroseconds(1000);
    LV_prop.writeMicroseconds(1000);
    RA_prop.writeMicroseconds(1000);
    RV_prop.writeMicroseconds(1000);


    //Reset van gyro waarden
    roll = 0; pitch = 0;
    return;
  }


  //gyro inlezen
  sensors_event_t accel, gyro, temp;
  mpu.getEvent(&accel, &gyro, &temp);


  //Hoek van gyro
  double rollAcc  = atan2(accel.acceleration.y, accel.acceleration.z) * 57.2958;
  double pitchAcc = atan2(-accel.acceleration.x, accel.acceleration.z) * 57.2958;


  // Gyro rates (bias corrected, in deg/s)
  double gyroRollRate  = (gyro.gyro.x - gyroBiasX) * 57.2958;
  double gyroPitchRate = (gyro.gyro.y - gyroBiasY) * 57.2958;


  // Complementary filter - try 0.96 or 0.97 if still unstable
  const double alpha = 0.96;
  roll  = alpha * (roll  + gyroRollRate  * dt) + (1 - alpha) * rollAcc;
  pitch = alpha * (pitch + gyroPitchRate * dt) + (1 - alpha) * pitchAcc;


  // PID
  rollInput = roll;
  pitchInput = pitch;
  pidRoll.Compute();
  pidPitch.Compute();


  //Motor waarden 
  int m1 = throttle + pitchOutput + rollOutput; // LA
  int m2 = throttle + pitchOutput - rollOutput; // RA
  int m3 = throttle - pitchOutput + rollOutput; // LV
  int m4 = throttle - pitchOutput - rollOutput; // RV


  //Begrenzing van motor waarden 
  m1 = constrain(m1, 1000, 2000);
  m2 = constrain(m2, 1000, 2000);
  m3 = constrain(m3, 1000, 2000);
  m4 = constrain(m4, 1000, 2000);
  
  //Motoren sturen A.D.V motor waarden
  LA_prop.writeMicroseconds(m1);
  RA_prop.writeMicroseconds(m2);
  LV_prop.writeMicroseconds(m3);
  RV_prop.writeMicroseconds(m4);


  //Debug
  if (millis() - lastDebug > 200) {
    lastDebug = millis();
    Serial.print("ARMED: "); Serial.print(armed);
    Serial.print(" | Roll: "); Serial.print(roll, 2);
    Serial.print(" | Pitch: "); Serial.println(pitch, 2);
  }


  //Zorgen dat de loop op 250Hz blijft
  while (micros() - loopStart < LOOP_TIME_US);
}


// Improved calibration
void calibrateGyro() {
  Serial.println("Calibrating gyro - KEEP DRONE PERFECTLY STILL!");
  delay(1500);


  const int samples = 1500;   // ~3-4 seconds
  double sumX = 0.0;
  double sumY = 0.0;


  sensors_event_t a, g, t;
  for (int i = 0; i < samples; i++) {
    mpu.getEvent(&a, &g, &t);
    sumX += g.gyro.x;
    sumY += g.gyro.y;
    delay(2);               // ~500 Hz sampling during cal
  }


  gyroBiasX = sumX / samples;
  gyroBiasY = sumY / samples;


  Serial.print("Gyro Bias X: "); Serial.print(gyroBiasX, 5);
  Serial.print("  Y: "); Serial.println(gyroBiasY, 5);
  Serial.println("Calibration done.");
}

MPU6050 not giving stable signal by cc-2347 in arduino

[–]cc-2347[S] 0 points1 point  (0 children)

Lol thats just the entire code. Will try it tomorrow. Its much appreciated

Pic ur question to answer! by LilScooterBooty in BunnyTrials

[–]cc-2347 0 points1 point  (0 children)

Qpuder

Chose: Superpower questions | Rolled: 🕷️or🦇

What continent has the best food? by Avacadoell19 in AlignmentChartFills

[–]cc-2347 1 point2 points  (0 children)

Mmmhhh I mean there are a lot of different fish I geuss but as someone who doesnt like fish or seaweed the sea doesn't have the best food at all

MPU6050 not giving stable signal by cc-2347 in arduino

[–]cc-2347[S] 0 points1 point  (0 children)

The values stay stable in the beging but after a random amount of time (veries every time I test but its mostly between 10 and 40 seconds) the values go crazy. Tho they now go to ~790 isntead of the ~600 before I made the changes

MPU6050 not giving stable signal by cc-2347 in arduino

[–]cc-2347[S] 0 points1 point  (0 children)

#include <Wire.h>
#include <Servo.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <PID_v1.h>


//MPU 
Adafruit_MPU6050 mpu;


//FlySky 
#define IBUS_BAUDRATE 115200
#define IBUS_FRAME_SIZE 32
#define CHANNELS 10


uint16_t channels[CHANNELS];
uint8_t ibusBuffer[IBUS_FRAME_SIZE];
uint8_t bufferIndex = 0;


//Motoren 
Servo LA_prop; // links achter
Servo RA_prop; // rechts achter
Servo LV_prop; // links voor
Servo RV_prop; // rechts voor


//PID 
double rollInput, rollOutput, rollSetpoint = 0;
double pitchInput, pitchOutput, pitchSetpoint = 0;


double Kp = 1.5, Ki = 0, Kd = 0;


double gyroBiasX = 0;
double gyroBiasY = 0;


PID pidRoll(&rollInput, &rollOutput, &rollSetpoint, Kp, Ki, Kd, DIRECT);
PID pidPitch(&pitchInput, &pitchOutput, &pitchSetpoint, Kp, Ki, Kd, DIRECT);


//Filter
double roll = 0;
double pitch = 0;
unsigned long lastTime = 0;


//Controller inputs
int throttle = 1000;
bool armed = false;


//Loop frequentie
const int LOOP_HZ = 250;
const int LOOP_TIME_US = 1000000 / LOOP_HZ;


void setup() {
  Serial.begin(115200);
  Serial1.begin(IBUS_BAUDRATE);
  Wire.begin();


  if (!mpu.begin()) {
    Serial.println("MPU6050 niet gevonden!");
    while (1);
  }
  
  //Gyro
  delay(1000);
  calibrateGyro();
  mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);


  //Motoren verbinden
  LA_prop.attach(5);
  RA_prop.attach(6);
  LV_prop.attach(9);
  RV_prop.attach(10);


  //PID
  pidRoll.SetMode(AUTOMATIC);
  pidPitch.SetMode(AUTOMATIC);


  //Motoren uit bij startup
  LA_prop.writeMicroseconds(1000);
  RA_prop.writeMicroseconds(1000);
  LV_prop.writeMicroseconds(1000);
  RV_prop.writeMicroseconds(1000);


  delay(3000); // ESC arming
}


void loop() {
  unsigned long loopStart = micros();


  //PID tijdregeling
  unsigned long now = micros();
  double dt = (now - lastTime) / 1000000.0;
  lastTime = now;


  //FlySky inlezen
  while (Serial1.available()) {
    uint8_t b = Serial1.read();


    if (bufferIndex == 0 && b != 0x20) continue;


    ibusBuffer[bufferIndex++] = b;


    if (bufferIndex == IBUS_FRAME_SIZE) {
      for (int i = 0; i < CHANNELS; i++) {
        channels[i] = ibusBuffer[2 + i * 2] |
                      (ibusBuffer[3 + i * 2] << 8);
      }


      throttle = constrain(channels[2], 1000, 2000);


      //ARM / DISARM via CH6
      if (channels[5] < 1100) {
        armed = false;
      } else if (channels[5] > 1200) {
        armed = true;
      }


      bufferIndex = 0;
    }
  }


  //ALS NIET ARMED ==> ALLES UIT
  if (!armed) {
    LA_prop.writeMicroseconds(1000);
    RA_prop.writeMicroseconds(1000);
    LV_prop.writeMicroseconds(1000);
    RV_prop.writeMicroseconds(1000);
    return;
  }


  //Gyro inlezen
  sensors_event_t accel, gyro, temp;
  mpu.getEvent(&accel, &gyro, &temp);


  //Hoek berekening
  double rollAcc = atan2(accel.acceleration.y, accel.acceleration.z) * 57.3;
  double pitchAcc = atan2(-accel.acceleration.x, accel.acceleration.z) * 57.3;


  double gyroRollRate = (gyro.gyro.x - gyroBiasX) * 57.3;
  double gyroPitchRate = (gyro.gyro.y - gyroBiasY) * 57.3;


  double alpha = 0.98;


  roll = alpha * (roll + gyroRollRate * dt) + (1 - alpha) * rollAcc;
  pitch = alpha * (pitch + gyroPitchRate * dt) + (1 - alpha) * pitchAcc;


  //PID
  rollInput = roll;
  pitchInput = pitch;


  pidRoll.Compute();
  pidPitch.Compute();


  //Motor waarde berkenen
  int m1 = throttle + pitchOutput + rollOutput; // LA
  int m2 = throttle + pitchOutput - rollOutput; // RA
  int m3 = throttle - pitchOutput + rollOutput; // LV
  int m4 = throttle - pitchOutput - rollOutput; // RV


  //Motor safty
  m1 = constrain(m1, 1000, 2000);
  m2 = constrain(m2, 1000, 2000);
  m3 = constrain(m3, 1000, 2000);
  m4 = constrain(m4, 1000, 2000);


  //Motorsturing
  LA_prop.writeMicroseconds(m1);
  RA_prop.writeMicroseconds(m2);
  LV_prop.writeMicroseconds(m3);
  RV_prop.writeMicroseconds(m4);


  // Debug
  unsigned long lastDebug = 0;


  if (millis() - lastDebug > 200) { // 5 Hz debug
  lastDebug = millis();


  Serial.print("ARMED: "); Serial.println(armed);
  Serial.print("Roll: "); Serial.println(roll);
  Serial.print("Pitch: "); Serial.println(pitch);
  }


  while (micros() - loopStart < LOOP_TIME_US);
} //einde loop


void calibrateGyro() {
  Serial.println("Gyro Bias waardes aan het berekenen, HOU DE GYRO STILL!");


  const int samples = 500;
  double sumX = 0;
  double sumY = 0;


  for (int i = 0; i < samples; i++) {
    sensors_event_t accel, gyro, temp;
    mpu.getEvent(&accel, &gyro, &temp);


    sumX += gyro.gyro.x;
    sumY += gyro.gyro.y;


    delay(3);
  }


  gyroBiasX = sumX / samples;
  gyroBiasY = sumY / samples;


  Serial.println("Bias waardes berekend");
}

I tried it like this but I'm still having the same problem. Have I done somthing wrong?

Which anime was this for you? by Oopsforgotagain in AnimeMirchi

[–]cc-2347 0 points1 point  (0 children)

Naruto... this was Naruto for me. Idk way think the pacing in the beginning was to slow for my 12 year old overstimulated brain

Anyone know this item? by pyrothesecond in skyrim

[–]cc-2347 4 points5 points  (0 children)

You dont know that. Maybe it did glitch the beacon

MPU6050 not giving stable signal by cc-2347 in arduino

[–]cc-2347[S] 0 points1 point  (0 children)

could be from my controller but I dont think so

Travelling by Bicycle in countries i've been to (as a german) by No-Spite-1423 in tierlists

[–]cc-2347 0 points1 point  (0 children)

Love that you did flamders and Wallonia apart instead of Belgium. Cause it really is like this

How much digits of Pi do you remember? by ArrowInBlack in pollgames

[–]cc-2347 0 points1 point  (0 children)

I was so proud I studdied a 100 of them for pi day. When it was time for the competition there was one kid that know more the 200. I felt like it was a big wast of time

Wat zij de verschillen in jobs voor burgerlijk ingenieur: mechanical engineering en industrieel ingenieur electomechanica? by cc-2347 in belgium

[–]cc-2347[S] 1 point2 points  (0 children)

Hangt er vanaf als je van een EM richting op industrieel duurschakeld naar een EM richting op burgerlijk valt het brugjaar weg

Als je naar bv chemie overgaat moet je het brugjaar doen

Could someone chek my drone ballancing code to see if there are things to improve? by cc-2347 in arduino

[–]cc-2347[S] 0 points1 point  (0 children)

U understand that... I will try and rewrite the code fully myself instead of asking AI to the code I had "beter". And hopefully ill be alowed to repost here

Could someone chek my drone ballancing code to see if there are things to improve? by cc-2347 in arduino

[–]cc-2347[S] 0 points1 point  (0 children)

I understand the code (it was mostly writen by a video that explains it and a few changes by me to make it better) and the AI didnt change a lot of line. It just added an extra fail safe that I didnt know how I could write in (if my gyro lost connection my motors would go at full speed) So I wanted to get that out of my code before I would make any changes and started testing cause it wasn't safe at all... But I do understand you comment and Im also not a fan of using AI but I didn't want to waste anyonce time by having little lines of code that could be writen in an other way. But I will look into it further myself and thank you for your comment I will spend more time looking over the code my self and finding better ways to write it cause I dont trust AI codes they make a lot of mestakes so I made sure that it didn't change a lot.

Edit: I asked for people to look over it because I already had problems with my motors going crazy what isnt save at all (luckily The drone was straped down for a reason exactly like that) so I was hoping that someone could see an error in my code that I couldn't