0
\$\begingroup\$

My idea was to have multiple MPU 6050 (6-DOF accelerometer) sensors connected and read by an NodeMCU. I had tested a single accelerometer on the D1, D2 pins and it worked perfectly (using the `Adafruit MPU 6050 library).

Given that multiple sensors need to communicate via different pins I now wanted to try to use different pins, such as the D0, D1 for instance.

I read the Adafruit Documentation and came to the conclusion that I might be able to use different TwoWire connections. So my code that I tried looked like:

  Wire.begin(16, 5);

  if (!mpu.begin(ßx68, &Wire, 0)) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }

given that the D0, D1 pins should correspond to the integers 16 and 5 according to the pinout schemas and according to the source code of the wire library, which specifies that the begin method sets the SDA and SCL pins if specified.

Unfortunately though, my serial prints that the chip that I connected can not be found (its powered, as confirmed by the LED...). I would really appreciate help on how to connect I2C devices on different pins! Thanks in advance!

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Just FYI, you can put 2 MPU6050 devices together on the same I2C bus by tying the AD0 pin on one of them high and the other one low. AD0 sets the LSbit of the MPU6050's I2C address. \$\endgroup\$
    – brhans
    Aug 5 at 13:17
  • \$\begingroup\$ Ah, thanks a lot this perhaps will also help. But in the end I would like to have 4-5 mpu sensors, so I will still need to sort this problem out. Do you see a reason why the above does not work? \$\endgroup\$
    – Iconstrife
    Aug 5 at 13:41
  • 1
    \$\begingroup\$ expanding on what @brhans said ... you can connect your 4 or 5 sensors and connect each AD0 pin to a different GPIO pin ... pull only one AD0 pin low at a time \$\endgroup\$
    – jsotola
    Aug 5 at 22:07
  • \$\begingroup\$ io 16 is a pin of the RTC peripheral so the access is slower. don't use it for I2C. the Wire library in esp8266 Arduino is bit banged "software I2C" so it can use pair of free io. but there is only one global Wire object in the library. \$\endgroup\$
    – Juraj
    Aug 6 at 6:09
  • \$\begingroup\$ Ok, thanks. Yeah the idea was to use the Wire library and set the objects pins every now and then to different sensors. \$\endgroup\$
    – Iconstrife
    Aug 6 at 12:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.