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
And run this code but get no answer back:
id=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