Author Topic: MPU6050 coding  (Read 23233 times)

jlajithin

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
MPU6050 coding
« on: February 26, 2014, 10:38:34 PM »
Hi

I wanna use MPU6050 with RFDuino. My program is attached with this. And when i run the program in rfduino it got stuck at the " DMP ready! Waiting for first interrupt... " Please help me. i will attach the original working code for the arduino also.

edorphy

  • RFduino Full Member
  • ***
  • Posts: 86
  • Karma: +0/-0
    • View Profile
Re: MPU6050 coding
« Reply #1 on: February 27, 2014, 06:00:19 PM »
Im assuming this code is included in the I2C Dev project?

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: MPU6050 coding
« Reply #2 on: February 27, 2014, 08:13:17 PM »
I am thinking you might change the interrupt callback setup from

attachInterrupt(0, dmpDataReady, RISING);

to

RFduino_pinWakeCallback(X, HIGH, dmpDataReady);

Change X to the pin number you have hooked up to the MPU6050 interrupt pin.

I don't know if that will work like a real interrupt except when the RFduino is sleeping.
But at lease it should call the callback when the MPU is ready to send something.

edorphy

  • RFduino Full Member
  • ***
  • Posts: 86
  • Karma: +0/-0
    • View Profile
Re: MPU6050 coding
« Reply #3 on: February 28, 2014, 10:44:12 AM »
That was my initial impression, as attachInterrupt won't do anything.

I'm surprised you got as far as you did with your modified code. Lots of incompatibility compile time errors with the code you provided. What modifications have you made to the MPU class or 6 axis motion apps headers?

I have the I2C lib installed required for the DMP sample to work.

I'm working with this chip (MPU6050 specifically for DMP applications) for my senior design project so I'm fairly familiar with it.

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: MPU6050 coding
« Reply #4 on: March 02, 2014, 02:43:19 AM »
Add
#include <RFduinoBLE.h>

Change
#define LED_PIN 13
to a pin number in the RFduino range. I used gpio3.
#define LED_PIN 3

