Built-in project · ESP32-DevKitC V4

MicroPython serial print: the ESP32’s running time, on an ESP32-DevKitC V4

MicroPython on an ESP32 with nothing wired: print() sends a greeting and then the running time in seconds to the Serial Monitor. The whole build, an ESP32-DevKitC V4, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner About 5 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $10. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • Sending text to the Serial Monitor with print
  • Measuring uptime with time.ticks_ms
  • Formatting numbers into a string with %d
  • Pausing with time.sleep
  • Difficulty: Beginner
  • Time: About 5 minutes
  • Board: ESP32-DevKitC V4
  • Parts: 1

How it works

Nothing is wired for this one. The script prints a start message once, then loops forever.

Each pass asks time.ticks_ms() how many milliseconds have passed since the board started, divides by 1000 to get seconds, and prints it. Then it sleeps one second. You see the count tick up in the Serial Monitor.

Parts list

1 part, plus the jumper wires. They retail for about $10; on Mokxi they're free.

Kits that can build it

These 3 starter kits have every part in the circuit. Each kit's page lists what else it can build.

The code

The MicroPython code exactly as the editor opens it. Change a line there and press Run: the board runs it on the official MicroPython firmware, with nothing to compile.

main.py · ESP32-DevKitC V4
# Serial print: say hello once, then print how long the board has been
# running, every second. print() goes to the Serial Monitor.
import time

print("ESP32 initialization completed!")
while True:
    print("Running time: %d s" % (time.ticks_ms() // 1000))
    time.sleep(1)

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The count seems to skip or repeat This project
    Printing takes a tiny bit of time on top of the one second sleep. That is normal for a simple timer.
  • The board is not found, or upload fails with a connecting message. ESP32-DevKitC V4
    Use a USB cable that carries data, not charge only. Pick the ESP32 Dev Module board. If it still fails, hold BOOT while uploading starts, then release.
  • Some pins never read right, or the board will not boot with a wire attached. ESP32-DevKitC V4
    GPIO34 to 39 are input only and have no pull-ups. GPIO6 to 11 run the flash, so leave them alone. GPIO0, 2 and 12 are boot pins; avoid pulling them the wrong way at reset.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.