MEMS陀螺儀(Gyroscope):
角速度計,測量單位 角速度(度/秒)
例如:
LPY530AL Dual
加速度感測器:
測量加速度的裝置,也就是g force
例如:
三軸加速度感測器 ADXL335
MPU-6050
MPU6050 三軸陀螺儀+三軸加速度 6軸模組
規格
I²C函式庫http://www.i2cdevlib.com/devices/mpu6050#source
https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050
http://ming-shian.blogspot.tw/20 ... pu6050row-data.html
http://gogoprivateryan.blogspot.tw/2014/07/mpu-6050-google.html- #include "I2Cdev.h"
- #include "MPU6050.h"
- #include "Wire.h"
- #include <Servo.h>
- MPU6050 accelgyro;
- Servo servo1;
- int16_t ax, ay, az;
- int16_t gx, gy, gz;
- int val;
- int prev;
- void setup() {
- Wire.begin();
- Serial.begin(38400);
- Serial.println("Initializing I2C devices...");
- accelgyro.initialize();
- servo1.attach(7);
- // verify connection
- Serial.println("Testing device connections...");
- Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
- }
- void loop() {
- // read raw accel/gyro measurements from device
- accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
- Serial.print("a/g:\t");
- Serial.print(ax); Serial.print("\t");
- Serial.print(ay); Serial.print("\t");
- Serial.print(az); Serial.print("\t");
- Serial.print(gx); Serial.print("\t");
- Serial.print(gy); Serial.print("\t");
- Serial.println(gz);
- val = map(ay,-17000,17000,0,179);
- if (val!=prev){
- servo1.write(val);
- prev=val;
- }
- delay(50);
- }
複製代碼 |