**Index**

- Eclipse IDE and JTAG
- Unlock STM32F103 with JTAG
- Flash firmware using Bluetooth
- Serial Port Bluetooth
- Serial Port Plot
- SM32F103C8T6 use 128kbytes flash

- Observer
- Shane Colton documentation and firmware
- Firmware
- Part 1: Field-Oriented
- Part 2: Field-Oriented
- Sensorless Pneu Scooter - part 1
- Sensorless Pneu Scooter - part 2
- Sensorless Pneu Scooter - part 3
- Texas Instruments videos
- Chinese controllers code

- Chinese balance group reference design
- Kerry D. Wong -- A Self-Balancing Robot
- Self balance bicycle
- PID
- LQR
- PID and LQR, MATLAB
- Steve Brunton videos

__MPU6050 freq__

__MPU6050 freq__

---

I think you will have to change your I2C frequency to 400KHz (max is 500KHz), only read accelerometers, configure the MPU sample rate to 350 Hz or higher, configure the MPU low pass filter to 175Hz or higher and check the accelerometer range so that it does not saturate.

Yes, the MPU6050 can have a sample rate of 1 KHz if you are able to read values out at that speed. It will be difficult if you are reading every gyro and accel every time and you are using I2C.

Your MPU allows a sample rate of 8kHz only for the gyrometer, the accelerometer allows only 1kHz.

Given you use 400kHz I2C speed, the highest data rate to read all values is theoretically 2.61kHz, 2.96kHz if you omit the temperature reading (15 bytes must be transmitted, needing 9 clocks each). That's a theoretical maximum that is practically never reached.

If you read only the gyro values (as the accelerometer values aren't that fast anyway) you may reach about 7kHz.

---

I am looking to use the MPU6050 on a self balancing bicycle. I am using a PIC micro so can't take the code directly from i2Cdevlib.

I am only interested in the angle in one axis (I'm only interested in roll). I have some questions I was hoping someone could help with:

1. If I'm interested in only one axis and only small angles (+/- 10deg), is it OK to just grab the accelerometer and gyro data for that one axis; or should I still get all 3 and combine for some reason?

**I have seen posts for other IMUs suggesting that you should combine readings to get the required angle. For example, assume I am interested in only the X angle, then it suggests something like this:**

//Convert Accelerometer values to degrees

AccXangle = (float) (atan2(*(acc_raw_y),*(acc_raw_z))+M_PI)*RAD_TO_DEG;

But what is incorrect with doing:

AccXangle = (float) ((acc_raw_x / 9.81) * RAD_TO_DEG); // For small angles where sin(theta)

is approx equal to theta

Since I am not interested in full 360deg locus but just small angles, will the second method not work?

//Convert Accelerometer values to degrees

AccXangle = (float) (atan2(*(acc_raw_y),*(acc_raw_z))+M_PI)*RAD_TO_DEG;

But what is incorrect with doing:

AccXangle = (float) ((acc_raw_x / 9.81) * RAD_TO_DEG); // For small angles where sin(theta)

is approx equal to theta

Since I am not interested in full 360deg locus but just small angles, will the second method not work?

I guess I can use the first method but I was curious; and want to know if I really need the overhead of the more complex atan2 function.

2. What is the method to 'zero' the gyro? Since the gyro measures angular velocity, the ang_vel*dt will give change in angle, hence needs summing from a known point. So, do I need to put my bike into a 'zero' position and then start the gyro measurements or is there a cleverer way to do it?

If I'm using a complimentary filter in the form:

X_angle = 0.98 * (angle + gyroX_vel * dt) + 0.02 * accXAngle

then if I set X_angle = accXangle for the first loop iteration will that be OK?