I2C scan with Micropython and NodeMCU 12E returns empty list

1.7k views Asked by At

I'm trying to hook up a MPU6050 with my NodeMCU board with Micropython flashed in it.

My current wiring is the following:

MPU6050      Board
Vcc          3.3v
Gnd          Gnd
SDA          D6
SCL          D7

Through the command line, I've tried the following commands:

>>> from machine import Pin, I2C
>>> i2c = I2C(sda=Pin(12),scl=Pin(13))
>>> i2c.scan()
[]
>>>

12 and 13 were the GPIO values that I took from this pinout and I've also tried with the D1 and D2 pins as many people online do.

Although I plan to use a premade module for reading the MPU6050 values, I would have liked to see this by myself (the pre-made modules seem too overwhelming, so I wanted to see if I could do something by myself).

I'm getting quite crazy because everything seems fine to me (according to other people's wiring seen online too).

As always, thanks in advance!

2

There are 2 answers

0
magicleon94 On BEST ANSWER

Turns out the code was right and the cause was a faulty contact in the breadboard.

0
Alfonso On

Just in case someone else runs into this problem: After fighting for hours trying to get a NodeMCU work with a MCP23017 on micropython and getting the empty i2c.scan() I noticed that the problem is that for some reason micropython does not like using D1 & D2 (it does work when I test the same hardware configuration on arduino). Just use the following wiring for SDA and SCL in addition to the suggested wiring for the chip and you should be fine:

SDA: D6
SCL: D7

you should get:

>>> i2c = machine.I2C(scl=machine.Pin(13), sda=machine.Pin(12))
>>> i2c.scan()
[32]