Hi all, I am currently trying to connect the MPU6050 GY521 to my waveshare pico LCD 1.14 that is connected to Raspberry Pi Pico and using the Arduino IDE. However, I don't understand why the i2c_scanner is not picking up the MPU6050 GY521. Currently my connections are as follows:
VCC - 3V3(OUT)
GND - GPIO28
SDA - GPIO26
SCL - GPIO27
I have attached an image that shows how it is connected. Currently, the pico is connected to the pico 1.14 LCD and the MPU6050 is connected to the pins to of the pico LCD. The MPU6050 led lights up and I tested with a multimeter as well so I know the connection should not be the issue so I am looking at the code but it is as simple as it gets already and I don't know what else is possibly stopping it from detecting the MPU6050 GY521. Below is also my code. Please let me know if there is anything I am missing out.
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
void setup()
{
Wire1.begin();
Serial.begin(115200);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire1.beginTransmission(address);
error = Wire1.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(2500); // wait 5 seconds for next scan
}
Hi, thank you for your reply. Does that mean if I connect to 5V for vcc, I would not need the pull-up resistors or is it something I need no matter what vcc I connect to?
The MPU6050 is a 3.3V device. If you wish to use it with a 5V processor, level shifters are required for SDA and SCL. (In fact, any time you mix voltage levels).
There must be pullup resistors on both the 5V and 3.3V side of the level shifters.
The Raspberry Pi Pico is not a 5V device, it is 3V3, pull ups must be used between 3V3 and the two I2C lines, clock and data. I tend to use 3K3 for this, although you can pull harder by using 1K8 resistors.
Oh I see, thank you for the reply. I checked the MPU6050 GY521 and it looks like it already has an external pull-up resistor that is 2.2kohms as shown on the 222. Does that mean I still need a pull-up resistor? Sorry, if it seems like I am missing something obvious.
Did you install the Raspberry Pi Pico via the "Boards" in the Arduino IDE, or did you install another build environment via a json file ? I assume that you have installed it via the "Boards", then you have Arduino on top of Mbed. I think that Mbed defines the pins for the I2C bus.
What is the module on the right in the photo with the black pcb ?
Suggestions
Please use the label names of the pins. Such as: GP20, GP21, GND.
Get the MPU-6050 working
Remove the display module. Use Wire and not Wire1, use GP4 for SDA and GP5 for SCL. You don't have to add extra pullup resistors. Power the MPU-6050 module with 3.3V (I hope that works, you might want to try to power it with 5V because it has a onboard voltage regulator). Run a I2C Scanner with Wire and not Wire1.
Suppose that works, then you can try Wire1. I don't know at which pins Wire1 is. I don't even know if there is a second I2C bus. If that also works, then you can add the display.
Can you just use Wire and not Wire1 or are those pins used for the display ?
such that it uses GP26 and GP27 for sda and scl wire1. I will try it out with the 5V power to see if it works. Currently, its soldered and hot glued to GP26 and GP27 hence why I am trying to use Wire1. I could try using Wire but it would have to wait for a while until i get my arduino toolkit.
I think that the default pins for the earlephilhower version are also at pin GP4 and GP5 for Wire and Wire1 is at GP26 (SDA) and GP27 (SCL).
That means you should see the sensor.
Did you know that you may pull SDA and SCL low ?
You could write a sketch that toggles SDA and SCL very slow, so you can measure them at the MPU-6050 module.
A logic analyzer is even better, I'm very fond of the LHT00SU1 in combination with PulseView/sigrok.
By slowly do you mean I should just try to make the delay longer and then keep toggling between high and low for sda and scl state? This is something I tried. The weird part is it only managed to detect the MPU once then it goes back to no i2c devices found no matter what I do. I tried running again but it did not happen.
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
int sdaState = LOW;
int sclState = LOW;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup()
{
Wire1.begin();
Wire1.setClock(50000);
Serial.begin(115200);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
for (int i = 0; i < 15; i++) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (sdaState == LOW || sclState == LOW)
{
sdaState = HIGH;
sclState = HIGH;
}
else
{
sdaState = LOW;
sclState = LOW;
}
nDevices = 0;
Serial.println(sdaState);
Wire1.beginTransmission(104);
digitalWrite(26, sdaState);
digitalWrite(27, sclState);
error = Wire1.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
Serial.print(104,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
// set the LED with the ledState of the variable:
}
}
}
I was thinking about digitalWrite() to that pin to toggle it with at least 2 seconds delay with the delay function, so you can measure the signal at the sensor module with a module.
If your I2C bus is sometimes working, can you try to power the MPU-6050 module with 5V ?
Suppose that the voltage regulator on the sensor module has a voltage drop of 1V (I don't know) then the sensor gets 2.3V. Suppose that your MPU-6050 is fake (this I know, it is a counterfeit) and does not work at a lower voltage, then it could be a explanation for what you experience.
The Raspberry Pi Pico is a very nice modern board. You could connect that to a very nice modern sensor
Your MPU-6050 is old, outdated and counterfeit, and it is on a questionable circuit board