change
void dmpDataRead() {
to
int dmpDataRead(uint32_t ulPin) {

Comment out the TWBR
//       TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)

Change
        attachInterrupt(0, dmpDataReady, RISING);
to
        //attachInterrupt(0, dmpDataReady, RISING);
        pinMode(2,INPUT);
        RFduino_pinWakeCallback(2,HIGH,dmpDataReady);

NOTE, I used gpio2 for the interrupt callback.
That will compile, upload and sort of run getting you started.


thoriqsalafi

  • RFduino Newbie
  • *
  • Posts: 17
  • Karma: +0/-0
    • View Profile
Re: MPU6050 coding
« Reply #5 on: March 02, 2014, 07:26:31 PM »
thanks tolson it is working, but the rfduino is stop receiving the i2c after that, like the one in this post http://forum.rfduino.com/index.php?topic=368.0

can you help me to fix this?
« Last Edit: March 05, 2014, 08:08:30 PM by thoriqsalafi »

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: MPU6050 coding
« Reply #6 on: May 01, 2014, 09:07:48 AM »
Example code...
1. Sending TeaPot Quaternion over the BLE. Serial 9600 baud is painfully slow for TeaPort updates.
2. A different approach to handling the DMP FIFO Interrupt and FIFO overflow problem locking up I2C bus.
3. Tilt experiment
4. The Processing TeaPot program by Jeff Rowberg is an AirPlane. Using his as a basis my version is a Rocket.
http://thomasolson.com/PROJECTS/BLE/RFduino/MyRocket.pde

http://thomasolson.com/PROJECTS/BLE/RFduino/MPU6050_DMP6_MyTilt.ino

Code: [Select]
// MyTilt by Thomas Olson Rev 20140425.1
// Using I2Cdev class by Jeff Rowberg <jeff@rowberg.net>

#include "Wire.h"
#include "I2Cdev.h"
#include <RFduinoBLE.h>

char buf[20]; // buffer to send to BLE radio.

#include "MPU6050_6Axis_MotionApps20.h"
MPU6050 mpu; //MPU6050 mpu(0x69); // <-- use for AD0 high

/* =========================================================================
   NOTE: In addition to connection 3.3v, GND, SDA, and SCL, this sketch
   depends on the MPU-6050's INT pin being connected to GPIO2. (RFduino)
 * ========================================================================= */
// IMPORTANT NOTE: The default RFduino library for I2C uses S0D1 for the pin mode
// of the SCL and SDA lines. Typical BOBs with built-in pullups of 2.2K,4.7K and 10K
// violate the nRF51822 maximum current of 0.5mA for the S0D1 mode.
// Change the libraries/Wire/Wire.cpp to use H0D1 (5.0mA) if combined parallel resistance is
// less than 6.8Kohm.

// My goal is to send the TEAPOT data over the BLE. I need to figure out to get Processing
// to receive bluetooth packets. In mean time I can see the packets using Nordic tool
// and on Linux using gatttool.
// For testing send to Serial Port at 9600(RFduino speed limitation) baud which doesn't
// seem to be fast enough to do serious IMU / DMP work.
// Comment this out to not send to serial port
#define TEAPOT_ON_SERIAL_PORT
#define TILT_ANALYSIS

#define LED_PIN 3 // just needed for testing that the loop is working.
bool blinkState = false;

#define DMP_IRQ_PIN 2 // the INT pin from the MPU for FIFO updates

#ifdef TILT_ANALYSIS
  #define LED_TILT 4
  #define R2D 57.295
  float XYtilt;
  float TiltThreshold = 30.0;  // Threshold of too much tilt
#endif

// 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

// I'm only interested in quaternions.
Quaternion q;           // [w, x, y, z]  quaternion container

// packet structure for InvenSense teapot demo
uint8_t teapotPacket[14] = { '$', 0x02, 0,0, 0,0, 0,0, 0,0, 0x00, 0x00, '\r', '\n' };

// ================================================================
// ===               INTERRUPT DETECTION ROUTINE                ===
// ================================================================

volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high

// To keep from getting hosed by conflict between DMP and Radio priorities disable the
// DMP until FIFO data is dealt with later.
int dmpDataReady(uint32_t ulPin) {
    buf[17]++;
    mpuInterrupt = true;
    mpuIntStatus = mpu.getIntStatus();
    mpu.setDMPEnabled(false);
}

// ================================================================
// ===                      INITIAL SETUP                       ===
// ================================================================

void setup() {
    buf[17]=0; // just a loop counter I send to the BLE.

    Serial.begin(9600);   
    Wire.begin();
    NRF_TWI1->FREQUENCY = TWI_FREQUENCY_FREQUENCY_K100 << TWI_FREQUENCY_FREQUENCY_Pos;

    // initialize device
    Serial.println(F("Initializing I2C devices..."));
    mpu.initialize();

    // verify connection
    Serial.println(F("Testing device connections..."));
    Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

#ifdef TILT_ANALYSIS
    Serial.print("LimitAngle: ");
    Serial.print(TiltThreshold);
    TiltThreshold = sin(TiltThreshold/R2D)/2;
    Serial.print(" - ");
    Serial.println(TiltThreshold);
    pinMode(LED_TILT, OUTPUT);
    digitalWrite(LED_TILT,false);
#endif

    // configure LED for output
    pinMode(LED_PIN, OUTPUT);

    // load and configure the DMP
    Serial.println(F("Initializing DMP..."));
    devStatus = mpu.dmpInitialize();
    // make sure it worked (returns 0 if so)
    if (devStatus == 0) {
      // supply your own gyro offsets here, scaled for min sensitivity
      mpu.setXGyroOffset(220);
      mpu.setYGyroOffset(76);
      mpu.setZGyroOffset(-85);
      mpu.setZAccelOffset(1788);
         
      // 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;

      // enable RFduino interrupt detection
      Serial.println(F("Enabling interrupt detection RFduino GPIO2)..."));
      pinMode(DMP_IRQ_PIN,INPUT);
      mpuIntStatus = mpu.getIntStatus();
      RFduino_pinWakeCallback(DMP_IRQ_PIN,HIGH,dmpDataReady);

      // turn on the DMP, now that it's ready
      Serial.println(F("Enabling DMP..."));
      mpu.setDMPEnabled(true);

      // get expected DMP packet size for later comparison
      packetSize = mpu.dmpGetFIFOPacketSize();

    } else {
        // ERROR!
        // 1 = initial memory load failed
        // 2 = DMP configuration updates failed
        // (if it's going to break, usually the code will be 1)
        Serial.print(F("DMP Initialization failed (code "));
        Serial.print(devStatus);
        Serial.println(F(")"));
    }


    RFduinoBLE.advertisementData = "myDMP"; 
    RFduinoBLE.begin();

}



// ================================================================
// ===                    MAIN PROGRAM LOOP                     ===
// ================================================================

void loop() {
    RFduinoBLE.send(buf,20);

    // if programming failed, don't try to do anything
    if (!dmpReady) return;

    while (!mpuInterrupt) {     
      // other program behavior stuff here
    }

    // Hmmm! Since Radio interrupt can hose our DMP activity throwing it out of wack,
    // send how many DMP interrupts occurred since last action.
    // If more than once print the number of times.
    if(buf[17] > 1){
      //Serial.print("Missed IRQs ");
      //Serial.println((uint8_t)buf[17]);
      buf[16] = buf[17];
      buf[17] = 0;
    }

    // reset interrupt flag
    mpuInterrupt = false;

    fifoCount = mpu.getFIFOCount();

    // check for overflow (this should never happen unless our code is too inefficient)
    if ((mpuIntStatus & 0x10) || fifoCount >= 1024) {
        mpu.resetFIFO();
 //   } else if (mpuIntStatus & 0x02) {  //WTH: should be 0x01
    } else if (mpuIntStatus & 0x01) {
        // wait for correct available data length, should be a VERY short wait
        while (fifoCount < packetSize) {
          fifoCount = mpu.getFIFOCount();
        }
        // read a packet from FIFO
        mpu.getFIFOBytes(fifoBuffer, packetSize);
        // track FIFO count here in case there is > 1 packet available
        // (this lets us immediately read more without waiting for an interrupt)
        fifoCount -= packetSize; //Actually, the way I am doing it now I don't care.
 
 
        #ifdef TILT_ANALYSIS
                             
          // Calcultate tilt angle about the Z axis. Set TILT_FLAG if > limit
          mpu.dmpGetQuaternion(&q, fifoBuffer);

          XYtilt = sqrt(q.x * q.x + q.y * q.y);
          //Serial.print("XYtilt: ");
          //Serial.println(XYtilt);
          if(XYtilt >TiltThreshold){
            digitalWrite(LED_TILT,true);
            teapotPacket[10] = 0x01; // I'm defining the unused byte as a status byte
          }else{
            digitalWrite(LED_TILT,false);
            teapotPacket[10] = 0x00;
          }
        #endif
 
        // display quaternion values in InvenSense Teapot demo format:
        teapotPacket[2] = fifoBuffer[0];
        teapotPacket[3] = fifoBuffer[1];
        teapotPacket[4] = fifoBuffer[4];
        teapotPacket[5] = fifoBuffer[5];
        teapotPacket[6] = fifoBuffer[8];
        teapotPacket[7] = fifoBuffer[9];
        teapotPacket[8] = fifoBuffer[12];
        teapotPacket[9] = fifoBuffer[13];
        teapotPacket[11]++; // packetCount, loops at 0xFF on purpose
           
        #ifdef TEAPOT_ON_SERIAL_PORT
          Serial.write(teapotPacket, 14);
        #endif
           
        for(int i=0;i<14;i++){
          buf[i] = teapotPacket[i]; //teapot data to BLE.
        }

        // The DMP FIFO gets lost when too much radio activity is going on.
        // So forget it. Just reset it
        mpu.resetFIFO();
        // Don't just see if Radio is not running. Instead wait for radio to
        // start and then wait for it to be done to ensure we don't get
        // interrupted.
        while(!RFduinoBLE.radioActive);
        while(RFduinoBLE.radioActive);       
        mpu.setDMPEnabled(true);

        // blink LED to indicate activity
        blinkState = !blinkState;
        digitalWrite(LED_PIN, blinkState);
    }
   
}//loop

// Example Commanding over BLE.
// Not really doing anything important here yet.
void RFduinoBLE_onReceive(char *data, int len) {
  if (len >= 1) { 
        switch(data[0]){
          case 'R':
            //Got RESET CMD;
            RFduino_systemReset();
            break;
          case 'C':
            buf[19]++;
            //Got the Count increment CMD");
            break;
          default:
            break;       
        }
  }
}

// For now just store RSSI in outgoing data buffer.
void RFduinoBLE_onRSSI(int rssi){
  buf[18] = (uint8_t)rssi;
}


sarahzohar88

  • RFduino Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: MPU6050 coding
« Reply #7 on: May 21, 2014, 03:03:12 AM »
Very helpful postings so thanks for it

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: MPU6050 coding
« Reply #8 on: May 25, 2014, 12:30:53 PM »
Looks like RFduino library version 1.9 is doing much better with the I2C bus lockup issues. I've backed out some of my FIFO limiting mods to see if v1.9 works better. I've also commented out the radioActive checks for a worse case test. So far seems to work. Also, we no longer need to hack the UART and variants files to force use of baud rates higher than 9600 with the BLE active as there is now a override_uart_limit variable you can set before defining the serial device.

    override_uart_limit = true;
    Serial.begin(115200);

Code: [Select]
// MyTilt by Thomas Olson Rev 20140425.1
// 20140525.1 Removed my FIFO mods to test RFduino v1.9 fixes.
// Using I2Cdev class by Jeff Rowberg <jeff@rowberg.net>

#include "Wire.h"
#include "I2Cdev.h"
#include <RFduinoBLE.h>

char buf[20]; // buffer to send to BLE radio.

#include "MPU6050_6Axis_MotionApps20.h"
MPU6050 mpu; //MPU6050 mpu(0x69); // <-- use for AD0 high

/* =========================================================================
   NOTE: In addition to connection 3.3v, GND, SDA, and SCL, this sketch
   depends on the MPU-6050's INT pin being connected to GPIO2. (RFduino)
 * ========================================================================= */
// IMPORTANT NOTE: The default RFduino library for I2C uses S0D1 for the pin mode
// of the SCL and SDA lines. Typical BOBs with built-in pullups of 2.2K,4.7K and 10K
// violate the nRF51822 maximum current of 0.5mA for the S0D1 mode.
// Change the libraries/Wire/Wire.cpp to use H0D1 (5.0mA) if combined parallel resistance is
// less than 6.8Kohm. NOTE: RFD v1.9 has switched to H0D1 by default.

// My goal is to send the TEAPOT data over the BLE. I need to figure out to get Processing
// to receive bluetooth packets. In mean time I can see the packets using Nordic tool
// and on Linux using gatttool.
// For testing send to Serial Port at 9600(RFduino speed limitation) baud which doesn't
// seem to be fast enough to do serious IMU / DMP work.
// Comment this out to not send to serial port
#define TEAPOT_ON_SERIAL_PORT
#define TILT_ANALYSIS

#define LED_PIN 3 // just needed for testing that the loop is working.
bool blinkState = false;

#define DMP_IRQ_PIN 2 // the INT pin from the MPU for FIFO updates

#ifdef TILT_ANALYSIS
  #define LED_TILT 4
  #define R2D 57.295
  float XYtilt;
  float TiltThreshold = 30.0;  // Threshold of too much tilt
#endif

// 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

// I'm only interested in quaternions.
Quaternion q;           // [w, x, y, z]  quaternion container

// packet structure for InvenSense teapot demo
uint8_t teapotPacket[14] = { '$', 0x02, 0,0, 0,0, 0,0, 0,0, 0x00, 0x00, '\r', '\n' };

// ================================================================
// ===               INTERRUPT DETECTION ROUTINE                ===
// ================================================================

volatile bool mpuInterrupt = false;     // indicates whether MPU interrupt pin has gone high

// To keep from getting hosed by conflict between DMP and Radio priorities disable the
// DMP until FIFO data is dealt with later. NOTE: no longer needed for RFD v1.9
int dmpDataReady(uint32_t ulPin) {
    buf[17]++;
    mpuInterrupt = true;
//    mpuIntStatus = mpu.getIntStatus();
//    mpu.setDMPEnabled(false);
}

// ================================================================
// ===                      INITIAL SETUP                       ===
// ================================================================

void setup() {
    buf[17]=0; // just a loop counter I send to the BLE.
override_uart_limit = true;
    Serial.begin(115200);   
    Wire.begin();
    NRF_TWI1->FREQUENCY = TWI_FREQUENCY_FREQUENCY_K250 << TWI_FREQUENCY_FREQUENCY_Pos;

    // initialize device
    Serial.println(F("Initializing I2C devices..."));
    mpu.initialize();

    // verify connection
    Serial.println(F("Testing device connections..."));
    Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));

#ifdef TILT_ANALYSIS
    Serial.print("LimitAngle: ");
    Serial.print(TiltThreshold);
    TiltThreshold = sin(TiltThreshold/R2D)/2;
    Serial.print(" - ");
    Serial.println(TiltThreshold);
    pinMode(LED_TILT, OUTPUT);
    digitalWrite(LED_TILT,false);
#endif

    // configure LED for output
    pinMode(LED_PIN, OUTPUT);

    // load and configure the DMP
    Serial.println(F("Initializing DMP..."));
    devStatus = mpu.dmpInitialize();
    // make sure it worked (returns 0 if so)
    if (devStatus == 0) {
      // supply your own gyro offsets here, scaled for min sensitivity
      mpu.setXGyroOffset(220);
      mpu.setYGyroOffset(76);
      mpu.setZGyroOffset(-85);
      mpu.setZAccelOffset(1788);
         
      // 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;

      // enable RFduino interrupt detection
      Serial.println(F("Enabling interrupt detection RFduino GPIO2)..."));
      pinMode(DMP_IRQ_PIN,INPUT);
      mpuIntStatus = mpu.getIntStatus();
      RFduino_pinWakeCallback(DMP_IRQ_PIN,HIGH,dmpDataReady);

      // turn on the DMP, now that it's ready
      Serial.println(F("Enabling DMP..."));
      mpu.setDMPEnabled(true);

      // get expected DMP packet size for later comparison
      packetSize = mpu.dmpGetFIFOPacketSize();

    } else {
        // ERROR!
        // 1 = initial memory load failed
        // 2 = DMP configuration updates failed
        // (if it's going to break, usually the code will be 1)
        Serial.print(F("DMP Initialization failed (code "));
        Serial.print(devStatus);
        Serial.println(F(")"));
    }


    RFduinoBLE.advertisementData = "myDMP"; 
    RFduinoBLE.begin();

}



