Skip to content
NewA realistic 3D head for a free swim cap editor
Nov 17, 2026·4 MIN READ
Logging IMU data from an M5Stack Core2 to CSV, and the two bugs that hid it

Logging IMU data from an M5Stack Core2 to CSV, and the two bugs that hid it

I set up an M5Stack Core2 to stream its MPU6886 accelerometer and gyroscope to a CSV file at 100 Hz. The code was fine. The log file stayed empty because of two serial port traps.

I had an M5Stack Core2 on the desk and one evening to play with it. The plan was small: read the built-in MPU6886 and save the samples on my Mac as CSV. The firmware took a few minutes. Then I ran the logger and got an empty file.

The setup

The Core2 is an ESP32 with a touch screen, a battery, a speaker and a 6-axis IMU in one box. I used PlatformIO with the Arduino framework and the M5Unified library, version 0.3.0. One library covers the display, the power chip and the IMU, and it detects the board by itself. Mine turned out to be the v1.1 revision with the AXP2101 power chip.

flowchart LR
    IMU[MPU6886] -->|I2C| ESP["ESP32<br/>100 Hz loop"]
    ESP -->|"USB serial<br/>115200 baud"| PY["log.py<br/>on the Mac"]
    PY --> CSV["logs/imu-date.csv"]

The firmware is one loop: every 10 ms read the accelerometer and the gyroscope, then print one line.

src/main.cpp
void setup() {
  auto cfg = M5.config();
  M5.begin(cfg);
  // M5.begin() does not open the serial port, so open it here.
  Serial.begin(115200);
  Serial.println("t_ms,ax_g,ay_g,az_g,gx_dps,gy_dps,gz_dps");
}

That Serial.begin line was not there at first. It is half of the story.

An empty file, twice

The first run of make log wrote zero bytes. No error, no boot text, nothing. There were two separate bugs, and each one alone was enough to give an empty file.

SymptomCauseFix
Not a single byte on the portThe port was opened with DTR and RTS on, and that kept the board in resetOpen the port with both lines off
Boot text, then silenceM5.begin() did not open Serial in my build, so Serial.println went nowhereCall Serial.begin(115200) after M5.begin()

The first one sits in the USB chip wiring. The DTR and RTS lines also drive the reset and boot pins of the ESP32, so the flashing tool can restart the board. A plain serial open sets both lines on. On my Core2 that meant the chip never started. In Python the fix is three lines before open():

tools/log.py
ser = serial.Serial()
ser.port = port
ser.baudrate = 115200
ser.dtr = False
ser.rts = False
ser.open()

For the PlatformIO monitor the same thing is monitor_dtr = 0 and monitor_rts = 0 in platformio.ini.

With that fixed I saw the ROM boot messages and then nothing again. The board was running, but my lines never arrived.

Build once with -DCORE_DEBUG_LEVEL=5. The ESP32 core then prints its own log over the same wire. I saw the board detection and the IMU start, so the chip was alive and only my Serial output was missing. That pointed straight at the missing Serial.begin.

The result

After both fixes the logger saved 697 rows in about 7 seconds, so a steady 100 Hz:

logs/imu-20261117-001514.csv
t_ms,ax_g,ay_g,az_g,gx_dps,gy_dps,gz_dps
770,-0.0007,0.2913,0.9408,0.15,0.64,0.28
780,0.0022,0.2889,0.9445,-0.28,-0.28,-1.55
790,-0.0036,0.2898,0.9389,-0.16,-0.15,-0.21

The board was lying still, a bit tilted. The three acceleration values add up to about 0.98 g, which is what gravity should give.

Opening the serial port restarts the Core2. Every log starts at t_ms close to zero, and the logger has to skip the boot text before the CSV header.

Next idea: a remote for Vimo Swim

While it was logging I looked at the box again. It has BLE, a touch screen, a vibration motor and a battery. That is most of what a poolside remote for the Vimo Swim device needs, so a coach could change the tempo without a phone.

I will not port the Vimo Swim firmware to it. That firmware is Rust on an nRF52, and the Core2 is a different chip family. A small BLE client that speaks the protocol the device already has is far less work. The Core2 is not waterproof, so it stays on the deck.

What it took

One evening, about 30 lines of firmware and a 60-line Python script. Most of the time went into the empty file, not into the IMU. Next time I will print one line right after boot and read it on the Mac before I write anything else. A serial link that I have seen working is worth more than code that should work.

Share
Mariusz Smenżyk
Written by

Mariusz Smenżyk

Builder for sport. Make. Test. Launch.

Related notes