Hello Arduino community,
I've encountered an issue with displaying data on the serial monitor and I'm hoping someone can help. I'm working with an ESP32-WROOM-32 Development Board and a GY-87 10DOF MPU6050 HMC5883L BMP180 sensor module. Despite trying different codes and adjusting the delay, nothing is displayed on the serial monitor.
Here's a brief overview of my setup:
- Components: ESP32-WROOM-32 Development Board, GY-87 10DOF MPU6050 HMC5883L BMP180 sensor module.
- Wiring Diagram:
- ESP32 to GY-87: VCC to a 3.3V output on the ESP32, GND to GND, SDA (Serial Data Line) to GPIO 21 (default SDA pin for I2C on most ESP32 boards), and SCL (Serial Clock Line) to GPIO 22 (default SCL pin for I2C).
I've included the use of BluetoothSerial, Wire, Adafruit_HMC5883_U, MPU6050, and I2Cdev libraries in my code. The setup initializes the sensors and checks for Bluetooth connection, and the loop reads sensor data and prints it over Bluetooth Serial when a connection is present. The baud rate for the serial communication is set at 115200.
Despite these settings and wiring, I receive no output on the serial monitor. Has anyone experienced a similar issue or have any suggestions on what might be wrong or what I could try next?
Thank you in advance for your help!
#include <BluetoothSerial.h>
#include <Wire.h>
#include <Adafruit_HMC5883_U.h>
#include <MPU6050.h>
#include <I2Cdev.h>
BluetoothSerial SerialBT;
bool bluetoothConnected = false;
// Initialize sensor objects
Adafruit_HMC5883_Unified mag;
MPU6050 mpu;
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32_BT"); // Bluetooth device name
Serial.println("Waiting for Bluetooth connection...");
// Initialize sensors
if (!mag.begin()) {
Serial.println("Could not find HMC5883 sensor, check wiring!");
while (1);
}
// Initialize MPU6050
Wire.begin();
mpu.initialize();
// Enable magnetometer
mag.enableAutoRange(true);
}
void loop() {
// Check Bluetooth communication
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
if (SerialBT.connected() && !bluetoothConnected) {
Serial.println("Bluetooth connected!");
bluetoothConnected = true;
}
// Read sensor data
sensors_event_t event;
// Read magnetometer data
sensors_vec_t orientation;
mag.getEvent(&event);
if (event.magnetic.x != NAN && event.magnetic.y != NAN && event.magnetic.z != NAN) {
orientation.x = event.magnetic.x;
orientation.y = event.magnetic.y;
orientation.z = event.magnetic.z;
SerialBT.print("Magnetometer Data (HMC5883L): ");
SerialBT.print(orientation.x);
SerialBT.print(", ");
SerialBT.print(orientation.y);
SerialBT.print(", ");
SerialBT.println(orientation.z);
}
// Read accelerometer and gyroscope data from MPU6050
int16_t ax, ay, az, gx, gy, gz;
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
SerialBT.print("Acceleration (MPU6050): ");
SerialBT.print(ax);
SerialBT.print(", ");
SerialBT.print(ay);
SerialBT.print(", ");
SerialBT.println(az);
SerialBT.print("Gyroscope (MPU6050): ");
SerialBT.print(gx);
SerialBT.print(", ");
SerialBT.print(gy);
SerialBT.print(", ");
SerialBT.println(gz);
delay(500); // Adjust delay as needed
}

