Description
-
Arduino board: Nano
-
Arduino IDE version (found in Arduino -> About Arduino menu): V2.3.3
-
OLED-Display with 128x64 pixels do not work together in a code with the actual Adafruit MPU6050 library V2.2.6!
The issue can be reproduced also with the example code MPU6050_oled.ino out of the library package and a 128x64 OLED-Display.
As long as in line 6 a Screen_height of "32" is declared (for OLED 128x32), the code works.
In case of changing the value to "64" for a 128x64 OLED-Display, there is no error shown during compilation progress, but after
flashing to the µC there is no longer a reaction of Display, while during executing the flashed code, the SSD3306 I2C-allocation
while executing function display.begin() failed!
=> could also be checked by the standard Serial.print errormessage out of the mpu-example-code.
Note:- Until the Adafruit MPU6050 Library V1.0.2 this issue is not reproducable.
The described issue appears only since library V2.0.0 or newer. - If other Display sizes will also not work is not tested at the moment!
- Until the Adafruit MPU6050 Library V1.0.2 this issue is not reproducable.
Copy of the Code Example from Library:
#include <Adafruit_MPU6050.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
Adafruit_MPU6050 mpu;
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire); // adjustment to 128x64 OLED-Display -> do NOT work
//Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire);
// Standard line out of code-example from the library for 128x32 OLED ->will work
If other Display sizes will also not work is not tested at the moment!
void setup() {
Serial.begin(115200);
// while (!Serial);
Serial.println("MPU6050 OLED demo");
if (!mpu.begin()) {
Serial.println("Sensor init failed");
while (1)
yield();
}
Serial.println("Found a MPU-6050 sensor");
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
Serial.println(F("SSD1306 allocation failed"));
for (;;)
; // Don't proceed, loop forever
}
display.display();
delay(500); // Pause for 2 seconds
display.setTextSize(1);
display.setTextColor(WHITE);
display.setRotation(0);
}
void loop() {
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
display.clearDisplay();
display.setCursor(0, 0);
Serial.print("Accelerometer ");
Serial.print("X: ");
Serial.print(a.acceleration.x, 1);
Serial.print(" m/s^2, ");
Serial.print("Y: ");
Serial.print(a.acceleration.y, 1);
Serial.print(" m/s^2, ");
Serial.print("Z: ");
Serial.print(a.acceleration.z, 1);
Serial.println(" m/s^2");
display.println("Accelerometer - m/s^2");
display.print(a.acceleration.x, 1);
display.print(", ");
display.print(a.acceleration.y, 1);
display.print(", ");
display.print(a.acceleration.z, 1);
display.println("");
Serial.print("Gyroscope ");
Serial.print("X: ");
Serial.print(g.gyro.x, 1);
Serial.print(" rps, ");
Serial.print("Y: ");
Serial.print(g.gyro.y, 1);
Serial.print(" rps, ");
Serial.print("Z: ");
Serial.print(g.gyro.z, 1);
Serial.println(" rps");
display.println("Gyroscope - rps");
display.print(g.gyro.x, 1);
display.print(", ");
display.print(g.gyro.y, 1);
display.print(", ");
display.print(g.gyro.z, 1);
display.println("");
display.display();
delay(100);
}
//CODE END