Skip to content
SDB
02Technology

Visualize NodeMCU-plugged MPU6050 realtime movement on OLED

NodeMCU ESP8266 + MPU6050 gyro/accelerometer with SSD1306 OLED readout, optional DHT11, InvenSense teapot packets over serial, and a Processing 3D visualiser — motion on the bench and on the screen.

Subhendu Datta Bhowmik5 min read

This project wires an MPU6050 gyro/accelerometer to a NodeMCU ESP8266, shows live status on a 0.96″ I²C OLED, optionally reads a DHT11, and streams quaternion “teapot” packets so a Processing sketch can render the board’s orientation in 3D.

NodeMCU with MPU6050 and OLED display on a breadboard
Bench setup — NodeMCU, MPU6050 and SSD1306 OLED for realtime motion feedback

Hardware

  • NodeMCU ESP8266 board
  • MPU6050 gyro / accelerometer module
  • 0.96″ I²C OLED (SSD1306, 128×64)
  • DHT11 temperature & humidity sensor (optional expansion)
  • Jumpers / breadboard

Software: Arduino IDE · Processing (+ toxiclibs) · IoT cloud hooks as needed

NodeMCU ESP8266

NodeMCU is open-source firmware paired with DIP-style prototyping boards that combine a USB interface with an ESP-12 / ESP8266 Wi-Fi SoC (Tensilica Xtensa LX106). The DIP form factor is friendly on a breadboard and common in IoT builds.

MPU6050

The MPU6050 is a MEMS package with a 3-axis accelerometer, 3-axis gyroscope, and an onboard Digital Motion Processor (DMP). 16-bit ADCs capture 3D motion; I²C talks to the MCU. Typical uses include drones, self-balancing robots and RC vehicles.

Module pins

PinRole
INTInterrupt digital output
AD0I²C address LSB (tie to VCC to flip slave address)
XCL / XDAAuxiliary I²C clock / data for other sensors
SCL / SDAPrimary I²C to the microcontroller
GND / VCCGround / supply (module often run from 5 V or 3.3 V per board design)

Gyroscope — rotational velocity about X, Y, Z.
Accelerometer — tilt / inclination about X, Y, Z.

Diagram of MPU6050 three-axis gyroscope axes
3-axis gyroscope — rotational velocity about X, Y and Z
Diagram of MPU6050 three-axis accelerometer axes
3-axis accelerometer — tilt and inclination about X, Y and Z

OLED (SSD1306 0.96″)

FeatureDetail
PanelMonochrome SSD1306, ~0.96″
Resolution128×64, wide viewing angle
Supply3 V–5 V (5 V and 3.3 V logic friendly)
BusSPI or I²C
ExtrasBitmap graphics; Arduino libraries available

Typical 7-pin mapping

#NameNotes
1GNDCircuit ground
2Vdd / Vcc3.3 V or 5 V
3SCK / SCL / D0Clock (I²C or SPI)
4SDA / MOSI / D1Data
5RES / RSTHold low briefly to reset
6DC / A0Command / data select
7CSChip select (multi-SPI)

Circuit

I²C for MPU and OLED (SCL/SDA on the NodeMCU), interrupt from MPU on D6, activity LED on D7, optional DHT11 on a digital pin. Sample and final wiring:

Sample wiring diagram for NodeMCU MPU6050 and OLED
Sample circuit — NodeMCU with MPU6050 and display
Final project circuit including DHT11 sensor
Final circuit — MPU6050, OLED and optional DHT11 on the NodeMCU

Processing visualiser

Processing is an open Java-based creative coding IDE (ancestor of ideas behind Arduino and p5.js). For the 3D orientation demo, install Processing and toxiclibs, then open a serial port to the NodeMCU (115200 baud) and parse InvenSense teapot packets into a quaternion-driven model.

Firmware outline (NodeMCU)

Core idea: initialise OLED + Wi-Fi + DHT, bring up MPU DMP, then either show connection / climate on the OLED or stream teapot packets for Processing.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
 
MPU6050 mpu;
#define OUTPUT_TEAPOT
#define INTERRUPT_PIN D6
#define LED_PIN D7
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define DHTPIN 2
#define DHTTYPE DHT11
 
