Korneliusz Jarzebski 11 жил өмнө
parent
commit
c8a1f1d379

+ 7 - 0
MPU6050.cpp

@@ -279,6 +279,13 @@ Vector MPU6050::readNormalizeGyro()
     return ng;
 }
 
+float MPU6050::readTemperature(void)
+{
+    int16_t T;
+    T = readRegister16(MPU6050_REG_TEMP_OUT_H);
+    return (float)T/340 + 36.53;
+}
+
 int16_t MPU6050::getGyroOffsetX(void)
 {
     return readRegister16(MPU6050_REG_GYRO_XOFFS_H);

+ 4 - 0
MPU6050.h

@@ -49,6 +49,8 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #define MPU6050_REG_ACCEL_YOUT_L  (0x3E)
 #define MPU6050_REG_ACCEL_ZOUT_H  (0x3F)
 #define MPU6050_REG_ACCEL_ZOUT_L  (0x40)
+#define MPU6050_REG_TEMP_OUT_H    (0x41)
+#define MPU6050_REG_TEMP_OUT_L    (0x42)
 #define MPU6050_REG_GYRO_XOUT_H   (0x43)
 #define MPU6050_REG_GYRO_XOUT_L   (0x44)
 #define MPU6050_REG_GYRO_YOUT_H   (0x45)
@@ -110,6 +112,8 @@ class MPU6050
 	bool getSleepEnabled(void);
 	void setSleepEnabled(bool state);
 
+	float readTemperature(void);
+
 	int16_t getGyroOffsetX(void);
 	void setGyroOffsetX(int16_t offset);
 	int16_t getGyroOffsetY(void);

+ 7 - 3
MPU6050_gyro_pitch_roll_yaw/MPU6050_gyro_pitch_roll_yaw.ino

@@ -30,10 +30,14 @@ void setup()
     Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
     delay(500);
   }
-
+  
   // Calibrate gyroscope. The calibration must be at rest.
   // If you don't want calibrate, comment this line.
-  mpu.calibrateGyro(100);
+  mpu.calibrateGyro();
+
+  // Set threshold sensivty. Default 3.
+  // If you don't want use threshold, comment this line or set 0.
+  mpu.setThreshold(3);
 }
 
 void loop()
@@ -41,7 +45,7 @@ void loop()
   timer = millis();
 
   // Read normalized values
-  Vector norm = mup.readNormalizeGyro();
+  Vector norm = mpu.readNormalizeGyro();
 
   // Calculate Pitch, Roll and Yaw
   pitch = pitch + norm.YAxis * timeStep;

+ 10 - 1
MPU6050_gyro_simple/MPU6050_gyro_simple.ino

@@ -15,8 +15,8 @@ void setup()
 {
   Serial.begin(115200);
 
+  // Initialize MPU6050
   Serial.println("Initialize MPU6050");
-
   while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
   {
     Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
@@ -28,6 +28,15 @@ void setup()
   // mpu.setGyroOffsetY(15);
   // mpu.setGyroOffsetZ(15);
   
+  // Calibrate gyroscope. The calibration must be at rest.
+  // If you don't want calibrate, comment this line.
+  mpu.calibrateGyro();
+
+  // Set threshold sensivty. Default 3.
+  // If you don't want use threshold, comment this line or set 0.
+  mpu.setThreshold(3);
+  
+  // Check settings
   checkSettings();
 }
 

+ 38 - 0
MPU6050_temperature/MPU6050_temperature.ino

@@ -0,0 +1,38 @@
+/*
+    MPU6050 Triple Axis Gyroscope & Accelerometer. Temperature Example.
+    Read more: TODO
+    GIT: https://github.com/jarzebski/Arduino-MPU6050
+    Web: http://www.jarzebski.pl
+    (c) 2014 by Korneliusz Jarzebski
+*/
+
+#include <Wire.h>
+#include <MPU6050.h>
+
+MPU6050 mpu;
+
+void setup() 
+{
+  Serial.begin(115200);
+
+  Serial.println("Initialize MPU6050");
+
+  while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
+  {
+    Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
+    delay(500);
+  }
+}
+
+void loop()
+{
+  float temp = mpu.readTemperature();
+
+  Serial.print(" Temp = ");
+  Serial.print(temp);
+  Serial.println(" *C");
+  
+  delay(500);
+}
+
+