Jump to content
I2Cdevlib Forums

Search the Community

Showing results for tags 'i2c'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • 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


Last Updated

  • Start


Filter by number of...


  • Start





Website URL







Found 19 results

  1. I have problem with MPU6050. Approximately every 1 - 2 minutes I get the NACK on the I2C bus from the sensor. This situation arises entirely by chance. I receive NACK during read "Current FIFO buffer size" register, but after reading this register again, the device responds normally. Do not know what could be the reason?
  2. aniket_prasad

    MPU6050 calibration

    Hello guys I have been trying to get yaw values from gyro MPU6050 for my application. The application is basically to control a robot's movement with respect gyro readings. Recently I started facing some issues relating calibration of the gyro. In my code I am mapping all the values of the whole range of yaw (-180 to 180) to pwm range (0 to 200). So ideally the sensor should get calibrated every time at value 100. The situation I am facing is that it gets calibrated at 100 just 3 times out of 10. What may be the possible issue? I am attaching the code for reference. Thank you GYRO.txt
  3. Hi there, I am attempting to use an SSD1306 and a MPU6050 together. I am using the U8G2 and I2CDevlib libraries but the devices seem to be mixing each other up. The devices each work seperatly but not together and have different addresses. Does anyone know why this is happening?
  4. 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"); } } }
  5. Hello so im trying to use the code for the AD7746 chip, however it includes a file called I2Cdev.h that i don't know where to find it? could anyone help me find the file
  6. 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
  7. Hello there, I have built a balancing robot using the mpu6050 and have got it all to work well so far. Here is a picture of the setup: https://drive.google.com/open?id=0B1X3D227-XxdSUVEekFsTXU0aXM Now I am seeking to add some extra functionality to it, and implement a state space control scheme. I was originally using an Arduino Uno for everything, but now that I got encoders for the motors, and I have no more free interrupt pins on the main Uno board, I have also added a Pro-Mini to the setup. The Pro-Mini is intended to handle all the measurements and calculate the final values for the robot's horizontal position and vertical angle. With this setup, I would like to have the mpu6050, the Pro-Mini, and the Uno all connected via i2c, and only send or request data when the main Uno requires it during the loop. I got the setup working with a software serial connection between the two Arduino boards, but I wasn't happy with the speed of that setup. I've spent hours trying to get the Uno to act as a second slave device and respond to transmission events from the Pro-Mini, but I am pretty sure there are some conflicts with the DMP activities for the mpu6050. I read this post: https://www.i2cdevlib.com/forums/topic/111-arduino-example-sketch-to-read-magnetometer-while-dmp-is-on/ and tried to adapt it to set the address to that set on my Uno, but still no luck. This is the code I'm currently running on my Uno to be the receiver of the data that is sent: #include <Wire.h> void setup() { Wire.begin(0x1E); // join i2c bus with address #8 Wire.onReceive(receiveEvent); // register event Serial.begin(57600); // start serial for output } void loop() { delay(100); } // function that executes whenever data is received from master // this function is registered as an event, see setup() void receiveEvent(int howMany) { while (1 < Wire.available()) { // loop through all but the last char c = Wire.read(); // receive byte as a character Serial.print(c); // print the character } int x = Wire.read(); // receive byte as an integer Serial.println(x); // print the integer } And this is what I last tried to upload to the Pro-Mini to attempt to see anything come through on the serial monitor of the Uno: #define INTRO //#define DEBUG #define MINDEBUG //#define INCLUDESOFTWARESERIAL #define I2CDEV_SERIAL_DEBUG #include "Wire.h" #include "I2Cdev.h" #include "MPU6050_6Axis_MotionApps20.h" //#include "SoftwareSerial.h" #include <avr/wdt.h> //#include <PinChangeInt.h> // ================================================================ // === Define Timing Variables === // ================================================================ unsigned long loopTimeTotal = 0; unsigned long loopTimeTop = 0; double timeChange = 0; // ================================================================ // === Define MPU 6050 Variables === // ================================================================ MPU6050 mpu; // 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 VectorInt16 aaOffset; // [x, y, z] accel sensor measurements offset float euler[3]; // [psi, theta, phi] Euler angle container float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector //float yprOffset[] = {0, 0.0604, 0}; // [yaw, pitch, roll] offset yaw/pitch/roll container and gravity vector float yprOffset[] = {0, 0.04, 0}; //was 0.0805 int16_t gyros[3]; // [x, y, z] gyros container float ang = 0.0; //angle in radians float introAngle = 0.0; //used for intro conditions (>1.5 degrees) float tempAngle = 0.0; //used for motor speed section // ================================================================ // === Define PID Variables === // ================================================================ //float Kp = 35.332; //original float Kp = 19.79; //float Ki = 331.852; //original float Ki = 117.5682; //float Kd = 0.824; // original float Kd = .5429; float err = 0.0; // current error container float lasterr = 0.0; // previous error container float errsum = 0.0; // integral of error float derr = 0.0; // derivative of error float desAng = 0.0; // desired angle float dang = 0.0; //derivative of angle float lastAng = 0.0; //previous angle container double Vm = 0.0; //motor voltage desired void setup() { Serial.begin(57600); mpuInitializeSetup(); } void loop() { loopTimeTop = millis(); updateMeasPID(); loopTimeTotal = millis() - loopTimeTop; timeChange = (double)(loopTimeTotal / 1000.0); } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Update PID Control Variables //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void updateMeasPID(void) { lastAng = ang; //UPDATE MPU BASED VALUES fifoCount = mpu.getFIFOCount(); #ifdef DEBUG Serial.print("FIFO COUNT PID: "); Serial.println(fifoCount); #endif #ifdef MINDEBUG Serial.print("FIFO COUNT PID: "); Serial.println(fifoCount); #endif while (fifoCount < packetSize) { fifoCount = mpu.getFIFOCount(); } mpu.getFIFOBytes(fifoBuffer, packetSize); fifoCount -= packetSize; mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetGravity(&gravity, &q); mpu.dmpGetYawPitchRoll(ypr, &q, &gravity); mpu.dmpGetGyro(gyros, fifoBuffer); ang = ypr[1] - yprOffset[1]; //in radians dang = (ang - lastAng) / timeChange; //lasterr = err; err = desAng - ang; errsum += err * timeChange; errsum = constrain(errsum, -5, 5); //derr = (err - lasterr) / timeChange; //Update the desired voltage Vm = Kp * err + Ki * errsum - Kd * dang; //+Kd * derr; #ifdef MINDEBUG Serial.print("\nAngle: "); Serial.println(ang * 180 / M_PI); #endif #ifdef DEBUG //Print out all the variables just updated Serial.print("\nAngle: "); Serial.print(ang * 180 / M_PI); Serial.print("\tError: "); Serial.print(err); Serial.print("\tErrsum: "); Serial.print(errsum); Serial.print("\tderr: "); Serial.println(derr); Serial.print("timeChange: "); Serial.print(timeChange); Serial.print("\tVm: "); Serial.println(Vm); Serial.print("\n"); #endif } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // mpu6050 Initialize Function //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ void mpuInitializeSetup(void) { // Set up watchdog timer wdt_enable(WDTO_4S); //should be 4 seconds /////////////////////////////////// // initialize mpu6050/// /////////////////////////////////// // initialize device #ifdef INTRO Serial.println(F("Initializing I2C devices...")); #endif mpu.initialize(); // verify connection //Turn off watchdog timer if past this point wdt_disable(); #ifdef INTRO Serial.println(F("Testing device connections...")); #endif if (mpu.testConnection()) { #ifdef INTRO Serial.println(F("MPU6050 connection successful")); #endif } else { #ifdef INTRO Serial.println(F("MPU6050 connection failed")); #endif } // load and configure the DMP #ifdef INTRO Serial.println(F("Initializing DMP...")); #endif devStatus = mpu.dmpInitialize(); // set up in bypass mode mpu.setI2CMasterModeEnabled(0); mpu.setI2CBypassEnabled(1); Wire.beginTransmission(0x1E); Wire.write("Test"); Wire.endTransmission(); mpu.setI2CBypassEnabled(0); if (mpu.getI2CMasterModeEnabled()) { #ifdef INTRO Serial.println(F("I2C Master Mode Enabled")); #endif } else { #ifdef INTRO Serial.println(F("I2C Master Mode Not Enabled")); #endif } if (mpu.getI2CBypassEnabled()) { #ifdef INTRO Serial.println(F("Bypass Mode Enabled")); #endif } else { #ifdef INTRO Serial.println(F("Bypass Mode Not Enabled")); #endif } // make sure it worked (returns 0 if so) if (devStatus == 0) { // turn on the DMP, now that it's ready #ifdef INTRO Serial.println(F("Enabling DMP...")); #endif mpu.setDMPEnabled(true); // get expected DMP packet size for later comparison packetSize = mpu.dmpGetFIFOPacketSize(); //delay(5000); //mpu.resetFIFO(); //Initialize the angle to very high value so it trips the loop introAngle = 5; //Read data and wait for it to stabilize to between 1.5 degrees fifoCount = mpu.getFIFOCount(); while (introAngle > 90) { //delay(20); if (fifoCount >= packetSize) { mpu.getFIFOBytes(fifoBuffer, packetSize); fifoCount -= packetSize; #ifdef DEBUG Serial.print("FIFO Count:\t"); Serial.println(fifoCount); #endif mpu.dmpGetQuaternion(&q, fifoBuffer); mpu.dmpGetGravity(&gravity, &q); mpu.dmpGetYawPitchRoll(ypr, &q, &gravity); ypr[1] -= yprOffset[1]; introAngle = ypr[1] * 180 / M_PI; // degrees if (introAngle < 0) { introAngle = -introAngle; } #ifdef DEBUG Serial.print("Angle:\t"); Serial.println(introAngle); #endif } else { while (fifoCount < packetSize) { fifoCount = mpu.getFIFOCount(); #ifdef DEBUG Serial.print("fifoCount-While:\t"); Serial.println(fifoCount); #endif } //while } //else } // main while loop //set angle //Serial.print("\nSetup While Exit Value: "); //Serial.println(introAngle); ang = ypr[1]; } // if (devStatus == 0) else { // ERROR! // 1 = initial memory load failed // 2 = DMP configuration updates failed // (if it's going to break, usually the code will be 1) #ifdef INTRO Serial.print(F("DMP Initialization failed (code ")); Serial.print(devStatus); Serial.println(F(")")); #endif } } Now, the main change I added to try and test if it was working is this part that is found in the mpuInitializeSetup() function at the end of my code: // set up in bypass mode mpu.setI2CMasterModeEnabled(0); mpu.setI2CBypassEnabled(1); Wire.beginTransmission(0x1E); Wire.write("Test"); Wire.endTransmission(); mpu.setI2CBypassEnabled(0); I was hoping that by doing this, I would see the words "Test" on the serial monitor of the Uno. For the physical connections, I have the SCL and SDA lines of the Uno connected to the XCL and XDA lines of the mpu6050. The SCL and SDA lines of the mpu6050 are in turn connected to the SCL and SDA lines of the Pro-Mini. I am getting good data from the mpu6050, just not having any luck using the Uno as a slave device. If anyone has some suggestions or advice about this, it would be greatly appreciated. Thank you.
  8. 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
  9. 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...
  10. 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(); }
  11. 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; } }
  12. https://tachymoron.wordpress.com/2015/09/13/mpu6050-dmp-example-code-glitchish/
  13. 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
  14. I have mpu6050 interfaced to 8051 micro-controller. I am using this to balance my quadcopter. I googled very much but I did not find how to get value of gyro or accel, every where i found is that it was interfaced to Audrino. When I try to get the WHO_AM_I address values I get them successfully, but when I try to get the gyro values from register 0x43h it shows constantly varying values and are completely random, that is they are not rounding around any value. My question is that is there any initialization required to start getting correct value from gyro? Do I need to write some registers first so that then I could get the gyro values correctly?
  15. Hey all, I'm trying to get my MPU-9150 to work with my Arduino UNO, but when I load up the I2C scanner, it doesn't detect any devices at all. I obtained the scanner from below: http://playground.arduino.cc/Main/I2cScanner I've connected it in the following fashion: Arduino - MPU9150 3.3V - VCC GND - GND A4 - SDA A5 - SCL Digital2 - INT I haven't soldered the connections, they're in my breadboard. What could be causing the scanner to not detect any devices? Maybe the connections themselves aren't secure and I need to solder them, or maybe a faulty wire? Any help would be appreciated
  16. i imported i2cdev.h and mpu6050.h library. But it doesnt work. Help me please. Error code; MPU6050.cpp:1997:6: error: prototype for 'bool MPU6050::getMotionStatus()' does not match any in class 'MPU6050' bool MPU6050::getMotionStatus() { ^ In file included from MPU6050.cpp:37:0: C:\Users\ziya.ozcelik\Documents\Arduino\libraries\MPU6050/MPU6050.h:611:17: error: candidate is: uint8_t MPU6050::getMotionStatus() uint8_t getMotionStatus();
  17. I was testing my MPU6050 with Raspberry PI and got accelerometer(X,Y,Z) and gyroscope(X,Y,Z) data forming on registers at decentely high sample rate. Looks like I've accidently fed +5v from RPI to SDA or SCL the other day and weird things started to happen with MPU6050. Looks like gyroscope got fried. Accelerometer still respond, but at very slow rate. It changes it's value about once a second no matter what clock source I set. Gyroscope stopped responding at all and writes 0 to each axis all the time. Did my MPU6050 got fried? Looks like RPI's current is fatal for i2c?
  18. Hello Forum User, First off, thank you for taking the time to read this. Second, I require some assistance in the rewriting of the InvenSence DMP lib for the TI microcontroller for use with the Arduino Uno and MPU6050. I have managed to remove most of the syntax errors that occured when switching from .c to .cpp, and removed the TI microcontroller specific code, but I am having problems with utilizing the Wire.h twi libraries for the I2C communication (specificly writing a function to call the twi libs when the i2c_write or i2c_read functions are called.) Ideally, it would use the included Wire.h library or the i2cdev library for the i2c communication. The main reason for this rewrite is to provide the ability of the users to call all of the listed functions of the DMP. In my case, this is primarally for the Pedometer functions which are not included in other libraries, but it can be used for the other functions as well. Below is a link to the dropbox file with the original library and the modified library. https://www.dropbox.com/s/4umn96yhh5hb9gu/eMPL_Rewrite.zip?dl=0 Thank you very much for your assistance in the matter. -Amatoxin-
  19. Hi there, I have tried the GY-521 sensor on Arduino by using the guide from (http://playground.arduino.cc/Main/MPU-6050). It worked well. Can anyone guide me on how can I add another GY-512 module please? How do I define the additional sensor modules in the program? I was planning to use a total of 4 of them connected to my Arduino Uno as required in my exoskeleton project. However based on my research, I have found out that the MPU-6050 chip has a limitation where I could only connect a miximum of 2 of the sensor modules. Please help to understand the I2C communication as well.