說明
GY-80是一個包含加速度計(ADXL345)、陀螺儀(L3G4200)、電子羅盤(HMC5883)跟氣壓計(BMP085)的模組
我們只需要連接下面四個腳位即可獲得當下四個模組的值
接線
GY-80: VCC_3.3V <---> Arduino: 3V
GY-80: GND <---> Arduino: GND
GY-80: SCL <---> Arduino: Analog 5
GY-80: SDA <---> Arduino: Analog 4
函式庫
<GY80.h>點我下載 (來源:muggn/GY80@GitHub)
程式碼
#include <Wire.h>; #include <GY80.h>; GY80 sensor = GY80(); //create GY80 instance void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); sensor.begin(); //initialize sensors } void loop() { GY80_scaled val = sensor.read_scaled(); //get values from all sensors // print out values Serial.print("Mag:"); //magnetometer values Serial.print(val.m_x, 2); Serial.print(','); Serial.print(val.m_y, 2); Serial.print(','); Serial.print(val.m_z, 2); Serial.print(' '); Serial.print("Acc:"); //accelerometer values Serial.print(val.a_x, 3); Serial.print(','); Serial.print(val.a_y, 3); Serial.print(','); Serial.print(val.a_z, 3); Serial.print(' '); Serial.print("Gyro:"); //gyroscope values Serial.print(val.g_x, 1); Serial.print(','); Serial.print(val.g_y, 1); Serial.print(','); Serial.print(val.g_z, 1); Serial.print(' '); Serial.print("P:"); //pressure values Serial.print(val.p, 5); Serial.print(' '); Serial.print("T:"); //temperature values Serial.println(val.t, 1); delay(250); // delay in between reads for stability }
輸出
備註
Mag = Magnetometer Values(電子羅盤數值)
Acc = Accelerometer Values(加速度值)
Gyro = Gyroscope Values(陀螺儀數值)
P = Pressure Values(氣壓值)
T = Temperature Values(溫度)