I2C error with MPU6050

General discussion about topics related to OpenMV.
Cyborg67
Posts: 2
Joined: Tue May 08, 2018 8:52 am

I2C error with MPU6050

Postby Cyborg67 » Tue May 08, 2018 9:03 am

Hi,
I currently use an OpenMV M7 with the recent firmware update for a visual/inertial odometry project.
I tried to connect a Drotek 6050MPU (slave address 0x69) using the openMV build in I2C. But when I run the an exemple code, i got an error : OSError: [Errno 110] ETIMEDOUT
So i check if my IMU is still functional on my aduino and it work with no problem...

Do you have any idea...? :?

Code: Select all

from pyb import I2C

ACCEL_XOUT0 = const(0x3B)
ACCEL_YOUT0 = const(0x3D)
ACCEL_ZOUT0 = const(0x3F)
GYRO_XOUT0 = const(0x43)
GYRO_YOUT0 = const(0x45)
GYRO_ZOUT0 = const(0x47)

# Wake up board
addr = 0x69
i2c = I2C(2)
i2c.init(I2C.MASTER)
i2c.mem_write(0x01, addr, 0x6b)

i2c.mem_write(0b00011000, addr, ACCEL_CONFIG)
i2c.mem_write(0b00011000, addr, GYRO_CONFIG)

# helper for converting 2 bytes to int.
btoi = lambda msb, lsb: (msb << 8 | lsb) if not msb & 0x80 else -(((msb ^ 255) << 8) | (lsb ^ 255) + 1)

accel_range = 16.0
accel_rate = 2048.0
gyro_range = 2000.0
gyro_rate = 16.4
accel = [0.0] * 3
gyro = [0.0] * 3

# init buffers
adata = bytearray(6)
gdata = bytearray(6)

# Start loop
while True:
    i2c.mem_read(adata, addr, ACCEL_XOUT0)
    i2c.mem_read(gdata, addr, GYRO_XOUT0)
    accel = [btoi(adata[0], adata[1])/accel_rate, btoi(adata[2], adata[3])/accel_rate, btoi(adata[4], adata[5])/accel_rate]
    gyro = [btoi(gdata[0], gdata[1])/gyro_rate, btoi(gdata[2], gdata[3])/gyro_rate, btoi(gdata[4], gdata[5])/gyro_rate]
    print('\n\n')
    print('accel: ', accel)
    print('gyro: ', gyro)
    print('\n\n')
    delay(300)
User avatar
kwagyeman
Posts: 2118
Joined: Sun May 24, 2015 2:10 pm

Re: I2C error with MPU6050

Postby kwagyeman » Wed May 09, 2018 1:10 am

Hi, was this code working previously? Also, do you have pull ups on the SDA and SCL lines?
Nyamekye,
Cyborg67
Posts: 2
Joined: Tue May 08, 2018 8:52 am

Re: I2C error with MPU6050

Postby Cyborg67 » Sun May 20, 2018 9:35 am

Hi,
I solve my problem : The drotek IMU don't work well with the power 5V output of the OpenMV. So I use an external 5.5V power source. :D
User avatar
kwagyeman
Posts: 2118
Joined: Sun May 24, 2015 2:10 pm

Re: I2C error with MPU6050

Postby kwagyeman » Mon May 21, 2018 11:48 pm

The OpenMV Cam only outputs 3.3V. It has a 5V input however. It's I/O pins are 5V tolerant so you can't easily break things.
Nyamekye,

Return to “General Topics”

Who is online

Users browsing this forum: Bing [Bot] and 3 guests