Print Sensor Data to ESP32 Wifi OLED

Hi everyone, I'm using a Heltec ESP32 OLED Wifi Kit. I've spent some time getting the code to this point. It's very close! I would like some help getting some angle data from an MPU6050 IMU to print on my OLED through a loop. My code is below, I haven't included the setup and other stuff as I think that's working fine:

double FramesPerSecond(double seconds)
{
  static double framesPerSecond;
  framesPerSecond = (framesPerSecond * 0.9) + (1.0 / seconds * 0.1);
  return framesPerSecond;
}

void DrawLinesAndGraphicsFrame(int val)
{
    g_OLED.clearBuffer();
    g_OLED.home(); 
    
    g_OLED.drawFrame(0, 0, g_OLED.getWidth(), g_OLED.getHeight()); // border around display

    // Draw some text into the frame 
    g_OLED.setCursor(3, g_lineHeight * 2 + 2); /
    g_OLED.print("Hello");
    g_OLED.setCursor(3, g_lineHeight * 3 + 2);
    g_OLED.printf("World"); 
    g_OLED.setCursor(3, g_lineHeight * 4 + 2);
    g_OLED.printf("%03d", val); // 

    // Send Buffer            
    g_OLED.sendBuffer(); 
}

void loop()
{
    int fps = 0;

    for (;;) // Forever loop
    {
      double dStart = millis() / 1000.0; // record the start time
      DrawLinesAndGraphicsFrame(fps);
      double dEnd = millis() / 1000.0; // record the completion time 
      fps = FramesPerSecond(dEnd - dStart); // calculate FPS rate 
    }

}

I can get the Hello, World and val printing on the OLED, but I can't seem to figure out how to get some other sensor data printing in the loop, e.g. the mpu6050.getAccX and others. I've included some code from the MPU6050 tockn library which works just fine if I check through serial monitor. But I can't seem to figure out how to display it on the OLED the same way the 'val' is.


long timer = 0;

void loop() {
  mpu6050.update();

  if(millis() - timer > 1000){
    
    Serial.println("");
    Serial.print("temp : ");Serial.println(mpu6050.getTemp());
    Serial.print("accX : ");Serial.print(mpu6050.getAccX());
    Serial.print("\taccY : ");Serial.print(mpu6050.getAccY());
    Serial.print("\taccZ : ");Serial.println(mpu6050.getAccZ());
  
    Serial.print("gyroX : ");Serial.print(mpu6050.getGyroX());
    Serial.print("\tgyroY : ");Serial.print(mpu6050.getGyroY());
    Serial.print("\tgyroZ : ");Serial.println(mpu6050.getGyroZ());
  
    Serial.print("accAngleX : ");Serial.print(mpu6050.getAccAngleX());
    Serial.print("\taccAngleY : ");Serial.println(mpu6050.getAccAngleY());
  
    Serial.print("gyroAngleX : ");Serial.print(mpu6050.getGyroAngleX());
    Serial.print("\tgyroAngleY : ");Serial.print(mpu6050.getGyroAngleY());
    Serial.print("\tgyroAngleZ : ");Serial.println(mpu6050.getGyroAngleZ());
    
    Serial.print("angleX : ");Serial.print(mpu6050.getAngleX());
    Serial.print("\tangleY : ");Serial.print(mpu6050.getAngleY());
    Serial.print("\tangleZ : ");Serial.println(mpu6050.getAngleZ());
    Serial.println("\n");
    timer = millis();
    
  }

}

Any help would really be appreciated! Thank you!

Bump

OLED displays are usually graphic, which means that the letters are made up of pixels, so to fit more text on the screen, it is necessary to use a smaller font.

You yourself show an example. What prevents you from replacing the "Hello" output with your inscriptions and the "val" variable with data from the accelerometer?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.