// ================================================================
// ===                    MAIN PROGRAM LOOP                     ===
// ================================================================

void loop() {
    RFduinoBLE.send(buf,20);

    // if programming failed, don't try to do anything
    if (!dmpReady) return;

    while (!mpuInterrupt) {     
      // other program behavior stuff here
    }

    // Hmmm! Since Radio interrupt can hose our DMP activity throwing it out of wack,
    // send how many DMP interrupts occurred since last action.
    // If more than once print the number of times.
    if(buf[17] > 1){
      //Serial.print("Missed IRQs ");
      //Serial.println((uint8_t)buf[17]);
      buf[16] = buf[17];
      buf[17] = 0;
    }

    // reset interrupt flag
    mpuInterrupt = false;
    mpuIntStatus = mpu.getIntStatus();
   
    fifoCount = mpu.getFIFOCount();

    // check for overflow (this should never happen unless our code is too inefficient)
    if ((mpuIntStatus & 0x10) || fifoCount >= 1024) {
        mpu.resetFIFO();
 //   } else if (mpuIntStatus & 0x02) {  //WTH: should be 0x01
    } else if (mpuIntStatus & 0x01) {
        // wait for correct available data length, should be a VERY short wait
        while (fifoCount < packetSize) {
          fifoCount = mpu.getFIFOCount();
        }
        // read a packet from FIFO
        mpu.getFIFOBytes(fifoBuffer, packetSize);
        // track FIFO count here in case there is > 1 packet available
        // (this lets us immediately read more without waiting for an interrupt)
        fifoCount -= packetSize; //Actually, the way I am doing it now I don't care.
 
 
        #ifdef TILT_ANALYSIS
                             
          // Calcultate tilt angle about the Z axis. Set TILT_FLAG if > limit
          mpu.dmpGetQuaternion(&q, fifoBuffer);

          XYtilt = sqrt(q.x * q.x + q.y * q.y);
          //Serial.print("XYtilt: ");
          //Serial.println(XYtilt);
          if(XYtilt >TiltThreshold){
            digitalWrite(LED_TILT,true);
            teapotPacket[10] = 0x01; // I'm defining the unused byte as a status byte
          }else{
            digitalWrite(LED_TILT,false);
            teapotPacket[10] = 0x00;
          }
        #endif
 
        // display quaternion values in InvenSense Teapot demo format:
        teapotPacket[2] = fifoBuffer[0];
        teapotPacket[3] = fifoBuffer[1];
        teapotPacket[4] = fifoBuffer[4];
        teapotPacket[5] = fifoBuffer[5];
        teapotPacket[6] = fifoBuffer[8];
        teapotPacket[7] = fifoBuffer[9];
        teapotPacket[8] = fifoBuffer[12];
        teapotPacket[9] = fifoBuffer[13];
        teapotPacket[11]++; // packetCount, loops at 0xFF on purpose
           
        #ifdef TEAPOT_ON_SERIAL_PORT
          Serial.write(teapotPacket, 14);
        #endif
           
        for(int i=0;i<14;i++){
          buf[i] = teapotPacket[i]; //teapot data to BLE.
        }

        // The DMP FIFO gets lost when too much radio activity is going on.
        // So forget it. Just reset it
  //      mpu.resetFIFO();
        // Don't just see if Radio is not running. Instead wait for radio to
        // start and then wait for it to be done to ensure we don't get
        // interrupted.
//        while(!RFduinoBLE.radioActive);
//        while(RFduinoBLE.radioActive);       
//        mpu.setDMPEnabled(true);

        // blink LED to indicate activity
        blinkState = !blinkState;
        digitalWrite(LED_PIN, blinkState);
    }
   
}//loop

