MPU-6050 on I2C freezes arduino
hi everyone,
i don't know if i'm on right section hope so. have been building custom steering wheel play racing simulation games on pc using arduino mega 2560 , megajoy library. due complications needed move steering axis on board (an arduino uno r3) , works taking analog value of potentiometer (on pin a0) , acceleration on y axis mpu-6050 (on dedicated sda , scl of uno), mapping them in 0-1024 range. problem comes when start using i2c on uno. using on mega gave no problems on reading itself, when move sda , scl pins on uno code freezes , never recovers back. whole code long (always enough memory available tho) , i'm not gonna post because nobody read it, problem comes basic test code:
after few seconds , measurements (from 10 700) freezes. i've tried using watchdog kicks in project (you can notice stop on data stream , while racing isn't because can't control car, need better solution.
thanks in advance answer.
(sorry if english not best
)
i don't know if i'm on right section hope so. have been building custom steering wheel play racing simulation games on pc using arduino mega 2560 , megajoy library. due complications needed move steering axis on board (an arduino uno r3) , works taking analog value of potentiometer (on pin a0) , acceleration on y axis mpu-6050 (on dedicated sda , scl of uno), mapping them in 0-1024 range. problem comes when start using i2c on uno. using on mega gave no problems on reading itself, when move sda , scl pins on uno code freezes , never recovers back. whole code long (always enough memory available tho) , i'm not gonna post because nobody read it, problem comes basic test code:
code: [select]
#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("accelerometer: ");
serial.print("x = "); serial.print(acx);
serial.print(" | y = "); serial.print(acy);
serial.print(" | z = "); serial.println(acz);
//equation temperature in degrees c datasheet
serial.print("temperature: "); serial.print(tmp/340.00+36.53); serial.println(" c ");
serial.print("gyroscope: ");
serial.print("x = "); serial.print(gyx);
serial.print(" | y = "); serial.print(gyy);
serial.print(" | z = "); serial.println(gyz);
serial.println(" ");
delay(333);
}
after few seconds , measurements (from 10 700) freezes. i've tried using watchdog kicks in project (you can notice stop on data stream , while racing isn't because can't control car, need better solution.
thanks in advance answer.
(sorry if english not best

up
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > MPU-6050 on I2C freezes arduino
arduino
Comments
Post a Comment