Revisit to - Unable to Control Baud Rate from Jun '19

Hi Everyone,

Newbie back again I’m afraid, this time I’m trying to get a MPU6050 working.
The only example code I am successful with is from Microdigisoft which works with a baud rate of 9600, and displays values on a OLED screen.
This is also used in the code line
void setup()
{
Serial.begin(9600);
I have my COM7 port set to 9600,8,1

However, I’ve tried numerous other example codes from other websites
(the latest is from Arduino | MPU6050 6-DoF Accelerometer and Gyro | Adafruit Learning System)
that all appear to use a baud rate of 115200 without success,
I’ve included monitor = 115200 in my platformio.ini file, and changed my COM7 port set to 115200,8,1
and the other code examples all start the same with:-
void setup()
{
Serial.begin(115200);
But the serial monitor always returns Failed to find MPU6050 chip, or doesn’t reply with anything?

I’d like to use these ‘other’ example files as they have more code which addresses some of the drawbacks with stabilisation and filtering of the raw values from the MPU6050.

Here is my platformio monitor output:
Warning! Ignore unknown configuration option monitor in section [env:uno]
— Terminal on COM7 | 9600 8-N-1
— Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
— More details at Redirecting...
— Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
K�␋

As you can see Terminal on COM7 | 9600 8-N-1 ‘Should’ be COM7 | 115200 8-N-1
My DeviceManager COM7 Port setting is 115200

I’m currently using an example (Test 5 so far from randomnerdtutorials) and this code is what displays the above:

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!");

What I find is if I alter the code and the .ini file and my COM7 port setting all to 9600 baud I actually get a response back, but it’s always “Failed to find MPU6050 chip”.

Many thanks in advance for help on this topic.

It told you right there that that’s not a valid config option. It’s monitor_speed, just like the documentation says.

Thanks Max,
That’s given me a better understanding of how to read the documentation :slight_smile:
However, changing the code in the .ini file replies with this.:-

— Terminal on COM7 | 115200 8-N-1
— Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
— More details at Redirecting...
— Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
Adafruit MPU6050 test!
Failed to find MPU6050 chip

and whenever I try this baud rate I always get the same result?

The serial baud rate does not influence whether the MPU6050 is found or not. You have to check your wiring to and from the MPU6050.

Hi Max,
Thank you for your help!

The wiring was correct as I have results from the Microdigisoft example working at 9600 baud.

I’ve got it working which I think will help me with the other examples I’ve found,

Here’s the code I’m using:

#include <Arduino.h>

// Basic demo for accelerometer readings from Adafruit MPU6050
// ESP32 Guide: https://RandomNerdTutorials.com/esp32-mpu-6050-accelerometer-gyroscope-arduino/
// ESP8266 Guide: https://RandomNerdTutorials.com/esp8266-nodemcu-mpu-6050-accelerometer-gyroscope-arduino/
// Arduino Guide: https://RandomNerdTutorials.com/arduino-mpu-6050-accelerometer-gyroscope/

#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <SPI.h>
#include <Wire.h>

#define I2C_ADDRESS 0x68
Adafruit_I2CDevice i2c_dev = Adafruit_I2CDevice(I2C_ADDRESS);

//const int MPU6050_addr = 0x68;

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!");
  Serial.println("I2C device register test");

  if (!i2c_dev.begin()) {
    Serial.print("Did not find device at 0x");
    Serial.println(i2c_dev.address(), HEX);
    while (1);}

  // 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_5_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(2000);
}