// Example Commanding over BLE.
// Not really doing anything important here yet.
void RFduinoBLE_onReceive(char *data, int len) {
  if (len >= 1) { 
        switch(data[0]){
          case 'R':
            //Got RESET CMD;
            RFduino_systemReset();
            break;
          case 'C':
            buf[19]++;
            //Got the Count increment CMD");
            break;
          default:
            break;       
        }
  }
}

// For now just store RSSI in outgoing data buffer.
void RFduinoBLE_onRSSI(int rssi){
  buf[18] = (uint8_t)rssi;
}


« Last Edit: May 25, 2014, 12:33:08 PM by tolson »

Bamba

  • RFduino Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: MPU6050 coding
« Reply #9 on: May 31, 2014, 02:30:28 PM »
Thank you for the help guys.

I too am trying to do the MPUTeapot over BTLE, but for now I am trying to have it working over the USB port.
here is where I am at:
I have the MPU6050_MDP6 sketch working (with the help of you guys and others), I have processing running and I see the plan Applet running but I have no communicating between Processing and the RFduino (which is at this point a rduino). The RFduino is not receiving the 'r' character from Processing and even if I enter it on the serial port monitor, Processing is not being updated.

any help please?
what tools can I use to monitor the serial port ( I am using a MAC, but only for couple of years). I am not new to programming.
thank you 

