Whenever I read data from my IMU (BNO055) it interferes with the rotation of my brushless DC Motor. I get random spikes in RPM from the Motors - since I am building a quadcopter, this results in immense instability.
Setup:
- Reading IMU data
- Reading Potentiometer Value
- Writing to ESC to power BLDC
Observation:
BLDC rotation rate spikes irregularly (Motor turns faster for like a millisecond) whenever I read IMU data.
Remedies:
- I remove the line of code where I read the IMU data
- I introduce a delay of 100ms
I need at least 120Hz to achieve stable hover, so:
- I need the IMU data
- having a 100ms delay is not an option
Videos for showcase:
-
https://www.youtube.com/shorts/WHC9-OSielg
-> You can hear the spikes in RPM -
https://www.youtube.com/shorts/D3Z8-p7Zilw
-> As soon as I remove one line of code (IMU reading), motor runs smoothly
My code:
#include <Arduino.h>
// Servo
#include <Servo.h>
Servo ESC;
int const escPin = 9;
// IMU
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BNO055.h>
#include <Adafruit_Sensor.h>
Adafruit_BNO055 myIMU = Adafruit_BNO055();
void setup()
{
Serial.begin(115200);
// Initializing ESC
ESC.attach(escPin, 1000, 2000);
// Initializing IMU
myIMU.begin();
myIMU.setExtCrystalUse(true);
delay(1000);
}
void loop()
{
// Reading IMU -> the line of code in question
imu::Quaternion quat = myIMU.getQuat();
// Reading Potentiometer
float potVal = analogRead(A0);
// Writing to Motor
potVal = map(potVal, 0, 1023, 0, 180);
ESC.write(potVal);
}