test_code_for_ahrs

Dependencies:   mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 #include "MPU6050.h"
00004 
00005 #define gyro_read_address_H (0x1D)
00006 #define gyro_read_address_L (0x1E)
00007 
00008 
00009 Serial pc(USBTX, USBRX); // tx, rx
00010 MPU6050 imu;
00011 //imu(I, PinName scl);
00012 
00013 
00014 
00015 void print_char(char c = '*')
00016 {
00017     printf("%c", c);
00018     fflush(stdout);
00019 }
00020 
00021 DigitalOut led1(LED1);
00022 
00023 void print_thread(void const *argument)
00024 {
00025     while (true) {
00026         Thread::wait(1000);
00027         print_char();
00028     }
00029 }
00030 
00031 void read_imu(void const *argumennt) {
00032     while (true) {
00033         Thread::wait(1000);
00034         uint8_t whoami = imu.readByte(MPU6050_ADDRESS, WHO_AM_I_MPU6050);  // Read WHO_AM_I register for MPU-6050
00035         pc.printf("I AM 0x%x\n\r", whoami); pc.printf("I SHOULD BE 0x68\n\r");
00036     }
00037 }
00038 
00039 int main()
00040 {
00041     printf("\n\n*** RTOS basic example ***\n");
00042     
00043     Thread thread1(read_imu, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
00044     //Thread thread2(print_thread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE);
00045     
00046     //int gyro_val = 0;
00047     //char data_read[2];
00048     
00049     while (true) {
00050         led1 = !led1;
00051         //imu.read(gyro_read_address_H, data_read, 0); // no stop
00052         //imu.read(gyro_read_address_L, data_read, 0); // 
00053         //gyro_val = gyro_val | (int) data_read[0];
00054         //gyro_val = gyro_val | ((int) data_read[0] << 8);
00055         //printf("Gyro Value: %d\n", data_read[0]);
00056         Thread::wait(500);
00057     }
00058 }