java - Arduino MPU6050 Sensor Not Working with Code from Arduino's Website -


i keep getting following in serial monitor on , over: acx = -1 | acy = -1 | acz = -1 | tmp = 36.53 | gyx = -1 | gyy = -1 | gyz = -1

i using following code got off http://playground.arduino.cc/main/mpu-6050#sketch:

// mpu-6050 short example sketch // arduino user johnchi // august 17, 2014 // public domain #include<wire.h> const int mpu=0x68;  // i2c address of mpu-6050 int16_t acx,acy,acz,tmp,gyx,gyy,gyz; void setup(){   wire.begin();   wire.begintransmission(mpu);   wire.write(0x6b);  // pwr_mgmt_1 register   wire.write(0);     // set 0 (wakes mpu-6050)   wire.endtransmission(true);   serial.begin(9600); } void loop(){   wire.begintransmission(mpu);   wire.write(0x3b);  // starting register 0x3b (accel_xout_h)   wire.endtransmission(false);   wire.requestfrom(mpu,14,true);  // request total of 14 registers   acx=wire.read()<<8|wire.read();  // 0x3b (accel_xout_h) & 0x3c (accel_xout_l)        acy=wire.read()<<8|wire.read();  // 0x3d (accel_yout_h) & 0x3e (accel_yout_l)   acz=wire.read()<<8|wire.read();  // 0x3f (accel_zout_h) & 0x40 (accel_zout_l)   tmp=wire.read()<<8|wire.read();  // 0x41 (temp_out_h) & 0x42 (temp_out_l)   gyx=wire.read()<<8|wire.read();  // 0x43 (gyro_xout_h) & 0x44 (gyro_xout_l)   gyy=wire.read()<<8|wire.read();  // 0x45 (gyro_yout_h) & 0x46 (gyro_yout_l)   gyz=wire.read()<<8|wire.read();  // 0x47 (gyro_zout_h) & 0x48 (gyro_zout_l)   serial.print("acx = "); serial.print(acx);   serial.print(" | acy = "); serial.print(acy);   serial.print(" | acz = "); serial.print(acz);   serial.print(" | tmp = "); serial.print(tmp/340.00+36.53);  //equation temperature in degrees c datasheet   serial.print(" | gyx = "); serial.print(gyx);   serial.print(" | gyy = "); serial.print(gyy);   serial.print(" | gyz = "); serial.println(gyz);   delay(333); } 

this wiring using: http://jamesmpoe.com/roboticswiki/images/4/45/mpu6050-arduino-uno-connections.jpg

i not know wrong.

thank help.

first of all, i'd set clock x gyroscope oscillator instead of internal oscillator (as suggested on mpu6050 datasheet), hence

wire.begintransmission(mpu); wire.write(0x6b);  // pwr_mgmt_1 register wire.write(1);     // set 1 turn on xgyro oscillator wire.endtransmission(true); 

in project, however, wrote lot more initializations... suggest to

  1. write functions write/read bit(s), byte(s) , word(s) on i2c interface, because you'll need them
  2. write functions , set important parts of registers in mpu6050
  3. write more complex functions.

examples:

// i2c interface bool i2c_writebytes(uint8_t devaddr, uint8_t regaddr, uint8_t length, uint8_t* data) {     wire.begintransmission(devaddr);     wire.write((uint8_t) regaddr); // send address      (uint8_t = 0; < length; i++)     {         wire.write((uint8_t) data[i]);     }     return (wire.endtransmission() == 0); }  // simple function int16_t mpu6050_getaccelerationx() {     i2c_readbytes(mpu6050_address, mpu6050_ra_accel_xout_h, 2, rwbuffer);     return (((int16_t)rwbuffer[0]) << 8) | rwbuffer[1]; }  // complex function void mpu6050_initialize() {     mpu6050_reset();     delay(100);     mpu6050_setclocksource(mpu6050_clock_pll_xgyro);     mpu6050_setsleepenabled(false);     mpu6050_setwakecycleenabled(false);     mpu6050_switchspienabled(false);     mpu6050_seti2cmastermodeenabled(false);     mpu6050_setfifoenabled(false);     delay(100);      mpu6050_setrate(7); // 1khz scan freq     mpu6050_setdlpfmode(mpu6050_dlpf_bw_256);     mpu6050_setfullscalegyrorange(mpu6050_gyro_fs_250);     mpu6050_setfullscaleaccelrange(mpu6050_accel_fs_2);     mpu6050_setinterruptmode(mpu6050_intmode_activehigh);     mpu6050_setinterruptdrive(mpu6050_intdrv_pushpull);     mpu6050_setinterruptlatch(mpu6050_intlatch_waitclear);     mpu6050_setinterruptlatchclear(mpu6050_intclear_anyread);     mpu6050_setfsyncinterruptenabled(0);     mpu6050_seti2cbypassenabled(0);     mpu6050_setclockoutputenabled(0);     mpu6050_setintenabled(mpu6050_interrupt_mask_data_rdy_bit); // interrupt when data ready } 

a useful resource mpu6050 registers map (you can find here).


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -