insayne
February 21, 2025, 4:39am
1
Hi, I'm pretty new to this stuff and I'm following a tutorial that uses the MPU6050 and a Nano (Lavfin clone). Usually in my programs Serial.print works fine, but it doesn't in this case. I'm using the basicMPU6050 Library, specifically the Output example.
/*
Get scaled and calibrated output of MPU6050
*/
#include <basicMPU6050.h>
// Create instance
basicMPU6050<> imu;
void setup() {
// Set registers - Always required
imu.setup();
// Initial calibration of gyro
imu.setBias();
// Start console
Serial.begin(38400);
}
void loop() {
// Update gyro calibration
imu.updateBias();
//-- Scaled and calibrated output:
// Accel
Serial.print( imu.ax() );
Serial.print( " " );
Serial.print( imu.ay() );
Serial.print( " " );
Serial.print( imu.az() );
Serial.print( " " );
// Gyro
Serial.print( imu.gx() );
Serial.print( " " );
Serial.print( imu.gy() );
Serial.print( " " );
Serial.print( imu.gz() );
Serial.print( " " );
// Temp
Serial.print( imu.temp() );
Serial.println();
}
I'm not changing any code, and when I upload to my Nano, nothing shows up on the serial monitor.
Another thing is that when I comment out all of the imu stuff from this example and put in some random Serial.print stuff, it works fine.
I'm really struggling to find the root of the problem because I've tried 2 different parts for both the nano and the MPU and triple checked that my connections were correct.
This is what my setup looks like, pretty simple:
This could be as simple as installing some random driver that I don't know about so any tips are appreciated!
TL;DR: Serial.print works except for when I'm using my MPU6050 and nothing shows up. I don't know where to start to fix this.
You might want to look at this How to get the best out of this forum before you proceed any further.
We only know what you tell us, and without knowing what you have, we don't stand a chance.
So you need to post your code (in code tags), post a schematic of your wiring, and maybe post a good image of your hardware.
1 Like
insayne
February 21, 2025, 5:23am
3
Yeah, I edited the original post to include more info
Vin on the Nano is not an output. So you can't power your MPU from that.
2 Likes
Yikes, that regulator is not going to be happy about having 5V being sent backwards through it.
insayne
February 21, 2025, 5:06pm
6
Ok, I changed the wiring and now I'm using the basic_readings example from Adafruit's MPU6050 library:
// Basic demo for accelerometer readings from Adafruit MPU6050
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
void setup(void) {
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MPU6050 test!");
// Try to initialize!
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
Serial.print("Accelerometer range set to: ");
switch (mpu.getAccelerometerRange()) {
case MPU6050_RANGE_2_G:
Serial.println("+-2G");
break;
case MPU6050_RANGE_4_G:
Serial.println("+-4G");
break;
case MPU6050_RANGE_8_G:
Serial.println("+-8G");
break;
case MPU6050_RANGE_16_G:
Serial.println("+-16G");
break;
}
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.print("Gyro range set to: ");
switch (mpu.getGyroRange()) {
case MPU6050_RANGE_250_DEG:
Serial.println("+- 250 deg/s");
break;
case MPU6050_RANGE_500_DEG:
Serial.println("+- 500 deg/s");
break;
case MPU6050_RANGE_1000_DEG:
Serial.println("+- 1000 deg/s");
break;
case MPU6050_RANGE_2000_DEG:
Serial.println("+- 2000 deg/s");
break;
}
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.print("Filter bandwidth set to: ");
switch (mpu.getFilterBandwidth()) {
case MPU6050_BAND_260_HZ:
Serial.println("260 Hz");
break;
case MPU6050_BAND_184_HZ:
Serial.println("184 Hz");
break;
case MPU6050_BAND_94_HZ:
Serial.println("94 Hz");
break;
case MPU6050_BAND_44_HZ:
Serial.println("44 Hz");
break;
case MPU6050_BAND_21_HZ:
Serial.println("21 Hz");
break;
case MPU6050_BAND_10_HZ:
Serial.println("10 Hz");
break;
case MPU6050_BAND_5_HZ:
Serial.println("5 Hz");
break;
}
Serial.println("");
delay(100);
}
void loop() {
/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
/* Print out the values */
Serial.print("Acceleration X: ");
Serial.print(a.acceleration.x);
Serial.print(", Y: ");
Serial.print(a.acceleration.y);
Serial.print(", Z: ");
Serial.print(a.acceleration.z);
Serial.println(" m/s^2");
Serial.print("Rotation X: ");
Serial.print(g.gyro.x);
Serial.print(", Y: ");
Serial.print(g.gyro.y);
Serial.print(", Z: ");
Serial.print(g.gyro.z);
Serial.println(" rad/s");
Serial.print("Temperature: ");
Serial.print(temp.temperature);
Serial.println(" degC");
Serial.println("");
delay(500);
}
Now, the serial monitor is printing "Adafruit MPU6050 test!" and nothing else.
Run the Arduino I2C address scanner program to see if the correct I2C address is printed. If not, I2C communications and/or the sensor are not functioning.
1 Like
insayne:
Ok, I changed the wiring
Changed, how? We can't see what you see unless you show us.
insayne
February 21, 2025, 5:26pm
9
Actually it turns out I'm just dumb. If you look hard at the image I uploaded you may notice that some pins have 2 inputs because I overlayed the MPU and the Nano.
This is my new wiring
I'm now getting the output I wanted! Thanks for the responses!
system
Closed
August 20, 2025, 5:26pm
10
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.