Go Down

Topic: MPU6050 + nRF24L01 (Read 848 times) previous topic - next topic



I'm trying to send the signal of MPU6050 (Accelerometer + Gyr) through the nRF24L01 (RF Radio). For both, I'm using librarys, and each sensor alone with its library it works. My aim to send the Euler Angles that the Jeff Rowberg library calculates.

Code: [Select]
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"

MPU6050 mpu;


bool blinkState = false;

// MPU control/status vars
bool dmpReady = false;  // set true if DMP init was successful
uint8_t mpuIntStatus;   // holds actual interrupt status byte from MPU
uint8_t devStatus;      // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize;    // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount;     // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer

Quaternion q;           // [w, x, y, z]         quaternion container
float euler[3];         // [psi, theta, phi]    Euler angle container
float euler_send[3];

uint8_t teapotPacket[14] = { '$', 0x02, 0,0, 0,0, 0,0, 0,0, 0x00, 0x00, '\r', '\n' };

// Interrupt
    volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high
    void dmpDataReady() {
    mpuInterrupt = true;

// RF
RF24 radio(9,10);

const uint64_t pipe = 0xE8E8F0F0E1LL;


void setup() {
    // join I2C bus (I2Cdev library doesn't do this automatically)
    mpu.initialize(); // Initalize I2c device
//    Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
    while (Serial.available() && Serial.read()); // empty buffer again
    devStatus = mpu.dmpInitialize();
     if (devStatus == 0) {
        // turn on the DMP, now that it's ready
//        Serial.println(F("Enabling DMP..."));

        // enable Arduino interrupt detection
//        Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
        attachInterrupt(0, dmpDataReady, RISING);
        mpuIntStatus = mpu.getIntStatus();

        // set our DMP Ready flag so the main loop() function knows it's okay to use it
//        Serial.println(F("DMP ready! Waiting for first interrupt..."));
        dmpReady = true;

        // get expected DMP packet size for later comparison
        packetSize = mpu.dmpGetFIFOPacketSize();
    pinMode(LED_PIN, OUTPUT); // Configure LED for output

void loop() {
   if (!dmpReady) return; // If programming failed, don't try to do anything
   mpuInterrupt = false;
   mpuIntStatus = mpu.getIntStatus();
   fifoCount = mpu.getFIFOCount();
   while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
   mpu.getFIFOBytes(fifoBuffer, packetSize); // Read a packet from FIFO
   fifoCount -= packetSize; //

   // display Euler angles in degrees
            mpu.dmpGetQuaternion(&q, fifoBuffer);
            mpu.dmpGetEuler(euler, &q);
            Serial.print(euler[0] * 180/M_PI);
            Serial.print(euler[1] * 180/M_PI);
            Serial.println(euler[2] * 180/M_PI);
     euler_send[0]= (euler[0] * 180/M_PI);
     radio.write( &euler_send[0], sizeof(euler_send) );
      blinkState = !blinkState;
      digitalWrite(LED_PIN, blinkState);

But, in the first moment it looks like works, but, a bit later it doesn't work. Below a little example that happen.

euler   -0.13   3.06   0.77
euler   -0.15   3.03   0.77
euler   -55.25   nan   34.44
euler   87.35   nan   46.15
euler   -137.02   nan   23.93

Any idea? Thanks so much

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131