I can see the DMP outputs on the serial monitor.
I have enabled OUPUT_TEAPOT
my serial settings are the same as the Processing : 115200


« Last Edit: June 02, 2014, 01:20:51 PM by Bamba »

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: MPU6050 coding
« Reply #10 on: May 31, 2014, 02:45:40 PM »
Check what your serial port device is called on the MAC and change the processing sketch to match. On my Linux system my USB adaptor is /dev/ttyUSB0.
Also, you have to not be using the Arduino serial monitor when you start the processing sketch.

Bamba

  • RFduino Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: MPU6050 coding
« Reply #11 on: June 01, 2014, 12:56:35 PM »
Thank you Tolson.
yes, that helped, I was reading that I had to change the port name.
If anyone else has this issue, I made the following changes to the MPUTEAport processing :

    //String portName = Serial.list()[0];   <= commented this line out
   
    // get a specific serial port (use EITHER this OR the first-available code above)
    String portName = "/dev/tty.usbserial-DC008KR3";   <= uncommented this line and added the port name

updated serial port baud rate to 9600 and also on the RFDuino sketch
port = new Serial(this, portName, 9600);

next is to try and have it work using the BT.
Adi

Bamba

  • RFduino Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: MPU6050 coding
« Reply #12 on: June 02, 2014, 01:23:20 PM »
Hi Tolson,
Thank you for the Rocket code, I ran both the processing sketch and the RFDunio sketch you provided using the RFdunio libs version 2.0 and I am still up able to connect at higher baud rate than 9600.
Do you have any idea why?
thanks,
B

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: MPU6050 coding
« Reply #13 on: June 02, 2014, 01:34:32 PM »
Which version of MyTilt sketch are you running. The MyTilt3 is the one for baud rate greater than 9600.

Make sure you have the override_uart_limit=true before the Serial.begin statement.
I.E...

    override_uart_limit = true;
    Serial.begin(115200);

Bamba

  • RFduino Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: MPU6050 coding
« Reply #14 on: June 02, 2014, 01:58:41 PM »
yes, using MyTilt3..

void setup() {
    buf[17]=0; // just a loop counter I send to the BLE.
override_uart_limit = true;
    Serial.begin(115200);   
    Wire.begin();
    NRF_TWI1->FREQUENCY = TWI_FREQUENCY_FREQUENCY_K250 << TWI_FREQUENCY_FREQUENCY_Pos;
..

processing:

    // get a specific serial port (use EITHER this OR the first-available code above)
    String portName = "/dev/tty.usbserial-DC008KR3";
    // open the serial port
    port = new Serial(this, portName, 115200);

output:


/dev/cu.Bluetooth-Incoming-Port /dev/cu.Bluetooth-Modem /dev/cu.usbserial-DC008KR3 /dev/tty.Bluetooth-Incoming-Port /dev/tty.Bluetooth-Modem /dev/tty.usbserial-DC008KR3
SEND R
SENT R
SEND R AGAIN
SEND R AGAIN
SEND R AGAIN

very strange, the only Baud rate that works is 9600