5

Dependencies:   mbed LCD_DISCO_F746NG MPU6050 BSP_DISCO_F746NG

Files at this revision

API Documentation at this revision

Comitter:
troshha
Date:
Wed Nov 13 10:28:00 2019 +0000
Commit message:
5

Changed in this revision

BSP_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
LCD_DISCO_F746NG.lib Show annotated file Show diff for this revision Revisions of this file
MPU6050.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r a3739a2e895d BSP_DISCO_F746NG.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BSP_DISCO_F746NG.lib	Wed Nov 13 10:28:00 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ST/code/BSP_DISCO_F746NG/#df2ea349c37a
diff -r 000000000000 -r a3739a2e895d LCD_DISCO_F746NG.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD_DISCO_F746NG.lib	Wed Nov 13 10:28:00 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ST/code/LCD_DISCO_F746NG/#d44525b1de98
diff -r 000000000000 -r a3739a2e895d MPU6050.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MPU6050.lib	Wed Nov 13 10:28:00 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/Sissors/code/MPU6050/#5c63e20c50f3
diff -r 000000000000 -r a3739a2e895d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 13 10:28:00 2019 +0000
@@ -0,0 +1,106 @@
+#include "mbed.h"
+#include "MPU6050.h"
+#include "LCD_DISCO_F746NG.h"
+#include "stm32746g_discovery_lcd.h"
+
+LCD_DISCO_F746NG lcd;
+DigitalOut myled(LED1);
+MPU6050 mpu(D14, D15);
+
+int main()
+{
+    float GyroBuffer[3];
+    float zero_level[3] = {0, 0, 0};
+    uint8_t buffer[100];
+    lcd.Init();
+    lcd.DisplayStringAt(10, 10, (uint8_t*)"Gyros_star", CENTER_MODE);
+    uint8_t tmpreg = 0;
+    read(MPU6050_GYRO_CONFIG_REG,&tmpreg,1);
+    switch(tmpreg & MPU6050_GYRO_XOUT_H_REG)
+    {
+        case MPU6050_GYRO_RANGE_250:
+            lcd.DisplayStringAt(20, 20, (uint8_t*)"250", CENTER_MODE);
+        break;
+    
+        case MPU6050_GYRO_RANGE_500:
+            lcd.DisplayStringAt(20, 20, (uint8_t*)"500", CENTER_MODE);
+        break;
+    
+        case MPU6050_GYRO_RANGE_2000:
+            lcd.DisplayStringAt(20, 20, (uint8_t*)"2000", CENTER_MODE);
+        break;
+  }
+    read(MPU6050_GYRO_YOUT_H_REG ,&tmpreg , 1);
+    switch(tmpreg >> 6) {
+        case 0:
+            lcd.DisplayStringAt(20, 40, (uint8_t*)"", CENTER_MODE);
+            break;
+        case 1:
+            lcd.DisplayStringAt(20, 40, (uint8_t*)"190", CENTER_MODE);
+            break;
+        case 2:
+            lcd.DisplayStringAt(20, 40, (uint8_t*)"380", CENTER_MODE);
+            break;
+        case 3:
+            lcd.DisplayStringAt(20, 40, (uint8_t*)"760", CENTER_MODE);
+            break;
+    }
+
+    for (int i = 0; i < 50; i++) {
+        mpu.getGyro(GyroBuffer);
+        zero_level[0] += GyroBuffer[0] / 131;
+        zero_level[1] += GyroBuffer[1] / 131;
+        zero_level[2] += GyroBuffer[2] / 131;
+        
+        wait_ms(10);
+    }
+    for (int i = 0; i < 3; i++)
+        zero_level[i] /= 50;
+        
+    
+    float noise_level = 0.0;
+    for (int i = 0; i < 50; i++) {
+        mpu.getGyroRaw(GyroBuffer[0]);
+        if ((GyroBuffer[0] / 131 - zero_level[0]) > noise_level) {
+            noise_level = (GyroBuffer[0] / 131 - zero_level[0]);
+        } 
+        else if ((GyroBuffer[0] / 131 - zero_level[0]) < -noise_level) {
+            noise_level = -(GyroBuffer[0] / 131 - zero_level[0]);
+        }
+        wait_ms(10);
+    }
+    sprintf((char*)buffer, "Noise = %.2f\n", noise_level);
+    lcd.DisplayStringAt(20, 70, buffer, CENTER_MODE);
+    sprintf((char*)buffer, "Zero = %.2f\n", zero_level[0]);
+    lcd.DisplayStringAt(20, 170, buffer, CENTER_MODE);
+    float angle = 0.0, prev_value = 0.0; 
+    bool status1 = false, status2 = false;
+    while(1) {
+        // Read Gyroscope values
+        wait(0.02);
+        
+        mpu.getGyroRaw(GyroBuffer);
+        float value = GyroBuffer[0] / 131 - zero_level[0];
+        if (value >= noise_level || value <= -noise_level) {
+            angle += (value + prev_value) / 2  * 0.02f ;
+        }
+        if (angle > 45.0){
+           status1 = true;
+            
+            
+        }else if  (angle < -45.0){            
+            status2 = true;
+            
+        } else if (status1 == true && status2 == true){
+            sprintf((char*)buffer, "Angle = %.3f\n", angle);
+            lcd.DisplayStringAt(20, 100, buffer, CENTER_MODE);
+            lcd.DisplayStringAt(20, 120, (uint8_t*)"All Right", CENTER_MODE);
+            }
+        
+        prev_value = value;
+        sprintf((char*)buffer, "Angle = %.3f\n", angle);
+        lcd.DisplayStringAt(20, 100, buffer, CENTER_MODE);
+        
+        
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r a3739a2e895d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Nov 13 10:28:00 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file