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, 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!
  2. Hello all! I am running MPU 6050 example. Every time after burning arduino i see this in the com port monitor: And this waiting can last VERY long... When I delete this while loop: 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 // . // . // . } Everything works OK... No waiting at all, and I see data immediately. This is the question. Must I wait for interrupt or I can read data from MPU (mpu.dmpGetXXXXXXXX) every time I need?
  3. 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
  4. 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
  5. 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 ?
  6. 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 ?
  7. 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...
  8. 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
  9. Hi everybody... I've been working on a project recently and i need to measure the roll and pitch angles of a moving platform, but the problem is that the value of these angles starts from 0 then reaches 90, then starts to decrease again to reach 0 (positive or negative 90 degrees of course) ... what i need to do is to have this value in the range of zero to 180 (positive or negative) not from zero to 90 as it is now ... do anyone have any idea??
  10. 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!
  11. I am working on an android project using Nexus 7. My goal is to achieve 1000Hz from the accelerometer. Nexus 7 uses MPU 6050 accel. But in 0 delay its sampling rate is ~200Hz. I want to ask that in the spec sheet it says that MPU6050 can give output 1Khz. But whenever DLPF_CFG is set to 0 its bandwidth is 260Hz. I am confused in this case. What does it mean? What is the normal sample rate for MPU 6050?
  12. 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(); }
  13. 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
  14. Hello, I'm encountering problem with function given in the title of this thread. My project is based on angular velocity from the Mpu6050's gyro, but I don't seem to get smooth enough readings. What is happening: - Through first 5-10s after the power up I mostly (not always) get perfect 0.00 reading. - After the internal calibration process ends, output gets dominated by -1.00 reading mixed with the prevoius one. (so it goes radomly like: -1-1-1-10-1000-10-10-1-10...and so on). In this case I can't simply compensate the reading by adding a constant. Is there a way to smooth output value? Also, it prints with the decimals, but it doesn't use them(X.00). How to get better precision with decimals being involved(eg. X.34)? And lastly, just to make sure, are those readings given in deg/s? Why I'm not using only gyro module? Because I'll need precise angle in later development to implement cascade PID. What I have tried/done: - Changing offsets. Result: it only changes output val for those first seconds. After, as I guess, internal calibration process it always ends on reading -1 and 0's. - No external noise is involved(from motors etc.) and MPU (Gy-521) doesn't share power supply with any other device. Conection( MPU - Arduino uno): Vcc - 5v Gnd- Gnd Sda - Sda Scl - Scl AD0- 5v // only with this setup I'm avoiding random sketch hangs... so far. Int - D2 I've modified / shortened Jeff's code (I'm using multiple tab sketch). I'll be grateful for any help. Also, I want to thank you for all the information I could find on this forum. Regards, Arek // I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class using DMP (MotionApps v2.0) // 6/21/2012 by Jeff Rowberg <jeff@rowberg.net> // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib // // Changelog: // 2013-05-08 - added seamless Fastwire support // - added note about gyro calibration // 2012-06-21 - added note about Arduino 1.0.1 + Leonardo compatibility error // 2012-06-20 - improved FIFO overflow handling and simplified read process // 2012-06-19 - completely rearranged DMP initialization code and simplification // 2012-06-13 - pull gyro and accel data from FIFO packet instead of reading directly // 2012-06-09 - fix broken FIFO read sequence and change interrupt detection to RISING // 2012-06-05 - add gravity-compensated initial reference frame acceleration output // - add 3D math helper file to DMP6 example sketch // - add Euler output and Yaw/Pitch/Roll output formats // 2012-06-04 - remove accel offset clearing for better results (thanks Sungon Lee) // 2012-06-01 - fixed gyro sensitivity to be 2000 deg/sec instead of 250 // 2012-05-30 - basic DMP initialization working /* ============================================ I2Cdev device library code is placed under the MIT license Copyright (c) 2012 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_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 // class default I2C address is 0x68 // specific I2C addresses may be passed as a parameter here // AD0 low = 0x68 (default for SparkFun breakout and InvenSense evaluation board) // AD0 high = 0x69 //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 the Arduino's external interrupt #0 pin. On the Arduino Uno and Mega 2560, this is digital I/O pin 2. * ========================================================================= */ /* ========================================================================= NOTE: Arduino v1.0.1 with the Leonardo board generates a compile error when using Serial.write(buf, len). The Teapot output uses this method. The solution requires a modification to the Arduino USBAPI.h file, which is fortunately simple, but annoying. This will be fixed in the next IDE release. For more info, see these links: http://arduino.cc/forum/index.php/topic,109987.0.html http://code.google.com/p/arduino/issues/detail?id=958 * ========================================================================= */ #define OUTPUT_READABLE_YAWPITCHROLL #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 VectorFloat gravity; // [x, y, z] gravity vector float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector int16_t gyro[3]; //[x,y,z] // ================================================================ // === INTERRUPT DETECTION ROUTINE === // ================================================================ volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high void dmpDataReady() { mpuInterrupt = true; } // ================================================================ // === INITIAL SETUP === // ================================================================ bool MPU_setup() { // join I2C bus (I2Cdev library doesn't do this automatically) #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE Wire.begin(); TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz). Comment this line if having compilation difficulties with TWBR. #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); #endif // initialize serial communication // (115200 chosen because it is required for Teapot Demo output, but it's // really up to you depending on your project) while (!Serial); // wait for Leonardo enumeration, others continue immediately // NOTE: 8MHz or slower host processors, like the Teensy @ 3.3v or Ardunio // Pro Mini running at 3.3v, cannot handle this baud rate reliably due to // the baud timing being too misaligned with processor ticks. You must use // 38400 or slower in these cases, or use some kind of external separate // crystal solution for the UART timer. // initialize device Serial.println(F("Initializing I2C devices...")); mpu.initialize(); mpu.setFullScaleGyroRange(0); //set the gyro range to 250 mpu.setFullScaleAccelRange(0); //set the accelerometer sensibilty to 2g Serial.print(F("Gyro sensitivity: ")); Serial.println(mpu.getFullScaleGyroRange()); // print gyro / acc sensitivity Serial.print(F("Acc sensitivity: ")); Serial.println(mpu.getFullScaleAccelRange()); // verify connection Serial.println(F("Testing device connections...")); Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed")); // 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(-30); mpu.setYGyroOffset(-54); mpu.setZGyroOffset(-21); mpu.setXAccelOffset(-3083); mpu.setYAccelOffset(-1972); mpu.setZAccelOffset(754); // 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(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(); } 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(")")); return false; } // configure LED for output pinMode(LED_PIN, OUTPUT); return true; } // ================================================================ // === MAIN PROGRAM LOOP === // ================================================================ void MPU_loop() { // if programming failed, don't try to do anything 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 // . // . // . } // reset interrupt flag and get INT_STATUS byte mpuInterrupt = false; mpuIntStatus = mpu.getIntStatus(); // get current FIFO count fifoCount = mpu.getFIFOCount(); // check for overflow (this should never happen unless our code is too inefficient) if ((mpuIntStatus & 0x10) || 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 if (mpuIntStatus & 0x02) { // 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; #ifdef OUTPUT_READABLE_YAWPITCHROLL // display Euler angles in degrees & angular velocity from gyro mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetGyro(gyro, fifoBuffer); mpu.dmpGetGravity(&gravity, &q); mpu.dmpGetYawPitchRoll(ypr, &q, &gravity); #endif // blink LED to indicate activity blinkState = !blinkState; digitalWrite(LED_PIN, blinkState); } } double MPU_gyroX(){ return gyro[0]; }
  15. Hi All, I am New to all this arduino stuff and was wondering if I could get help/see if it is possible to make a profilograph survey device from a arduino and MPU 6050? so a profilograph in a nutshell measures the floor plan every 0.5 sec in degrees which gives you data so that you can get a reading over a said distance. so what I want to do is build a device that is self calibrating (by the click of a push button) and write the data collected from the MPU6050 to a SD card shield and also have the data displayed on a LCD screen so that I know the data is begin collected. So in theory I would need..... Push button = self Calibrating Push Button = Start and Stop SD card Shield = Data files MPU 6050 = data collection Note: the data has to be in degrees so that it will work with a spreadsheet I have and also a filter will have to be in place so it will give me acc readings and be a true plan of the floor. If anyone can give me help or guidance on this (i.e Code, set up filters and the rest) I would be very greatful. Many Thanks.
  16. Hello! I'm trying to log the acceleration measured by a MPU6050 on a GY-521 breakout board on a microSD card using a microSD shield made by Sparkfun. Because the MPU6050_DMP6 sketch from the MPU6050 library of Jeff Rowberg (also using his I2Cdev lib) and the dataLogger sketch from the SDfat library both worked very good (when runnning alone) i thought i could combine them to achieve my goal. I deleted the (for my use) unnecessary code and instead of printing the acceleration data to the serial monitor i print it to the logfile. But this is not working so great. The sketch stops working completely random. Sometimes it runs for a couple of minutes, sometimes only for a few seconds. When it freezes i have to reset the arduino and it runs again for some time. I just can't figure out what the problem is. Here is what i already tried: 1) check the connections SD shield is just put on top of the arduino MPU -> Arduino VCC -> 5V GND -> GND SCL -> Analog 5 SDA -> Analog 4 INT -> Digital 2 solder points look good 2) check memory usage don't remember the exact value but it was stable and there was enough free memory 3) a LOT of different approaches how to handle the data all with pretty much the same results, i will spare you the details because mostly it was "try and error" Here is the basic sketch i described: ///////////////////////////////////////////////////////////////////////////////// #define BUTTON_PIN 4 ///////////////////////////////////////////////////////////////////////////////// //////////////Includes, Constants and Objects for datalogging//////////////////// #include <SdFat.h> // SD chip select pin. Be sure to disable any other SPI devices such as Enet. const uint8_t chipSelect = 8; //#define LOG_ACC // Log file base name. Must be six characters or less. #define FILE_BASE_NAME "DATA" // Error messages stored in flash. #define error(msg) error_P(PSTR(msg)) // File system object. SdFat sd; // Log file. SdFile file; //Variable for collumn separation ************* char tab = ';'; ///////////////////////////////////////////////////////////////////////////////// //////////////////////Includes, Constants and Objects for MPU//////////////////// #include "I2Cdev.h" #include "MPU6050_6Axis_MotionApps20.h" //#define OUTPUT_READABLE_REALACCEL // 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 SparkFun breakout and InvenSense evaluation board) // AD0 high = 0x69 MPU6050 mpu; //MPU6050 mpu(0x69); // <-- use for AD0 high //#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' }; ///////////////////////////////////////////////////////////////////////////////// //////////////////////////////User functions///////////////////////////////////// //------------------------------------------------------------------------------ // Write data header. void writeHeader() { file.print(F("accel_X")); file.print(tab); file.print(F("accel_Y")); file.print(tab); file.print(F("accel_Z")); file.println(); } //------------------------------------------------------------------------------ // error messages void error_P(const char* msg) { sd.errorHalt_P(msg); } //------------------------------------------------------------------------------ // Interrupt detection volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high void dmpDataReady() { mpuInterrupt = true; } //------------------------------------------------------------------------------ // setup function void setup() { const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1; char fileName[13] = FILE_BASE_NAME "00.CSV"; Serial.begin(115200); //while (!Serial) {} // wait for Leonardo //delay(1000); pinMode(BUTTON_PIN, INPUT_PULLUP); Serial.println(F("Press Button to start")); while(digitalRead(BUTTON_PIN)) {} //wait for button // Initialize the SD card at SPI_HALF_SPEED to avoid bus errors with // breadboards. use SPI_FULL_SPEED for better performance. if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt(); // Find an unused file name. if (BASE_NAME_SIZE > 6) { error("FILE_BASE_NAME too long"); } while (sd.exists(fileName)) { if (fileName[BASE_NAME_SIZE + 1] != '9') { fileName[BASE_NAME_SIZE + 1]++; } else if (fileName[BASE_NAME_SIZE] != '9') { fileName[BASE_NAME_SIZE + 1] = '0'; fileName[BASE_NAME_SIZE]++; } else { error("Can't create file name"); } } if (!file.open(fileName, O_CREAT | O_WRITE | O_EXCL)) error("file.open"); do { delay(10); } while (Serial.read() >= 0); Serial.print(F("Logging to: ")); Serial.println(fileName); // Write data header. writeHeader(); // join I2C bus (I2Cdev library doesn't do this automatically) #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE Wire.begin(); TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz) #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); #endif // 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")); // 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(99); mpu.setYGyroOffset(-35); mpu.setZGyroOffset(67); mpu.setZAccelOffset(1106); // 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(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(); } 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(13, OUTPUT); } // ================================================================ // === MAIN PROGRAM LOOP === // ================================================================ void loop() { // if programming failed, don't try to do anything if (!dmpReady) return; // wait for MPU interrupt 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 // . // . // . } // reset interrupt flag and get INT_STATUS byte mpuInterrupt = false; mpuIntStatus = mpu.getIntStatus(); // get current FIFO count fifoCount = mpu.getFIFOCount(); // check for overflow (this should never happen unless our code is too inefficient) if ((mpuIntStatus & 0x10) || 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 if (mpuIntStatus & 0x02) { // 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; // get real acceleration, adjusted to remove gravity mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetAccel(&aa, fifoBuffer); mpu.dmpGetGravity(&gravity, &q); mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity); file.print(aaReal.x); file.write(tab);//*************** file.print(aaReal.y); file.write(tab);//*************** file.println(aaReal.z); // Force data to SD and update the directory entry to avoid data loss. if (!file.sync() || file.getWriteError()) Serial.println(F("write error")); if (!digitalRead(BUTTON_PIN)) { // Close file and stop. file.close(); Serial.println(F("Done")); while(1) {} } } } If you have any ideas how to solve this issue, any help will be greatly appreciated. wambo
  17. Hello I am combinig MPU6050 with Encoder for cycle simulation. But as I move the encoder very fastly it stopped automatically giving readings. I am little bit confused whats is the exact problem? My Code #define BAUDRATE 38400 //Encoder //#define pinA A1 #define ARDUINOPIN A2 #define STATE_UNINIT 0 #define STATE_INIT 1 byte systemState; volatile long count; int pinA = 2; int pinB = 3; int limitSW_1 = 4; boolean sigA = 0; boolean sigB = 0; boolean status_L1 = 0; //Ends Encoder //Start MPU #include "I2Cdev.h" #include "MPU6050_6Axis_MotionApps20.h" #include "PinChangeInt.h" #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include "Wire.h" #endif #define OUTPUT_READABLE_QUATERNION //#define OUTPUT_READABLE_YAWPITCHROLL //Ends MPU MPU6050 mpu; // MPU control/status vars bool dmpReady = false; 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 = false; // indicates whether MPU interrupt pin has gone high void dmpDataReady() { mpuInterrupt = true; } // ================================================================ // === INITIAL SETUP === // ================================================================ void setup() { // join I2C bus (I2Cdev library doesn't do this automatically) #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE Wire.begin(); TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz) #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); #endif Serial.begin(BAUDRATE); //while (!Serial); // mpu.initialize(); devStatus = mpu.dmpInitialize(); mpu.setXGyroOffset(52); mpu.setYGyroOffset(18); mpu.setZGyroOffset(-24); mpu.setZAccelOffset(1030); // 1688 factory default for my test chip if (devStatus == 0) { mpu.setDMPEnabled(true); pinMode(ARDUINOPIN, INPUT_PULLUP); // attachInterrupt(ARDUINOPIN, dmpDataReady, RISING); attachPinChangeInterrupt(ARDUINOPIN, dmpDataReady, RISING); mpuIntStatus = mpu.getIntStatus(); dmpReady = true; packetSize = mpu.dmpGetFIFOPacketSize(); } else { } systemState = STATE_UNINIT; // pinMode(pinA, INPUT_PULLUP); // attachPinChangeInterrupt(pinA, interruptA, CHANGE); // pinMode(pinB, INPUT_PULLUP); // attachPinChangeInterrupt(pinB, interruptB, CHANGE); attachInterrupt(0, interruptA, CHANGE); attachInterrupt(1, interruptB, CHANGE); } // ================================================================ // === MAIN PROGRAM LOOP === // ================================================================ void loop() { if (!dmpReady) return; while (!mpuInterrupt && fifoCount < packetSize) {} mpuInterrupt = false; mpuIntStatus = mpu.getIntStatus(); fifoCount = mpu.getFIFOCount(); if ((mpuIntStatus & 0x10) || fifoCount == 1024) { mpu.resetFIFO(); } else if (mpuIntStatus & 0x02) { while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount(); mpu.getFIFOBytes(fifoBuffer, packetSize); fifoCount -= packetSize; //YPR #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(","); // Serial.print(ypr[1] * 180/M_PI); // Serial.print(","); // Serial.println(ypr[2] * 180/M_PI); #endif //Quaternion #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(","); Serial.print(q.x); Serial.print(","); Serial.print(q.y); Serial.print(","); Serial.print(q.z); Serial.print(","); #endif Serial.print(count); Serial.print(','); Serial.print(status_L1); Serial.println(); // Stream.flush(); } status_L1 = digitalRead(limitSW_1); if (status_L1 == 1 && false) { count = 0; systemState = STATE_INIT; } // delay(50); } //interupt for PinA void interruptA() { sigA = digitalRead(pinA); switch(sigA) { case 0: if(sigB == 1) count++; else count--; break; case 1: if(sigB == 0) count++; else count--; break; } } //interupt for PinA void interruptB() { sigB = digitalRead(pinB); switch(sigB) { case 0: if(sigA == 0) count++; else count--; break; case 1: if(sigA == 1) count++; else count--; break; } }
  18. Hello I am using MPU6050 + Encoder + Switch. While running the sketch its show output in Serial monitor for some time then suddenly its stop.Please give me some suggestion asap. Code: #define BAUDRATE 9600 //Encoder #define pinA A1 #define STATE_UNINIT 0 #define STATE_INIT 1 byte systemState; volatile long count; //int pinA = 2; int pinB = 3; int limitSW_1 = 4; boolean sigA = 0; boolean sigB = 0; boolean status_L1 = 0; //Ends Encoder //Start MPU #include "I2Cdev.h" #include "MPU6050_6Axis_MotionApps20.h" #include "PinChangeInt.h" #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include "Wire.h" #endif #define OUTPUT_READABLE_QUATERNION //#define OUTPUT_READABLE_YAWPITCHROLL //Ends MPU MPU6050 mpu; // MPU control/status vars bool dmpReady = false; 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 = false; // indicates whether MPU interrupt pin has gone high void dmpDataReady() { mpuInterrupt = true; } // ================================================================ // === INITIAL SETUP === // ================================================================ void setup() { // join I2C bus (I2Cdev library doesn't do this automatically) #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE Wire.begin(); TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz) #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); #endif Serial.begin(BAUDRATE); //while (!Serial); // mpu.initialize(); devStatus = mpu.dmpInitialize(); mpu.setXGyroOffset(52); mpu.setYGyroOffset(18); mpu.setZGyroOffset(-24); mpu.setZAccelOffset(1030); // 1688 factory default for my test chip if (devStatus == 0) { mpu.setDMPEnabled(true); attachInterrupt(0, dmpDataReady, RISING); mpuIntStatus = mpu.getIntStatus(); dmpReady = true; packetSize = mpu.dmpGetFIFOPacketSize(); } else { } systemState = STATE_UNINIT; pinMode(pinA, INPUT_PULLUP); attachPinChangeInterrupt(pinA, interruptA, CHANGE); //attachInterrupt(0, interruptA, CHANGE); attachInterrupt(1, interruptB, CHANGE); } // ================================================================ // === MAIN PROGRAM LOOP === // ================================================================ void loop() { if (!dmpReady) return; while (!mpuInterrupt && fifoCount < packetSize) {} mpuInterrupt = false; mpuIntStatus = mpu.getIntStatus(); fifoCount = mpu.getFIFOCount(); if ((mpuIntStatus & 0x10) || fifoCount == 1024) { mpu.resetFIFO(); } else if (mpuIntStatus & 0x02) { while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount(); mpu.getFIFOBytes(fifoBuffer, packetSize); fifoCount -= packetSize; //YPR #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(","); // Serial.print(ypr[1] * 180/M_PI); // Serial.print(","); // Serial.println(ypr[2] * 180/M_PI); #endif //Quaternion #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(","); Serial.print(q.x); Serial.print(","); Serial.print(q.y); Serial.print(","); Serial.print(q.z); Serial.print(","); #endif Serial.print(count); Serial.print(','); Serial.print(status_L1); Serial.println(); // Stream.flush(); } status_L1 = digitalRead(limitSW_1); if (status_L1 == 1 && false) { count = 0; systemState = STATE_INIT; } // delay(50); } //interupt for PinA void interruptA() { sigA = digitalRead(pinA); switch(sigA) { case 0: if(sigB == 1) count++; else count--; break; case 1: if(sigB == 0) count++; else count--; break; } } //interupt for PinA void interruptB() { sigB = digitalRead(pinB); switch(sigB) { case 0: if(sigA == 0) count++; else count--; break; case 1: if(sigA == 1) count++; else count--; break; } }
  19. Hi, I am using MPU6050 with your written code in DMP mode on Arduino due and it's working fine stand alone.. But I have to integrate some other things into my code like (Due timer library to generate software interrupt every second, external interrupt on pin 52 to count pulses ). when i tried to integrate them in one code i have FIFO Overflow problem. even though i tried to run it at as low as 20hz by changing the registers value in the "3dmath.h" file. can you please help me out with this problem i am facing. my project is kind of stuck at this point. Thank you. #include <DueTimer.h> #include "I2Cdev.h" #include "MPU6050_6Axis_MotionApps20.h" #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include "Wire.h" #endif MPU6050 mpu; //#define OUTPUT_READABLE_WORLDACCEL #define OUTPUT_READABLE_REALACCEL #define LED_PIN 13 // (Arduino is 13, Teensy is 11, Teensy++ is 6) #define LED_PIN1 12 bool blinkState = false; bool blinkState1 = 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 double vel_data; double vel; double Dummy = 0 ; double t_s = 0; double S[2] = {0,0}; double Q[2] = {0.05,0.05}; double R[2] = {0.5, 0.01}; double Y[2] = {0,0}; double X[2] ={0,0}; double P[2] = {0.5,0.5}; double K[2] = {0, 0}; uint32_t timer = 0; uint32_t dt = 0; int16_t sample,sped=0; int16_t ax, ay, az; int16_t gx, gy, gz; int16_t sensorValue; char val; int count; bool flag; // ================================================================ // === INTERRUPT DETECTION ROUTINE === // ================================================================ volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high void dmpDataReady() { mpuInterrupt = true; } // ================================================================ // === INITIAL SETUP === // ================================================================ void setup() { // join I2C bus (I2Cdev library doesn't do this automatically) #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE Wire.begin(); Wire1.begin(); //TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz) #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); #endif Serial1.begin(115200); //115200 or 19200 while (!Serial1); // wait for Leonardo enumeration, others continue immediately Serial1.println(F("Initializing I2C devices...")); mpu.initialize(); // verify connection Serial1.println(F("Testing device connections...")); Serial1.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed")); // wait for ready // Serial1.println(F("\nSend any character to begin DMP programming and demo: ")); // while (Serial1.available() && Serial1.read()); // empty buffer // while (!Serial1.available()); // wait for data // while (Serial1.available() && Serial1.read()); // empty buffer again // load and configure the DMP Serial1.println(F("Initializing DMP...")); devStatus = mpu.dmpInitialize(); // supply your own gyro offsets here, scaled for min sensitivity mpu.setXGyroOffset(-1); //220 inc. will inc. mpu.setYGyroOffset(-24); //76 mpu.setZGyroOffset(51); //-85 mpu.setZAccelOffset(1788); // increasing number will increase 16384 // make sure it worked (returns 0 if so) if (devStatus == 0) { // turn on the DMP, now that it's ready Serial1.println(F("Enabling DMP...")); mpu.setDMPEnabled(true); // enable Arduino interrupt detection Serial1.println(F("Enabling interrupt detection (Arduino Due external interrupt 2)...")); attachInterrupt(2, dmpDataReady, RISING); mpuIntStatus = mpu.getIntStatus(); // set our DMP Ready flag so the main loop() function knows it's okay to use it Serial1.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) Serial1.print(F("DMP Initialization failed (code ")); Serial1.print(devStatus); Serial1.println(F(")")); } // configure LED for output pinMode(LED_PIN, OUTPUT); delay(5000); attachInterrupt(52, rpm_fun, FALLING); Timer.getAvailable().attachInterrupt(firstHandler).start(1000000); // from DueTimer library delay(50); } void firstHandler(){ // Software interrupt every one second. Serial1.println("int"); flag = true; } void rpm_fun() // Hardware interrupt to count external pulses. { count = count + 1; } // ================================================================ // === MAIN PROGRAM LOOP === // ================================================================ void loop() { // if programming failed, don't try to do anything 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 // . // . // . } // reset interrupt flag and get INT_STATUS byte mpuInterrupt = false; mpuIntStatus = mpu.getIntStatus(); // get current FIFO count fifoCount = mpu.getFIFOCount(); // check for overflow (this should never happen unless our code is too inefficient) if ((mpuIntStatus & 0x10) || fifoCount == 1024) { // reset so we can continue cleanly mpu.resetFIFO(); Serial1.println(F("FIFO overflow!")); // otherwise, check for DMP data ready interrupt (this should happen frequently) } else if (mpuIntStatus & 0x02) { // 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; #ifdef OUTPUT_READABLE_REALACCEL // display real acceleration, adjusted to remove gravity // -----Get data from MPU-6050----- mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetAccel(&aa, fifoBuffer); mpu.dmpGetGravity(&gravity, &q); mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity); mpu.dmpGetYawPitchRoll(ypr, &q, &gravity); sample = -(aaReal.x); //Dummy = (abs(sample)>80) ? ((double)sample/16384)*9.81 : 0; Dummy = (double)sample/16384 * 9.81; t_s = (((double)micros() - timer)/1000000); // -----Get data from Arduino UNO----- Wire1.requestFrom(2, 1); // request 1 byte from slave device #2 while(Wire1.available()) // slave may send less than requested { sped = Wire1.read(); // receive a byte as character vel_data = ( 0.85 *((double)(sped)* 0.216)) + (0.15 * X[1]); // Serial1.println(sped); // print the character } //--------Prediction------- X[0] = X[0]; // Velocity X[1] = X[1]; // Acceleration P[0] = Q[0]; P[1] = t_s * Q[1]; //-------Kalman Gain-------- S[0] = P[0] + R[0]; S[1] = P[1] + R[1]; K[0] = P[0]/S[0]; K[1] = P[1]/S[1]; //--------Update------------- //vel = vel + t_s * Dummy; Y[0] = vel_data - X[0]; Y[1] = Dummy - X[1]; // Y[1] = Dummy - X[1]; X[0] = X[0] + (K[0]*Y[0]); X[1] = X[1] + (K[1]*Y[1]); P[0] = P[0] - (K[0]*P[0]); P[1] = P[1] - (K[1]*P[1]); timer = micros(); #endif // blink LED to indicate activity blinkState = !blinkState; digitalWrite(LED_PIN, blinkState); } }
  20. Hi guys, I come here, to ask you all nice people one tricky question.But for the beginning I will describe you my project which I am working on. My project is quadcopter, but not normal one, on board should be raspberry pi and arduino due with mpu6050. 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 of arduino DUE it again cant connect. Afterwards I have to power off arduino DUE and than power it again on. Than it works. So it looks to me some problem with registers or probably as I read, it can be with pull-ups on I2C. I was trying to repair it for a month but I could not, after lot of time I am trying to contact some person or group of people who could help me. I would be happy for all kinds of help. Here I am posting also my code on github and some pics of quadcopter. https://github.com/JurajKabzan/Quadcopter Little description of my project. On pc runs ground control written in C# which generates control strings and than sends them over network connection through sockets to raspberry pi, it executes them and then when necessary sends directly over serial to arduino DUE. Arduino DUE takes care for PIDs and sensors staff. When I use example dmp from i2cdevlib it happens the same.One I can next time I can not connect. Please I will be happy for all kind of help!
  21. https://tachymoron.wordpress.com/2015/09/13/mpu6050-dmp-example-code-glitchish/
  22. well I dont have any Problem with the arduino sketch and libraries. I can read all the Information from the sensor. My question is related to the dmp integreted in the unit. Als is that mentioned in the Header file "MPU6050_6Axis_MotionApps20.h" many data will be written to different Registers at power on. if i have unterstand the Routine "dmpinitialize" at first a block of Memory will be written (the first Register in which the first Byte will be written is the Register 0x6F") and then configuration data will be written and finally "dmpupdate" data. Is there anyone who can affirm that the first Register in which the first block Memory data will be written at power on is 0x68? and i would appreciate when i got also in which adress the other data will be written? ( i have tried to find it out but until now i cannot get it) i have tried to Display the Content of some Registers from the Serial Monitor provided by arduino IDE. I have added a few line of fuctions from the library "wire" just after the line "devStatus = mpu.dmpInitialize();" My program dont do anything just initialize dmp. the Content of the Register are not equal to any of the series of data to write through the Routine "dmpinitiaze" Please help me to understand what is going!!!!! Ah why am i interested to These adress? I want to reprogramm in Assembler avr and i should These adress at first step known. I would appreciate any Help, even a Suggestion to read up to 10M Byte pdf document.
  23. I am trying to get the MPU6050 example to compile and I can't seem to do it. I am using Arduino 1.0.5 on a Windows computer. So far, I have confirmed that the I2Cdev and the MPU6050 libraries are located in C:/Program Files (x86)/Arduino/Libraries. I have included the helper_3dmath library at the top of the example sketch, but I still cannot get it to compile. There is a long list of errors, but below are a couple. This seems to be an issue with the libraries I have included. C:\Users\Randy\Documents\Arduino\libraries\MPU6050/helper_3dmath.h: In member function 'float Quaternion::getMagnitude()': C:\Users\Randy\Documents\Arduino\libraries\MPU6050/helper_3dmath.h:74: error: 'sqrt' was not declared in this scope .... and: C:\Users\Randy\Documents\Arduino\libraries\MPU6050/MPU6050_6Axis_MotionApps20.h:596: error: 'class VectorInt16' has no member named 'x' C:\Users\Randy\Documents\Arduino\libraries\MPU6050/MPU6050_6Axis_MotionApps20.h:597: error: 'class VectorInt16' has no member named 'y' Please let me know if I am missing something obvious or if you will need more information to help. Thanks.
  24. Hello everybody, We should connect two mpu6050 to an Arduino mega but we don't know how to connect them physically. We know that we have to turn the i2c adress from 0x68 to 0x69 in order to have 2 different adress, one for each sensor. Someone says that it must connect them in parallel but other thinks that it is usefull to set two digital pins high or low to "swich on/off" a sensor in order to read information alternated. moreover we would like to read quarternion or euler data but now we are only able to receive raw data. May anyone help us? thanks
  25. I've connected multiple(3 or more) MPU6050s on an I2C bus and used AD0 pin to control the chips. But after altering the AD0 pin I've to reset the chip to perform the address change. Is it possible to change the chip's address permanently without need to change the external AD0 pin? Regards
×
×
  • Create New...