Qian Yuyang
/
Ex_4Rotor_template
NRF+MPU6050
Revision 5:6a93542b8922, committed 2019-04-15
- Comitter:
- AlexQian
- Date:
- Mon Apr 15 05:16:57 2019 +0000
- Parent:
- 4:1b985e622d26
- Commit message:
- Fly
Changed in this revision
MPU6050.h | 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 |
diff -r 1b985e622d26 -r 6a93542b8922 MPU6050.h --- a/MPU6050.h Wed Mar 20 10:44:31 2019 +0000 +++ b/MPU6050.h Mon Apr 15 05:16:57 2019 +0000 @@ -696,9 +696,9 @@ // Read the WHO_AM_I register, this is a good test of communication uint8_t whoami = readByte(MPU6050_ADDRESS, WHO_AM_I_MPU6050); // Read WHO_AM_I register for MPU-6050 - //pc.printf("I AM 0x%x\n\r", whoami); pc.printf("I SHOULD BE 0x68\n\r"); +// Serial_2.printf("I AM 0x%x\n\r", whoami); Serial_2.printf("I SHOULD BE 0x68\n\r"); - if (whoami == 0x68) // WHO_AM_I should always be 0x68 + if (whoami == 0x98) // WHO_AM_I should always be 0x68 { //pc.printf("MPU6050 is online..."); wait(1);
diff -r 1b985e622d26 -r 6a93542b8922 main.cpp --- a/main.cpp Wed Mar 20 10:44:31 2019 +0000 +++ b/main.cpp Mon Apr 15 05:16:57 2019 +0000 @@ -1,62 +0,0 @@ -#define HIGH 1 -#define LOW 0 -#include "mbed.h" -#include <string> -typedef bool boolean; -typedef std::string String; -#include "nRF24L01P.h" -#include "MPU6050.h" - -char rxdata[12] ; -float Yaw; -float Pitch; -float Roll; -int Power; -int Yaw_t; -int Pitch_t; -int Roll_t; -long CycleCount; -long ReceiveCount; - -#define NRF24_TRANSFER_SIZE 12 -nRF24L01P nrf24_PB_15(PB_15,PB_14,PB_13,PB_6,PB_5,PB_7); -Serial Serial_2(PA_2,PA_3); -mpu6050 mpu6050_I2C_1(PB_9,PB_8); -DigitalOut myDigitalOutPA_7(PA_7); -DigitalOut myDigitalOutPA_6(PA_6); - -int main() { -nrf24_PB_15.powerUp(); -nrf24_PB_15.setTransferSize( NRF24_TRANSFER_SIZE ); -nrf24_PB_15.setReceiveMode(); -nrf24_PB_15.setRxAddress(12345ull); -nrf24_PB_15.setTxAddress(12345ull); -nrf24_PB_15.enable(); - -Serial_2.baud(9600); - -mpu6050_I2C_1.Init(); - -CycleCount = 0; -ReceiveCount = 0; -while (true) { -CycleCount = CycleCount + 1; -mpu6050_I2C_1.receiveData(&Yaw,&Pitch,&Roll); -Serial_2.printf("Yaw=%.2f, Pitch=%.2f, Roll=%.2f \n",Yaw,Pitch,Roll); -if (nrf24_PB_15.readable()) { -ReceiveCount = ReceiveCount + 1; -myDigitalOutPA_7.write((ReceiveCount % 2 == 0)); -nrf24_PB_15.read( NRF24L01P_PIPE_P0, rxdata, NRF24_TRANSFER_SIZE); -if (rxdata[0] == 82) { -Power = rxdata[1]; -Yaw_t = rxdata[2] - 45; -Pitch_t = rxdata[3] - 45; -Roll_t = rxdata[4] - 45; -Serial_2.printf("Power=%d, Yaw=%d, Pitch=%d, Roll=%d \n",Power,Yaw_t,Pitch_t,Roll_t); -} -} -myDigitalOutPA_6.write((CycleCount % 2 == 0)); -wait(0.05); -} - -} \ No newline at end of file