Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tockn/mpu6050_tockn
Arduino library for easy communication with MPU6050
https://github.com/tockn/mpu6050_tockn
accelerometer arduino arduino-library gyroscope mpu6050
Last synced: about 1 hour ago
JSON representation
Arduino library for easy communication with MPU6050
- Host: GitHub
- URL: https://github.com/tockn/mpu6050_tockn
- Owner: tockn
- Created: 2018-03-11T06:13:31.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-09-30T15:51:49.000Z (over 4 years ago)
- Last Synced: 2025-01-02T08:12:56.296Z (7 days ago)
- Topics: accelerometer, arduino, arduino-library, gyroscope, mpu6050
- Language: C++
- Homepage:
- Size: 35.2 KB
- Stars: 227
- Watchers: 23
- Forks: 90
- Open Issues: 34
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MPU6050_tockn
Arduino library for easy communicating with the MPU6050
## Usage
You can see [example sketch.](https://github.com/Tockn/MPU6050_tockn/tree/master/examples)
If you want to get data of MPU6050, you must execute `update()` method before get method.
`update()` will get all data of MPU6050, and calculating angle by accelerometer, gyroscope and complementary filter.### Complementary filter
`update()` method calculate angle by accelerometer and gyroscope using complementary filter.
Those two coefficients determined by constructor.
Default coefficient of accelerometer is 0.02, gyroscope is 0.98.
`filtered_angle = (0.02 * accel) + (0.98 * gyro)`
#### example
If you want to set 0.1 to accelerometer coefficient and 0.9 to gyroscope coefficient, your code is
```MPU6050 mpu6050(Wire, 0.1, 0.9);```### Auto calibration
If you use `calcGyroOffsets()` in `setup()`, it will calculate calibration of the gyroscope, and the value of the gyroscope will calibrated.
⚠DO NOT MOVE MPU6050 during calculating.⚠
```
#include
#includeMPU6050 mpu6050(Wire);
void setup(){
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets();
}```
If you use `calcGyroOffsets(true)` in `setup()`, you can see state of calculating calibration in serial monitor.
```
#include
#includeMPU6050 mpu6050(Wire);
void setup(){
Serial.begin(9600);
Wire.begin();
mpu6050.begin();
mpu6050.calcGyroOffsets(true);
}
```
Serial monitor:
```
Calculate gyro offsets
DO NOT MOVE MPU6050.....
Done!
X : 1.45
Y : 1.23
Z : -1.32
Program will start after 3 seconds
```
If you know offsets of gyroscope, you can set them by `setGyroOffsets()`, and you don't have to execute `calcGyroOffsets()`, so you can launch program quickly.
#### example
```
#include
#includeMPU6050 mpu6050(Wire);
void setup(){
Serial.begin(9600);
Wire.begin();
mpu6050.begin();
mpu6050.setGyroOffsets(1.45, 1.23, -1.32);
}
```
## Licence
MIT
## Author[tockn](https://github.com/tockn)