DHT_Unified dht(DHTPIN, DHTTYPE);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
bool dmpReady = false;
uint8_t fifoBuffer[64];
uint8_t teapotPacket[14] = { '$', 0x02, 0,0, 0,0, 0,0, 0,0, 0x00, 0x00, '\r', '\n' };
volatile bool mpuInterrupt = false;
boolean conflag = 0;
 
void ICACHE_RAM_ATTR dmpDataReady() { mpuInterrupt = true; }
 
void setup() {
  Serial.begin(115200);
  dht.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  // splash / Wi-Fi connect status on OLED…
 
  Wire.begin();
  Wire.setClock(400000);
  mpu.initialize();
  pinMode(INTERRUPT_PIN, INPUT);
  uint8_t devStatus = mpu.dmpInitialize();
  if (devStatus == 0) {
    mpu.CalibrateAccel(6);
    mpu.CalibrateGyro(6);
    mpu.setDMPEnabled(true);
    attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING);
    dmpReady = true;
  }
  pinMode(LED_PIN, OUTPUT);
}
 
void loop() {
  if (conflag == 0) {
    // OLED: Wi-Fi status + DHT temperature / humidity
    // set conflag = 1 once linked
  } else {
    if (!dmpReady) return;
    if (mpu.dmpGetCurrentFIFOPacket(fifoBuffer)) {
#ifdef OUTPUT_TEAPOT
      teapotPacket[2] = fifoBuffer[0];
      teapotPacket[3] = fifoBuffer[1];
      teapotPacket[4] = fifoBuffer[4];
      teapotPacket[5] = fifoBuffer[5];
      teapotPacket[6] = fifoBuffer[8];
      teapotPacket[7] = fifoBuffer[9];
      teapotPacket[8] = fifoBuffer[12];
      teapotPacket[9] = fifoBuffer[13];
      Serial.write(teapotPacket, 14);
      teapotPacket[11]++;
#endif
      digitalWrite(LED_PIN, !digitalRead(LED_PIN));
    }
  }
}

Libraries used in the full sketch include Adafruit DHT / Unified Sensor / GFX / SSD1306, ESP8266WiFi, and Jeff Rowberg’s I2Cdev / MPU6050 MotionApps stack.

Processing sketch outline

import processing.serial.*;
import processing.opengl.*;
import toxi.geom.*;
import toxi.processing.*;
 
ToxiclibsSupport gfx;
Serial port;
char[] teapotPacket = new char[14];
float[] q = new float[4];
Quaternion quat = new Quaternion(1, 0, 0, 0);
 
void setup() {
  size(600, 600, OPENGL);
  gfx = new ToxiclibsSupport(this);
  port = new Serial(this, "COM4", 115200); // use your port
  port.write('r');
}
 
void draw() {
  background(0);
  pushMatrix();
  translate(width / 2, height / 2);
  float[] axis = quat.toAxisAngle();
  rotate(axis[0], -axis[1], axis[3], axis[2]);
  fill(255, 0, 0, 200);
  box(386, 40, 200);
  fill(255);
  text("https://subhdb.co.in", -183, 10, 101);
  popMatrix();
}
 
// serialEvent(): sync on '$', assemble 14-byte teapot packet,
// decode q0..q3 from bytes, quat.set(q[0], q[1], q[2], q[3]);

Replace COM4 with the NodeMCU serial device on your machine. Tilt the breadboard and the on-screen model should follow.

Watch it move

Original demo (also on my YouTube channel):

Watch on YouTube

References

This piece was first published on 9 May 2020 as Visualize NODEMCU plugged MPU6050's realtime movement in OLED display, and is carried here under Technology as part of the digital journey archive.

Filed under

  • NodeMCU
  • MPU6050
  • OLED
  • Processing
  • IoT
  • Sensors

Keep reading

Technology3 min read

The honest case for AI in the enterprise

Most enterprise AI programmes fail for the same reason enterprise search failed in 2008: nobody owned the data. Here is what actually has to be true before a model earns a place in production.

Read essay →
Technology5 min read

A complete home automation solution framework using Hassio

Raspberry Pi Hass.io as the hub, Mosquitto MQTT, NodeMCU driving an 8-channel relay bank, Home Assistant entities, an optional NodeMCU WebSocket UI, and a lighter IR/mobile alternative without the Pi.

Read essay →