Chat freely about anything...
User avatar
By Chris Scicluna
#39815 Hi All,

I read all around the place to connect ESP8266 + MPU6050 and although there are a couple of posts I tried everything and still cannot get the I2C address of the sensor.

Would love after this learning experience I would write a detailed tutorial on how to connect it, so would be really grateful if you could help me with this problem I am having.

I am using NodeMCU 1.0 + MPU6050 (GY-521) and connecting as follows:

NodeMCU - MPU6050
3.3v - VCC [I also tried VIN (5V) to VCC]
GND - GND
D4 - SCL
D3 - SDA


Image

And run this code but get no answer back:

Code: Select allid=0  -- need this to identify (software) IC2 bus?
sda=3 -- connect to pin GPIO0
scl=4 -- connect to pin GPIO2

-- initialize i2c with our id and pins in slow mode :-)
i2c.setup(id,sda,scl,i2c.SLOW)

-- user defined function: read from reg_addr content of dev_addr
function read_reg(dev_addr, reg_addr)
     i2c.start(id)
     i2c.address(id, dev_addr ,i2c.TRANSMITTER)
     i2c.write(id,reg_addr)
     i2c.stop(id)
     i2c.start(id)
     i2c.address(id, dev_addr,i2c.RECEIVER)
     c=i2c.read(id,1)
     i2c.stop(id)
     return c
end

print("Scanning I2C Bus")
for i=0,127 do
     if (string.byte(read_reg(i, 0))==0) then
     print("Device found at address "..string.format("%02X",i))
     end
end


Anyone stumbled in the same issue?

Thanks
User avatar
By hjsalom
#71819 From Arduino Playground: "Suppose all AD0 lines are default high (3.3V), so every MPU-6050 is I2C address 0x69. That I2C address is however never used ! The Arduino makes one of the AD0 lines low, and uses that sensor at I2C address 0x68. After that is finished, the Arduino selects another AD0 line, and can use that sensor.
So every sensor is used at I2C address 0x68 (one by one) and 0x69 is never used."