Jump to content
I2Cdevlib Forums

Search the Community

Showing results for tags 'mpu6050'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • I2Cdevlib Web Tools
    • I2C Protocol Analyzer
    • I2C Device Entry Interface
    • I2C Device Library API
  • I2Cdev Platform Discussion
    • Arduino (ATmega)
    • Arduino Due (ARM Cortex M3)
    • MSP430
    • Other Platforms
  • I2C Device Discussion
    • AD7746 capacitance-to-digital converter (Analog Devices)
    • ADS1115 16-bit A/D converter (Texas Instruments)
    • ADXL345 3-axis accelerometer (Analog Devices)
    • AK8975 3-axis magnetometer (AKM Semiconductor)
    • BMA150 3-axis accelerometer (Bosch Sensortec)
    • BMP085 pressure sensor (Bosch Sensortec)
    • DS1307 real-time clock (Maxim)
    • HMC5843 3-axis magnetometer (Honeywell)
    • HMC5883L 3-axis magnetometer (Honeywell)
    • iAQ-2000 indoor air quality sensor (AppliedSensor)
    • IQS156 ProxSense capacitive touch sensor (Azoteq)
    • ITG-3200 3-axis gyroscope (InvenSense)
    • L3G4200D 3-axis accelerometer (STMicroelectronics)
    • MPL3115A2 Xtrinsic Smart Pressure Sensor (Freescale)
    • MPR121 12-bit capacitive touch sensor (Freescale)
    • MPU-6050 6-axis accelerometer/gyroscope (InvenSense)
    • MPU-9150 9-axis accelerometer/gyroscope/magnetometer (InvenSense)
    • PanelPilot multi-screen digital meter (Lascar Electronics)
    • SSD1308 128x64 OLED/PLED driver (Solomon Systech)
    • TCA6424A 24-bit I/O expander (Texas Instruments)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

  1. HI Jeff, i work in UAV project with nrf52, i use a gy+-87 as motion's sensor . i have update your library of mpu 6050 for nrf 51 to nrf52 and it worked well based on the i2cdev library of nrf. i wrote a similar lirary for the hmc5883 inspired from yours for adruino, but i have some problem, the first that when i set a bypass to MPU6050, it seems that didnt work because i don't receve any data from the mag sensor, second when i try a lonely mag sensor hmc5883, i get data but the function of set gain and set mode seems didnt work because the when i receive data , all parameters of the sensor are the default parameters. can u take an eye please in my library and try to fixed the problem because i see that all the code was right mpu6500.c mpu6500.h i2cdev.c i2cdev.h main.c
  2. Hello there! I am beginner at this and I want to obtain the following: the raw gyroscope and accelerometer data from my MPU6050 (sparkfun edition). I did that. set the frequency of the IMU at 100 Hz. How to do this? the GNSS(GPS) data from arduino type GPS module. I did that. check/ set GPS frequency to 100 Hz. How to do this? use the MPU6050 fsync function so that I could get : 1 set of acc/gyro data at the same time as getting 1 set of gps data 99 sets of acc/gyro data (time spent since the beginning = 1 s) 1 set of acc/gyro data at the same time as getting 1 set of gps data 99.... etc. How to do this? Thank you! P.S. I need proper description:D
  3. Hi, Question about Accelerometer Scale Sensitivity Factor wrong values reading I have read accel values 8192 at +/- 2g but its should read 1g of 16384 at sensitivity of 2g From Datasheet https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf P.29 AFS_SEL | Full Scale Range | LSB Sensitivity--------+------------------+----------------0 | +/- 2g | 16384 LSB/g1 | +/- 4g | 8192 LSB/g2 | +/- 8g | 4096 LSB/g3 | +/- 16g | 2048 LSB/g Is somethings wrong? Thanks in advance.
  4. Hi, I'm new to the MPU6050 but getting some good results using 8051 micro interfaced to GY-521 breakout board to MPU6050. One puzzling thing is that while the Invensense register map for the MPU6050 states: REGISTERS 59 TO 64 – ACCELEROMETER MEASUREMENTS REGISTERS 67 TO 72 – GYROSCOPE MEASUREMENTS After a 200 mSec delay I measure the offsets, save them and subtract the offsets from the X,Y, and Z values of the acceleration and gyro angles. The results show values near zero after subtracting the offsets. So far, so good. But...I get the Gyro and Acceleration reversed. When I rotate the GY-521 90 degrees and then keep the board stable at the 90 degree position, the Acceleration values stay at a high value but the Gyro angle goes back to zero. When I rotate the board back to the resting position both the acceleration and gyro values got back to near zero. The gyro values only change when the board is actually being moved and go back to zero when the board is stationary, irregardless of the position/angle of the board. Here is the code: while(1) { ReadBytesIIC(59,14); //Read 14 register bytes starting at MPU6050 register 59. //Array[0]=register 59, Array[1]=register 60, etc. AccX=256*(int)Array[0]+(int)Array[1]+AccXOffset; AccY=256*(int)Array[2]+(int)Array[3]+AccYOffset; AccZ=256*(int)Array[4]+(int)Array[5]+AccZOffset; GyroX=256*(int)Array[8]+(int)Array[9]+GyroXOffset; GyroY=256*(int)Array[10]+(int)Array[11]+GyroYOffset; GyroZ=256*(int)Array[12]+(int)Array[13]+GyroZOffset; printf("\nAX,Y,Z, GX,Y,Z=%5d %5d %5d %5d %5d %5d",AccX,AccY,AccZ,GyroX,GyroY,GyroZ); DlyMs(50); } Can anyone explain to me why this might be happening? Thank you in advance. Bert
  5. I have a final project at the school. Me and my friend make an earthquake detector with mpu6050 sensor Which makes me and my friend confused is how i measure the irregular numbers of this mpu6050 Is there any way how to convert the numbers generated by mpu6050 into the Richter scale (SR) Do i have to custom that number into SR to display into lcd. sorry my bad english. here is my code // I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class // 10/7/2011 by Jeff Rowberg <jeff@rowberg.net> // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib // // Changelog: // 2013-05-08 - added multiple output formats // - added seamless Fastwire support // 2011-10-07 - initial release /* ============================================ I2Cdev device library code is placed under the MIT license Copyright (c) 2011 Jeff Rowberg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =============================================== */ // I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files // for both classes must be in the include path of your project #include "I2Cdev.h" #include "MPU6050.h" // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation // is used in I2Cdev.h #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include "Wire.h" #endif // class default I2C address is 0x68 // specific I2C addresses may be passed as a parameter here // AD0 low = 0x68 (default for InvenSense evaluation board) // AD0 high = 0x69 MPU6050 accelgyro; //MPU6050 accelgyro(0x69); // <-- use for AD0 high int16_t ax, ay, az; int16_t gx, gy, gz; int16_t vx, vy, vz; int xmax, xmin, ymax, ymin ,zmax, zmin; // uncomment "OUTPUT_READABLE_ACCELGYRO" if you want to see a tab-separated // list of the accel X/Y/Z and then gyro X/Y/Z values in decimal. Easy to read, // not so easy to parse, and slow(er) over UART. #define OUTPUT_READABLE_ACCELGYRO // uncomment "OUTPUT_BINARY_ACCELGYRO" to send all 6 axes of data as 16-bit // binary, one right after the other. This is very fast (as fast as possible // without compression or data loss), and easy to parse, but impossible to read // for a human. //#define OUTPUT_BINARY_ACCELGYRO #define LED_PIN 13 bool blinkState = false; void setup() { // join I2C bus (I2Cdev library doesn't do this automatically) #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE Wire.begin(); #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); #endif // initialize serial communication // (38400 chosen because it works as well at 8MHz as it does at 16MHz, but // it's really up to you depending on your project) Serial.begin(38400); // initialize device Serial.println("Initializing I2C devices..."); accelgyro.initialize(); // verify connection Serial.println("Testing device connections..."); Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); // use the code below to change accel/gyro offset values /* Serial.println("Updating internal sensor offsets..."); // -76 -2359 1688 0 0 0 Serial.print(accelgyro.getXAccelOffset()); Serial.print("\t"); // -76 Serial.print(accelgyro.getYAccelOffset()); Serial.print("\t"); // -2359 Serial.print(accelgyro.getZAccelOffset()); Serial.print("\t"); // 1688 Serial.print(accelgyro.getXGyroOffset()); Serial.print("\t"); // 0 Serial.print(accelgyro.getYGyroOffset()); Serial.print("\t"); // 0 Serial.print(accelgyro.getZGyroOffset()); Serial.print("\t"); // 0 Serial.print("\n"); accelgyro.setXGyroOffset(220); accelgyro.setYGyroOffset(76); accelgyro.setZGyroOffset(-85); Serial.print(accelgyro.getXAccelOffset()); Serial.print("\t"); // -76 Serial.print(accelgyro.getYAccelOffset()); Serial.print("\t"); // -2359 Serial.print(accelgyro.getZAccelOffset()); Serial.print("\t"); // 1688 Serial.print(accelgyro.getXGyroOffset()); Serial.print("\t"); // 0 Serial.print(accelgyro.getYGyroOffset()); Serial.print("\t"); // 0 Serial.print(accelgyro.getZGyroOffset()); Serial.print("\t"); // 0 Serial.print("\n"); */ // configure Arduino LED for pinMode(LED_PIN, OUTPUT); pinMode(11, OUTPUT); digitalWrite(11,LOW); delay(10000); accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); xmax=ax+2000; xmin=ax-2000; ymax=ay+2000; ymin=ay-2000; zmax=az+2000; zmin=az-2000; } void loop() { // read raw accel/gyro measurements from device accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); /*int t=10; vx=ax*t; vy=ay*t; vz=az*t;*/ if (ax>xmax||ax<xmin||ay>ymax||ay<ymin||az>zmax||az<zmin){ digitalWrite(11,HIGH); delay(8000); digitalWrite(11,LOW); } // these methods (and a few others) are also available //accelgyro.getAcceleration(&ax, &ay, &az); //accelgyro.getRotation(&gx, &gy, &gz); #ifdef OUTPUT_READABLE_ACCELGYRO // display tab-separated accel/gyro x/y/z values Serial.print("a/g:\t"); Serial.print(ax); Serial.print("\t"); Serial.print(ay); Serial.print("\t"); Serial.println(az); #endif #ifdef OUTPUT_BINARY_ACCELGYRO Serial.write((uint8_t)(ax >> 8)); Serial.write((uint8_t)(ax & 0xFF)); Serial.write((uint8_t)(ay >> 8)); Serial.write((uint8_t)(ay & 0xFF)); Serial.write((uint8_t)(az >> 8)); Serial.write((uint8_t)(az & 0xFF)); #endif // blink LED to indicate activity blinkState = !blinkState; digitalWrite(LED_PIN, blinkState); } thanks for the help master
  6. Hello, I am trying to interface the MPU6050 with Cypress PSoC 5 LP097 and read out the values. However I find that the values I read out are always zeroes. I have been struggling on this issue for quite long and do not know how to proceed ahead. Any tips are appreciated. Below is the code : File : MPU6050.c void Wakeup(void) { writeBit(MPU6050_RA_PWR_MGMT, MPU6050_PWR1_SLEEP_BIT,0); } void readbyte(uint8_t reg, uint8_t *data) { readbytes(reg,1,data); } bool readbytes(uint8_t reg, uint8_t len, uint8_t *data) { int i = 0; bool readSuccess = false; while (I2C_MSTR_NO_ERROR == I2C_MasterSendStart(MPU6050_DEVICE_ADDRESS, I2C_WRITE_XFER_MODE)); while (I2C_MSTR_NO_ERROR == I2C_MasterWriteByte(reg)); while (I2C_MSTR_NO_ERROR == I2C_MasterSendRestart(MPU6050_DEVICE_ADDRESS, I2C_READ_XFER_MODE)); while (i < (len-1) ) { data[i++] = I2C_MasterReadByte(I2C_ACK_DATA); } data = I2C_MasterReadByte(I2C_NAK_DATA); readSuccess = true; I2C_MasterSendStop(); UART_PutString("I2C read completed \n"); return readSuccess; } void writeBit(uint8_t reg, uint8_t num, uint8_t data) { uint8 pwr_mgmt_reg = 0; readbyte(reg,&pwr_mgmt_reg); // read the current value of pwr_mgmt_register UART_PutString("Pw mgmnt reg value = "); UART_PutChar(pwr_mgmt_reg + CONVERT_TO_ASCII); UART_PutString("\n"); pwr_mgmt_reg &= ~(1<<num); //set the sleep bit in the register // pwr_mgmt_reg &= 0x3F; writebyte(reg,pwr_mgmt_reg); //write back after setting the pin. } void writebyte(uint8_t reg, uint8_t data) { //uint8 i = 0; while (I2C_MSTR_NO_ERROR == I2C_MasterSendStart(MPU6050_DEVICE_ADDRESS, I2C_WRITE_XFER_MODE)); //start sequence while (I2C_MSTR_NO_ERROR == I2C_MasterWriteByte(reg)); //reach the reg address. //I2C_MasterSendRestart(SLAVE_ADDR, 0x00); while (I2C_MSTR_NO_ERROR == I2C_MasterWriteByte(data)); //write the data I2C_MasterSendStop(); //stop sequence UART_PutString("-----I2C write completed \n"); } bool readGyroData(uint8_t* rBuffer, uint8_t length) { return readbytes(MPU6050_RA_ACCEL_XOUT_H, length,rBuffer); } File main.c : #include "MPU6050.h" #include "project.h" #include <stdio.h> #include <stdbool.h> #define BUFFER_SIZE 0x1F4u #define CONVERT_TO_ASCII 0x30 #define MPU6050_DEVICE_ADDRESS 0x68u #define MPU6050_RA_ACCEL_XOUT_H 0x3Bu #define MPU6050_RA_PWR_MGMT 0x6Bu #define MPU6050_PWR1_SLEEP_BIT 0x06u /*MPU data read buffer*/ uint8_t I2C_RBUFFER[BUFFER_SIZE]; bool readGyroData(uint8_t* rBuffer, uint8_t length); int main(void) { CyGlobalIntEnable; /* Enable global interrupts. */ uint8 i; /* Place your initialization/startup code here (e.g. MyInst_Start()) */ I2C_Start(); UART_Start(); Wakeup(); for(;;) { /* Place your application code here. */ if (true == readGyroData(I2C_RBUFFER,0x0E)) { //14 bytes to read including temp. UART_PutString("GY 521 data : \n"); for(i = 0; i < 14; i++) { UART_PutCRLF(I2C_RBUFFER + CONVERT_TO_ASCII); } CyDelay(50); } else { UART_PutString("no data to read"); } } }
  7. I have tried the below program to interface mpu6050 with esp8266-12e and arduino uno both show fifo overflow issue when additional program is used. And it's giving this issue only when I include some delay in program like 1sec delay removing that delay it will work fine with no problems (now I have added delay just for test purpose that is:I will actually be throwing the data in firebase which will have more than 5 seconds delay when throwing angular data that time also it's going to give me overflow which happened) how do I sort this issue? Here is my code: #include "I2Cdev.h" #include "MPU6050_6Axis_MotionApps20.h" //#include "MPU6050.h" // not necessary if using MotionApps include file // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation // is used in I2Cdev.h #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include "Wire.h" #endif MPU6050 mpu; #define OUTPUT_READABLE_EULER //#define OUTPUT_READABLE_YAWPITCHROLL //#define OUTPUT_READABLE_REALACCEL //#define OUTPUT_READABLE_WORLDACCEL //#define OUTPUT_TEAPOT #define INTERRUPT_PIN 2 // use pin 2 on Arduino Uno & most boards //#define LED_PIN 13 // (Arduino is 13, Teensy is 11, Teensy++ is 6) 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 // orientation/motion vars Quaternion q; // [w, x, y, z] quaternion container VectorInt16 aa; // [x, y, z] accel sensor measurements VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements VectorFloat gravity; // [x, y, z] gravity vector float euler[3]; // [psi, theta, phi] Euler angle container float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector // 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 = true; // indicates whether MPU interrupt pin has gone high void dmpDataReady() { mpuInterrupt = true; } // ================================================================ // === INITIAL SETUP === // ================================================================ void setup() { Serial.begin(9600); // join I2C bus (I2Cdev library doesn't do this automatically) #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE //Wire.begin(4,5); Wire.begin(); //Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); #endif while (!Serial); // wait for Leonardo enumeration, others continue immediately Serial.println(F("Initializing I2C devices...")); mpu.initialize(); pinMode(INTERRUPT_PIN, INPUT); // verify connection Serial.println(F("Testing device connections...")); Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed")); // wait for ready Serial.println(F("\nSend any character to begin DMP programming and demo: ")); while (Serial.available() && Serial.read()); // empty buffer while (!Serial.available()); // wait for data while (Serial.available() && Serial.read()); // empty buffer again // load and configure the DMP Serial.println(F("Initializing DMP...")); devStatus = mpu.dmpInitialize(); // supply your own gyro offsets here, scaled for min sensitivity mpu.setXGyroOffset(-4); mpu.setYGyroOffset(7); mpu.setZGyroOffset(65); mpu.setZAccelOffset(1318); // 1688 factory default for my test chip // make sure it worked (returns 0 if so) if (devStatus == 0) { // turn on the DMP, now that it's ready Serial.println(F("Enabling DMP...")); mpu.setDMPEnabled(true); // enable Arduino interrupt detection Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)...")); // attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING); //mpuInterrupt = true; 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(); } 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(")")); } // configure LED for output // pinMode(LED_PIN, OUTPUT); } // ================================================================ // === MAIN PROGRAM LOOP === // ================================================================ void loop() { // if programming failed, don't try to do anything mpu_data(); delay(1000); } void mpu_data(void) { if (!dmpReady) return; // wait for MPU interrupt or extra packet(s) available //while (!mpuInterrupt && fifoCount < packetSize) // { // other program behavior stuff here // . // . // . // if you are really paranoid you can frequently test in between other // stuff to see if mpuInterrupt is true, and if so, "break;" from the // while() loop to immediately process the MPU data // . // . // . //} fifoCount = mpu.getFIFOCount(); // check for overflow (this should never happen unless our code is too inefficient) if(fifoCount == 1024) { // reset so we can continue cleanly mpu.resetFIFO(); Serial.println(F("FIFO overflow!")); // otherwise, check for DMP data ready interrupt (this should happen frequently) } else { // 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); mpu.resetFIFO(); // track FIFO count here in case there is > 1 packet available // (this lets us immediately read more without waiting for an interrupt) fifoCount -= packetSize; Serial.println(fifoCount); if (fifoCount > 2) { ////// clear fifo buffer mpu.resetFIFO(); } #ifdef OUTPUT_READABLE_QUATERNION // display quaternion values in easy matrix form: w x y z mpu.dmpGetQuaternion(&q, fifoBuffer); Serial.print("quat\t"); Serial.print(q.w); Serial.print("\t"); Serial.print(q.x); Serial.print("\t"); Serial.print(q.y); Serial.print("\t"); Serial.println(q.z); #endif #ifdef OUTPUT_READABLE_EULER // display Euler angles in degrees mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetEuler(euler, &q); Serial.print("euler\t"); Serial.print(euler[0] * 180/M_PI); Serial.print("\t"); Serial.print(euler[1] * 180/M_PI); Serial.print("\t"); Serial.println(euler[2] * 180/M_PI); #endif #ifdef OUTPUT_READABLE_YAWPITCHROLL // display Euler angles in degrees mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetGravity(&gravity, &q); mpu.dmpGetYawPitchRoll(ypr, &q, &gravity); Serial.print("ypr\t"); Serial.print(ypr[0] * 180/M_PI); Serial.print("\t"); Serial.print(ypr[1] * 180/M_PI); Serial.print("\t"); Serial.println(ypr[2] * 180/M_PI); #endif #ifdef OUTPUT_READABLE_REALACCEL // display real acceleration, adjusted to remove gravity mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetAccel(&aa, fifoBuffer); mpu.dmpGetGravity(&gravity, &q); mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity); Serial.print("areal\t"); Serial.print(aaReal.x); Serial.print("\t"); Serial.print(aaReal.y); Serial.print("\t"); Serial.println(aaReal.z); #endif #ifdef OUTPUT_READABLE_WORLDACCEL // display initial world-frame acceleration, adjusted to remove gravity // and rotated based on known orientation from quaternion mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetAccel(&aa, fifoBuffer); mpu.dmpGetGravity(&gravity, &q); mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity); mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q); Serial.print("aworld\t"); Serial.print(aaWorld.x); Serial.print("\t"); Serial.print(aaWorld.y); Serial.print("\t"); Serial.println(aaWorld.z); #endif #ifdef OUTPUT_TEAPOT // 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]; Serial.write(teapotPacket, 14); teapotPacket[11]++; // packetCount, loops at 0xFF on purpose #endif } } I saw this link :http://arduino.stackexchange.com/questions/10308/how-to-clear-fifo-buffer-on-mpu6050 and made changes but, no effect (note: I get proper data if I remove 1s delay in main void() loop if not it will give this fifo problem)
  8. I have tried the below program to interface mpu6050 with esp8266-12e and arduino uno both show fifo overflow issue when additional program is used. And it's giving this issue only when I include some delay in program like 1sec delay removing that delay it will work fine with no problems (now I have added delay just for test purpose that is:I will actually be throwing the data in firebase which will have more than 5 seconds delay when throwing angular data that time also it's going to give me overflow which happened) how do I sort this issue? Here is my code: #include "I2Cdev.h" #include "MPU6050_6Axis_MotionApps20.h" //#include "MPU6050.h" // not necessary if using MotionApps include file // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation // is used in I2Cdev.h #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include "Wire.h" #endif MPU6050 mpu; #define OUTPUT_READABLE_EULER //#define OUTPUT_READABLE_YAWPITCHROLL //#define OUTPUT_READABLE_REALACCEL //#define OUTPUT_READABLE_WORLDACCEL //#define OUTPUT_TEAPOT #define INTERRUPT_PIN 2 // use pin 2 on Arduino Uno & most boards //#define LED_PIN 13 // (Arduino is 13, Teensy is 11, Teensy++ is 6) 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 // orientation/motion vars Quaternion q; // [w, x, y, z] quaternion container VectorInt16 aa; // [x, y, z] accel sensor measurements VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements VectorFloat gravity; // [x, y, z] gravity vector float euler[3]; // [psi, theta, phi] Euler angle container float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector // 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 = true; // indicates whether MPU interrupt pin has gone high void dmpDataReady() { mpuInterrupt = true; } // ================================================================ // === INITIAL SETUP === // ================================================================ void setup() { Serial.begin(9600); // join I2C bus (I2Cdev library doesn't do this automatically) #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE //Wire.begin(4,5); Wire.begin(); //Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having compilation difficulties #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); #endif while (!Serial); // wait for Leonardo enumeration, others continue immediately Serial.println(F("Initializing I2C devices...")); mpu.initialize(); pinMode(INTERRUPT_PIN, INPUT); // verify connection Serial.println(F("Testing device connections...")); Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed")); // wait for ready Serial.println(F("\nSend any character to begin DMP programming and demo: ")); while (Serial.available() && Serial.read()); // empty buffer while (!Serial.available()); // wait for data while (Serial.available() && Serial.read()); // empty buffer again // load and configure the DMP Serial.println(F("Initializing DMP...")); devStatus = mpu.dmpInitialize(); // supply your own gyro offsets here, scaled for min sensitivity mpu.setXGyroOffset(-4); mpu.setYGyroOffset(7); mpu.setZGyroOffset(65); mpu.setZAccelOffset(1318); // 1688 factory default for my test chip // make sure it worked (returns 0 if so) if (devStatus == 0) { // turn on the DMP, now that it's ready Serial.println(F("Enabling DMP...")); mpu.setDMPEnabled(true); // enable Arduino interrupt detection Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)...")); // attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING); //mpuInterrupt = true; 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(); } 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(")")); } // configure LED for output // pinMode(LED_PIN, OUTPUT); } // ================================================================ // === MAIN PROGRAM LOOP === // ================================================================ void loop() { // if programming failed, don't try to do anything mpu_data(); delay(1000); } void mpu_data(void) { if (!dmpReady) return; // wait for MPU interrupt or extra packet(s) available //while (!mpuInterrupt && fifoCount < packetSize) // { // other program behavior stuff here // . // . // . // if you are really paranoid you can frequently test in between other // stuff to see if mpuInterrupt is true, and if so, "break;" from the // while() loop to immediately process the MPU data // . // . // . //} fifoCount = mpu.getFIFOCount(); // check for overflow (this should never happen unless our code is too inefficient) if(fifoCount == 1024) { // reset so we can continue cleanly mpu.resetFIFO(); Serial.println(F("FIFO overflow!")); // otherwise, check for DMP data ready interrupt (this should happen frequently) } else { // 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); mpu.resetFIFO(); // track FIFO count here in case there is > 1 packet available // (this lets us immediately read more without waiting for an interrupt) fifoCount -= packetSize; Serial.println(fifoCount); if (fifoCount > 2) { ////// clear fifo buffer mpu.resetFIFO(); } #ifdef OUTPUT_READABLE_QUATERNION // display quaternion values in easy matrix form: w x y z mpu.dmpGetQuaternion(&q, fifoBuffer); Serial.print("quat\t"); Serial.print(q.w); Serial.print("\t"); Serial.print(q.x); Serial.print("\t"); Serial.print(q.y); Serial.print("\t"); Serial.println(q.z); #endif #ifdef OUTPUT_READABLE_EULER // display Euler angles in degrees mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetEuler(euler, &q); Serial.print("euler\t"); Serial.print(euler[0] * 180/M_PI); Serial.print("\t"); Serial.print(euler[1] * 180/M_PI); Serial.print("\t"); Serial.println(euler[2] * 180/M_PI); #endif #ifdef OUTPUT_READABLE_YAWPITCHROLL // display Euler angles in degrees mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetGravity(&gravity, &q); mpu.dmpGetYawPitchRoll(ypr, &q, &gravity); Serial.print("ypr\t"); Serial.print(ypr[0] * 180/M_PI); Serial.print("\t"); Serial.print(ypr[1] * 180/M_PI); Serial.print("\t"); Serial.println(ypr[2] * 180/M_PI); #endif #ifdef OUTPUT_READABLE_REALACCEL // display real acceleration, adjusted to remove gravity mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetAccel(&aa, fifoBuffer); mpu.dmpGetGravity(&gravity, &q); mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity); Serial.print("areal\t"); Serial.print(aaReal.x); Serial.print("\t"); Serial.print(aaReal.y); Serial.print("\t"); Serial.println(aaReal.z); #endif #ifdef OUTPUT_READABLE_WORLDACCEL // display initial world-frame acceleration, adjusted to remove gravity // and rotated based on known orientation from quaternion mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetAccel(&aa, fifoBuffer); mpu.dmpGetGravity(&gravity, &q); mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity); mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q); Serial.print("aworld\t"); Serial.print(aaWorld.x); Serial.print("\t"); Serial.print(aaWorld.y); Serial.print("\t"); Serial.println(aaWorld.z); #endif #ifdef OUTPUT_TEAPOT // 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]; Serial.write(teapotPacket, 14); teapotPacket[11]++; // packetCount, loops at 0xFF on purpose #endif } } I saw this link :http://arduino.stackexchange.com/questions/10308/how-to-clear-fifo-buffer-on-mpu6050 and made changes but, no effect (note: I get proper data if I remove 1s delay in main void() loop if not it will give this fifo problem)
  9. Hi all, I'm trying to use the mpu6050 as a shock sensor (ie if a shock is > 2g's log the force and timestamp it). Here's the twist, I managed to get the MOT_INT working, but I eventhough i see changes in force required ro triggger an interrupt ( setting MOT_THR byte) I can't map it reliably to an actual G value. Each accelerometer output is on 16bits (signed) but the threshold is set on 8bits (signed) (which means you can only set the interrupt as 1/128th of the actual resolution ?). Also, once the interrupt is triggered, how am I supposed to find the "triggering value" in the fifo stack ? If you have any idea, please share
  10. Hello to everyone, I'm new in this forum and i'm searching for some help. I need to use two MPU6050 on the same arduino uno but i don't know how to do this, i need to send xyz (accelerometer and gyroscope) values to Max MSP via serial port. I'm not a programmer but an electroacoustic composer and i need to use two sensors to control gestures by a performer. I hope in your help. Thank you in advance Paolo accelerometro.zip
  11. Hi, I have a question about the sampling rate and the digital low pass filter configuration values for the mpu6050. I know from the datasheet that the output rate for the acceleration is 1kHz. I use the clock source from the X Gyro for reference, as default on the mpu6050.h lib from jeff rowberg. Does the DLPF_CFG = 0 (260Hz ) affect my acceleration sampling rate or the acceleration output rate? If so, does the output rate goes from 1kHz down to 260Hz? Thanks in advance
  12. Hallo everyone, does someone know what's kind of battery should i use for mpu6050,because i want to use the battery to power the mpu6050,i have tried use tow serial Li-ion which are up t 3v,and SDA ,SCL and INT will be connected to the Arduino,i run the code in the computer,but it didn't work. When i connect it to 3.3v pin of the Arduino and it works again.Can anyone know the reason? In the Datasheet it says mpu6050 can work between 2.4v-3.4v. Thanks
  13. Hi, everyone, I'm making a college project that consists in a quadcopter with Arduino. I'm trying to use MPU-6050 to balance it. I've already read about this sensor and done a complementary filter to combine the effects of the accelerometer and gyroscope. It worked nicely, and I'm using Processing to manage it. However, I still have no idea about how to use this combinated data to balance the quadcopter's motors. I've tried to do a simple test: if the quadcopter inclines at least 15 degrees to some side, motor(s) of the opposite side stops. This is a very bad solution, of course. Also, as the quadcopter vibrates, the MPU's accelerometer vibrates too, forcing the combinated data (angle of MPU) to be very different from the real angle. I found lot of stuff about making a filter, but couldn't find much stuff about balancing a quadcopter with MPU. So, I would appreciate every single help! Sorry about my English, this is not my natural language. Thanks!
  14. Hi guys, I'm interfacing the mpu6050 with Tiva C arm cortex m4 basesd launchpad "TM4C123GH6PM" I setup up the configuration of the IMU and when I ran I got a weird behavior from PITCH and ROLL readings. The vales should always read zero when leveled up.. but after every 4 or 5 outputs they go high. Roll : 82.890320 Pitch : 44.777519 Roll : 0.119266 Pitch : 82.930687 Roll : 0.070139 Pitch : 82.928864 Roll : 82.983780 Pitch : 44.805222 Roll : 0.049558 Pitch : 0.063718 Roll : 82.967545 Pitch : 0.014765 Roll : 82.964287 Pitch : 44.801392 Roll : 0.035360 Pitch : 82.988754 Roll : 0.035095 Pitch : 82.937157 Roll : 0.042208 Pitch : 82.950836 Roll : 0.161359 Pitch : 0.014031 Roll : 82.955894 Pitch : 0.002605 Roll : 0.021050 Pitch : 82.933815
  15. Greetings, My project requires connecting multiple MPU sensors and sending all rotation data to comp using USB. I have the single sensor code working absolutely fine. Now i am hooking up 2 sensors. Idea is : Tie together the SDA, SCL, Vcc, GND and INT lines of both MPUs together. Connect the AD0 pins of MPUs to different Arduino pins. Declare only 1 MPU6050 object (as given by jeff rowberg) with devAddr = 0x69 (I dont want to maintain X no. of object for X no. of sensors. My project going ahead may need 8+ sensors and i don't want to have 8+ MPU objects in my Arduino) Whenever any sensor needs to be Init / Read / Written to, enable that sensor by writing HIGH to AD0 pin, and writing LOW on all other AD0 pins of other sensors. Once the particular sensor has been enabled, i use the normal mpu functions from my MPU6050 object which have been provided by Jeff. Now while initializing, i enable sensor 1, call mpu.initialize, testconn, dmpInit.... etc... , then i enable sensor 2, and do the same. Same method is followed to collect data from all sensors. Problem is, only Sensor 2 gives valid output. Sensor 1 gives corrupt values. I debugged the problem a little bit, it seems only the sensor which i initalize the last (sensor 2 in above case) gives valid values. I first thought that when i init the second sensor using the single mpu object, it overwrites some SW vars in this object that were previously set by first sensor. Then when i try to access the Sensor 1 with this object, these overwritten values cause problems and arduino ends up reading garbage. However i went through the whole MPU library to see if there are any private / public vars that are MPU specific and that Jeff's code might be saving. but i found nothing. It seems almost all the seful function straightaway call I2CDev Read/WriteBit. This implies as long as the correct device's AD0 is HIGH, and MPU's SW object's devAddr = 0x69, everything should work fine. And yet it does not. Can someone help ? Thanks
  16. Hi, I have a quick question regarding the FIFO of MPU6050. Using Arduino Uno, I read six raw signals from accelerometer and gyroscope using FIFO. Arduino checks the number of bytes in FIFO periodically (roughly at around 1ms), and when the FIFO has more than 36 bytes (i.e., three samples), it reads in those 36 bytes of raw data from FIFO. (no interrupt for this) Problem is, one or two bytes at the beginning of the 36-byte packet simply disappear from time to time even when there happens no FIFO overflow, and because of this, it is almost impossible to use the data reliably for waveform display on a tablet. Is there any good way to prevent this kind of problem? Your help will be greatly appreciated. Thanks.
  17. Hello, I am trying to use both an MPU6050 IMU and an I2CXL-MaxSonar-EZ ultrasonic range sensor on a single Arduino board in order to send data to ROS. I am attempting to make a MaxSonar driver using I2Cdevlib as it the MPU code is far more difficult to change. The problem I am running into is that the datasheet (http://www.maxbotix.com/documents/I2CXL-MaxSonar-EZ_Datasheet.pdf) doesn't have a full register map. I have the device ID and data I need to send to the sonar to tell it to take a range measurement, but it doesn't give the register address to send the data to. Has anyone else tried doing this? Am I missing something somewhere? Any help is appreciated. Thanks
  18. Hello, I'm doing a quadcopter using an Arduino Due with a mpu6050 (GY 521). Basically everything works very well but not always. Here comes the problem. Sometimes Arduino DUE cant connect to mpu6050 over I2C. Sometimes it can and after restart the arduino DUE it again cant connect. Afterwards I have to power off arduino DUE and then power it again on. Then it works. I'm using pins 20 and 21 for SDA and SCL and then using pin 10 as interrup doing the digitalPinToInterrupt() thing. I'm using the famous Jeff rowberg DMP_MPU6050 example, First time I upload the code it usually work but if I reset the Arduino the next error appear: Initializing I2C devices... Testing device connections... MPU6050 connection failed Send any character to begin DMP programming and demo: Initializing DMP... DMP Initialization failed (code 1) Thank you for your answers
  19. Hello i post my mpu6050 in board and want to now when i tap in the board the distance between the zone of tap and the mpu ?
  20. Hello i post my mpu6050 in board and want to now when i tap in the board the distance between the zone of tap and the mpu ?
  21. Hello everyone! I don't know if this is the proper place to ask, so i apologies if it is not!. I am using the MPU6050 and when i read the values using the DMP (yaw, pitch and roll), i notice that when i move the MPU6050 in a "yawing" manner, the pitch changes briefly then changes back when i stop yawing. Has anyone experienced this? Any intuition on what is causing this? The Arduino board i am using is Intel Edison with Arduino Kit, Library is MPU6050 built on I2CDev. Note that the pitch and roll are pretty consistent, they do what they are supposed to do. The only issue is with the yaw changing the roll for some reason...
  22. Hi, I'm currently using mpu6050 DMP for INS along with dsPIC. I have a doubt regarding the registers in mpu6050. 0x6d, e, f registers are not given the data sheet but it's used in the code. I got the code from https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050 Plz anyone tell me about this. I'm also having trouble to get dmpMemory to verify. I'm not getting the values same as dmpMemory when it's read back. Thanks
  23. Helllo, I am a new user in Arduino. Actually, I am trying to get faminlar with a MPU6050 sensor (type GY 521). I am following the tuatorial here http://playground.arduino.cc/Main/MPU-6050#info and using the libraries here https://github.com/jrowberg/i2cdevlib/tree/master/Arduino Unfortunately, the sample code doesn't work, I can not get any infomation from the sensor. The serial monitor shows only one line "Initializing I2C devices..." and nothing more (please take a look to the attached image) I am using an Arduino Mega ADK board, maybe the sample code does not supports this board? Could any one, pleasem tell me what is the problem, and how to fix it. Thank you!
  24. Hi all, thanks in advance for reading. I am interfacing the PIC32MX320F128H with the MPU6050 over I2C. For some reason my program hangs when I try to initiate a start condition through I2C using plib. More specifically, when I call I2CGetStatus, the I2C_STATUS never returns I2C_START. Without changing the program on the microcontroller, I can get the program to work by doing a hack I've discovered. I unplug my microcontroller from power, I hold the reset button on the microcontroller, plug in the power, and release the reset button, and then my program runs fine. I get values from my accelerometer and gyroscope on the device. But then after reading from the device, I try to initiate a stop condition with I2CStop, but I get no I2C_STOP condition when I call I2CGetStatus afterwards. So I'm starting to think my original issue is related to my issue I get even when I use my workaround. I'm using the MPU6050 from sparkfun. https://www.sparkfun.com/products/11028 My schematic is very simple. VDD - 3.3v from microcontroller GND - GND from microcontroller SCL - A5 SDA - A4 VIO - 3.3v from microcontroller I have been looking at the power on procedure as listed on page 23 of 52 on the datasheet. https://www.cdiweb.com/datasheets/invensense/MPU-6050_DataSheet_V3%204.pdf I have hooked up my VDD and VIO lines to the oscilloscope, and I have looked at both cases when I use my workaround and normal power up, I don't see anything different, so I am very lost. I have successfully been able to interface and use the HMC5883L so I know how I2C works, and I know my I2C library works. But here is my code anyway. main.c #include "xc.h" #include <stdio.h> #include "serial.h" #include "BOARD.h" #include "IO_Ports.h" #include "I2Cpic32.h" #include <plib.h> #define SYS_CLOCK 80000000 #define SLV_CLOCK 400000 #define SLV_ADDR 0x68 #define DELAY(x) for (wait = 0; wait <= x; wait++) {asm("nop");} #define A_BIT 183000 #define A_LOT 18300000 int wait; int main(void) { int p_size, id; UINT32 actualClock; UINT8 packet[10], read_data[14]; uint8_t powerManagementReg; INT16 AcX, AcY, AcZ, GyX, GyY, GyZ, temp; // temp is temperature I2C_7_BIT_ADDRESS slave7BitAddress; DELAY(A_BIT); BOARD_Init(); printf("Board initialized\n"); DELAY(A_LOT); actualClock = I2CSetFrequency(I2C1, SYS_CLOCK, SLV_CLOCK); if ( abs(actualClock-SLV_CLOCK) > SLV_CLOCK/10 ) printf("Error: I2C1 clock frequency (%u) error exceeds 10%%.\n", (unsigned)actualClock); printf("Clock set: %u\n", actualClock); I2CEnable(I2C1, TRUE); printf("I2C Enabled\n"); DELAY(A_LOT); I2C_FORMAT_7_BIT_ADDRESS(slave7BitAddress, SLV_ADDR, I2C_WRITE); DELAY(A_BIT); // wakes up the MPU packet[0] = slave7BitAddress.byte; packet[1] = 0x6b; packet[2] = 0x00; p_size = 3; send_packet(packet, p_size); // gyro config packet[1] = 0x1b; packet[2] = 0x08; send_packet(packet, p_size); // sample rate config packet[1] = 0x19; packet[2] = 0x07; send_packet(packet, p_size); DELAY(A_LOT); for (; { I2C_FORMAT_7_BIT_ADDRESS(slave7BitAddress, SLV_ADDR, I2C_WRITE); packet[0] = slave7BitAddress.byte; packet[1] = 0x3b; p_size = 2; send_packet(packet, p_size); StartTransfer(FALSE); I2C_FORMAT_7_BIT_ADDRESS(slave7BitAddress, SLV_ADDR, I2C_READ); TransmitOneByte(slave7BitAddress.byte); read_data[0] = read_byte(I2C1); // ACCEL_XOUT[15:8] read_data[1] = read_byte(I2C1); // ACCEL_XOUT[7:0] read_data[2] = read_byte(I2C1); // ACCEL_YOUT[15:8] read_data[3] = read_byte(I2C1); // ACCEL_YOUT[7:0] read_data[4] = read_byte(I2C1); // ACCEL_ZOUT[15:8] read_data[5] = read_byte(I2C1); // ACCEL_ZOUT[7:0] read_data[6] = read_byte(I2C1); // TEMP_OUT[15:8] read_data[7] = read_byte(I2C1); // TEMP_OUT[7:0] read_data[8] = read_byte(I2C1); // GYRO_XOUT[15:8] read_data[9] = read_byte(I2C1); // GYRO_XOUT[7:0] read_data[10] = read_byte(I2C1); // GYRO_YOUT[15:8] read_data[11] = read_byte(I2C1); // GYRO_YOUT[7:0] read_data[12] = read_byte(I2C1); // GYRO_ZOUT[15:8] read_data[13] = read_byte(I2C1); // GYRO_ZOUT[7:0] AcX = (read_data[0] << 8) | read_data[1]; AcY = (read_data[2] << 8) | read_data[3]; AcZ = (read_data[4] << 8) | read_data[5]; temp = (read_data[6] << 8) | read_data[7]; GyX = (read_data[8] << 8) | read_data[9]; GyY = (read_data[10] << 8) | read_data[11]; GyZ = (read_data[12] << 8) | read_data[13]; printf("AcX: %d\n", AcX); printf("AcY: %d\n", AcY); printf("AcZ: %d\n", AcZ); printf("temp: %d\n", temp); printf("GyX: %d\n", GyX); printf("GyY: %d\n", GyY); printf("GyZ: %d\n", GyZ); check_status(I2C1); StopTransfer(); DELAY(A_LOT); } return 0; } I2Cpic32.c // Standard headers #include <stdbool.h> #include <stdint.h> // Microchip headers #include <xc.h> #include <plib.h> // User headers #include "I2Cpic32.h" BOOL ret; I2C_RESULT res; BOOL StartTransfer( BOOL restart ) { I2C_STATUS status; // Send the Start (or Restart) signal if(restart) { I2CRepeatStart(I2C1); } else { // Wait for the bus to be idle, then start the transfer while( !I2CBusIsIdle(I2C1) ); if(I2CStart(I2C1) != I2C_SUCCESS) { printf("Error: Bus collision during transfer Start\n"); return FALSE; } } // Wait for the signal to complete do { status = I2CGetStatus(I2C1); } while ( !(status & I2C_START) ); return TRUE; } BOOL TransmitOneByte( UINT8 data ) { // Wait for the transmitter to be ready while(!I2CTransmitterIsReady(I2C1)); // Transmit the byte if(I2CSendByte(I2C1, data) == I2C_MASTER_BUS_COLLISION) { printf("Error: I2C Master Bus Collision\n"); return FALSE; } // Wait for the transmission to finish while(!I2CTransmissionHasCompleted(I2C1)); return TRUE; } void StopTransfer( void ) { I2C_STATUS status; // Send the Stop signal I2CStop(I2C1); // Wait for the signal to complete do { status = I2CGetStatus(I2C1); printf("asuh\n"); } while ( !(status & I2C_STOP) ); } void check_status(I2C_MODULE id) { I2C_STATUS stat = I2CGetStatus(id); if (stat&I2C_TRANSMITTER_FULL) printf("check_status: I2C_TRANSMITTER_FULL\n"); if (stat&I2C_DATA_AVAILABLE) printf("check_status: I2C_DATA_AVAILABLE\n"); if (stat&I2C_SLAVE_READ) printf("check_status: I2C_SLAVE_READ\n"); if (stat&I2C_START) printf("check_status: I2C_START\n"); if (stat&I2C_STOP) printf("check_status: I2C_STOP\n"); if (stat&I2C_SLAVE_DATA) printf("check_status: I2C_SLAVE_DATA\n"); if (stat&I2C_RECEIVER_OVERFLOW) printf("check_status: I2C_RECEIVER_OVERFLOW\n"); if (stat&I2C_TRANSMITTER_OVERFLOW) printf("check_status: I2C_TRANSMITTER_OVERFLOW\n"); if (stat&I2C_10BIT_ADDRESS) printf("check_status: I2C_10BIT_ADDRESS\n"); if (stat&I2C_GENERAL_CALL) printf("check_status: I2C_GENERAL_CALL\n"); if (stat&I2C_ARBITRATION_LOSS) printf("check_status: I2C_ARBITRATION_LOSS\n"); if (stat&I2C_TRANSMITTER_BUSY) printf("check_status: I2C_TRANSMITTER_BUSY\n"); if (stat&I2C_BYTE_ACKNOWLEDGED) printf("check_status: I2C_BYTE_ACKNOWLEDGED\n"); } BYTE read_byte(I2C_MODULE id) { BYTE val; ret = I2CReceiverEnable(I2C1, TRUE); //printf("I2CReceiverEnable(I2C1, TRUE): %d\n", ret); while(!(ret = I2CReceivedDataIsAvailable(I2C1))); ret = I2CReceivedDataIsAvailable(I2C1); //printf("I2CReceivedDataIsAvailable(I2C1): %d\n", ret); I2CAcknowledgeByte(I2C1, TRUE); val = I2CGetByte(id); //printf("val: %x\n", val); while(!(ret = I2CAcknowledgeHasCompleted(I2C1))); //printf("I2CAcknowledgeHasCompleted(I2C1): %d\n", ret); return val; } void send_packet(UINT8 data[], int size) { int i; // Start transfer ret = StartTransfer(FALSE); //printf("StartTransfer(FALSE): %d\n", ret); for (i = 0; i < size; i++) { ret = TransmitOneByte(data[i]); //printf("TransmitOneByte(%x): %d\n", data[i], ret); ret = I2CByteWasAcknowledged(I2C1); //printf("I2CByteWasAcknowledged(I2C1): %d\n", ret); } // Stop transfer StopTransfer(); } uint8_t I2C_ReadReg(uint8_t address, uint8_t reg) { uint8_t val; printf("asuh\n"); StartTransfer(FALSE); ret = TransmitOneByte(address << 1); printf("TransmitOneByte(%x): %d\n", (address << 1), ret); ret = I2CByteWasAcknowledged(I2C1); printf("I2CByteWasAcknowledged(I2C1): %d\n", ret); ret = TransmitOneByte(reg); printf("TransmitOneByte(%x): %d\n", reg, ret); ret = I2CByteWasAcknowledged(I2C1); printf("I2CByteWasAcknowledged(I2C1): %d\n", ret); StartTransfer(TRUE); ret = TransmitOneByte((address << 1) + 1); printf("TransmitOneByte(%x): %d\n", ((address << 1) + 1), ret); ret = I2CReceiverEnable(I2C1, TRUE); printf("I2CReceiverEnable(I2C1, TRUE): %d\n", ret); while(!(ret = I2CReceivedDataIsAvailable(I2C1))); ret = I2CReceivedDataIsAvailable(I2C1); val = I2CGetByte(I2C1); printf("val: %x\n", val); StopTransfer(); return val; } int16_t I2C_ReadReg16(uint8_t address, uint8_t reg) { int16_t val; StartTransfer(FALSE); ret = TransmitOneByte(address << 1); printf("TransmitOneByte(%x): %d\n", (address << 1), ret); ret = I2CByteWasAcknowledged(I2C1); //printf("I2CByteWasAcknowledged(I2C1): %d\n", ret); ret = TransmitOneByte(reg); printf("TransmitOneByte(%x): %d\n", reg, ret); ret = I2CByteWasAcknowledged(I2C1); //printf("I2CByteWasAcknowledged(I2C1): %d\n", ret); StartTransfer(TRUE); ret = TransmitOneByte((address << 1) + 1); printf("TransmitOneByte(%x): %d\n", ((address << 1) + 1), ret); ret = I2CReceiverEnable(I2C1, TRUE); //printf("I2CReceiverEnable(I2C1, TRUE): %d\n", ret); while(!(ret = I2CReceivedDataIsAvailable(I2C1))); ret = I2CReceivedDataIsAvailable(I2C1); val = I2CGetByte(I2C1) << 8; ret = I2CReceiverEnable(I2C1, TRUE); //printf("I2CReceiverEnable(I2C1, TRUE): %d\n", ret); while(!(ret = I2CReceivedDataIsAvailable(I2C1))); ret = I2CReceivedDataIsAvailable(I2C1); val |= I2CGetByte(I2C1); printf("val: %x\n", val); StopTransfer(); return val; } void I2C_WriteReg(UINT8 address, UINT8 reg, UINT8 val) { // Start transfer ret = StartTransfer(FALSE); //printf("StartTransfer(FALSE): %d\n", ret); ret = TransmitOneByte(address); //printf("TransmitOneByte(%x): %d\n", address, ret); ret = I2CByteWasAcknowledged(I2C1); //printf("I2CByteWasAcknowledged(I2C1): %d\n", ret); ret = TransmitOneByte(reg); //printf("TransmitOneByte(%x): %d\n", reg, ret); ret = I2CByteWasAcknowledged(I2C1); //printf("I2CByteWasAcknowledged(I2C1): %d\n", ret); ret = TransmitOneByte(val); //printf("TransmitOneByte(%x): %d\n", val, ret); ret = I2CByteWasAcknowledged(I2C1); //printf("I2CByteWasAcknowledged(I2C1): %d\n", ret); // Stop transfer StopTransfer(); }
  25. I am trying to implement the MPU6050 on the NavSpark Platform. The I2C is slightly different which is no big deal to handle. The big issue is PROGMEM can not be used. It is suggested to use something this this "const double tmp[10000] =" Any suggestions on how to implement MPU6050 within this library structure for the NavSpark Platform? Thanks Bruce
×
×
  • Create New...