MicroPython: ESP32/ESP8266 Get Device Info (CPU, MAC Address, Flash Size, PSRAM & More)

In this quick guide, we’ll share a simple MicroPython script that displays useful information about your board. It’s a great tool for diagnostics and testing. The script retrieves details about the chip (such as the model and CPU frequency), the MAC address, memory usage, PSRAM availability, filesystem size, and free space, and lists the files stored on the board. This guide works with ESP32, ESP8266, and Raspberry Pi Pico boards.

MicroPython: ESP32/ESP8266 Get Device Info CPU, MAC Address, Flash Size, PSRAM & More

The code used in this tutorial was created and shared by Charles E. Hamilton, one of our readers.

New to MicroPython? Check out our eBook: MicroPython Programming with ESP32 and ESP8266 eBook (2nd Edition)

Prerequisites

To follow this tutorial you need MicroPython firmware installed on your ESP32 or ESP8266 boards. You also need an IDE to write and upload the code to your board. We suggest using Thonny IDE or uPyCraft IDE:

Learn more about MicroPython: MicroPython Programming with ESP32 and ESP8266

Get System Info – MicroPython Script

After loading MicroPython firmware on your board, copy the following code to Thonny IDE or the IDE of your choice.

# WhatsInIt.py - MicroPython Hardware & Environment Diagnostic Tool
# For ESP32 / ESP8266 boards
# Last updated: April 26, 2025 by Charles E. Hamilton
# This program is released into the public domain free of license and without warranties of any kind
# https://RandomNerdTutorials.com/micropython-esp32-esp8266-device-info/

import os
import sys
import gc
import machine
import network
import ubinascii

try:
    import esp
except ImportError:
    esp = None

try:
    import esp32
except ImportError:
    esp32 = None

print("\n" + "=" * 40)
print("        WHATS IN IT REPORT")
print("=" * 40)

# --- Chip & CPU Info ---
print("\n[CHIP INFO]")
print(f"Platform:           {sys.platform}")
print(f"MicroPython ver:    {os.uname().release} ({os.uname().version})")
print(f"Machine ID:         {os.uname().machine}")
print(f"CPU Frequency:      {machine.freq()} Hz")

# --- MAC Address ---
print("\n[NETWORK]")
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
mac = ubinascii.hexlify(wlan.config('mac'), ':').decode()
print(f"MAC Address:        {mac}")

# --- Memory Info ---
print("\n[MEMORY]")
print(f"Heap Allocated:     {gc.mem_alloc()} bytes")
print(f"Heap Free:          {gc.mem_free()} bytes")

# Flash size (ESP32 only)
if esp:
    try:
        flash_size = esp.flash_size()
        print(f"Flash Size:         {flash_size // (1024*1024)} MB")
    except:
        print("Flash Size:         Not available")

# PSRAM status (ESP32 only)
if esp32:
    try:
        psram_status = "Available" if esp32.ULP() is not None else "Not available"
    except:
        psram_status = "Not detected"
    print(f"PSRAM:              {psram_status}")

# --- Filesystem Info ---
print("\n[FILESYSTEM]")
try:
    fs_stats = os.statvfs("/")
    block_size = fs_stats[0]
    total_blocks = fs_stats[2]
    free_blocks = fs_stats[3]
    total = (block_size * total_blocks) // 1024
    free = (block_size * free_blocks) // 1024
    print(f"Total Size:         {total} KB")
    print(f"Free Space:         {free} KB")
except:
    print("Filesystem info:    Not available")

# --- Directory Contents ---
print("\n[FILES IN ROOT DIR]")
try:
    files = os.listdir()
    for f in files:
        print(f" - {f}")
except:
    print("Cannot list files.")

# --- Closing ---
print("\n[END OF REPORT]")
print("=" * 40)

View raw code

The following section prints information about the Chip and CPU: platform used, the micropython version, board model, and CPU frequency.

# --- Chip & CPU Info ---
print("\n[CHIP INFO]")
print(f"Platform:           {sys.platform}")
print(f"MicroPython ver:    {os.uname().release} ({os.uname().version})")
print(f"Machine ID:         {os.uname().machine}")
print(f"CPU Frequency:      {machine.freq()} Hz")

These lines print the board MAC address. The MAC address is a unique identifier assigned to your device’s network interface. It’s used for communication on Wi-Fi and other networks.

# --- MAC Address ---
print("\n[NETWORK]")
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
mac = ubinascii.hexlify(wlan.config('mac'), ':').decode()
print(f"MAC Address:        {mac}")

We print information about the board memory. The heap allocated is the amount of RAM currently in use by your program, while free heap is the amount of RAM still available for use.

# --- Memory Info ---
print("\n[MEMORY]")
print(f"Heap Allocated:     {gc.mem_alloc()} bytes")
print(f"Heap Free:          {gc.mem_free()} bytes")

There’s also a section to print the board flash size and if there’s PSRAM available.

# Flash size (ESP32 only)
if esp:
    try:
        flash_size = esp.flash_size()
        print(f"Flash Size:         {flash_size // (1024*1024)} MB")
    except:
        print("Flash Size:         Not available")

# PSRAM status (ESP32 only)
if esp32:
    try:
        psram_status = "Available" if esp32.ULP() is not None else "Not available"
    except:
        psram_status = "Not detected"
    print(f"PSRAM:              {psram_status}")

Finally, we print the filesystem total size and free space.

# --- Filesystem Info ---
print("\n[FILESYSTEM]")
try:
    fs_stats = os.statvfs("/")
    block_size = fs_stats[0]
    total_blocks = fs_stats[2]
    free_blocks = fs_stats[3]
    total = (block_size * total_blocks) // 1024
    free = (block_size * free_blocks) // 1024
    print(f"Total Size:         {total} KB")
    print(f"Free Space:         {free} KB")
except:
    print("Filesystem info:    Not available")

And if there are any files in the filesystem root directory.

# --- Directory Contents ---
print("\n[FILES IN ROOT DIR]")
try:
    files = os.listdir()
    for f in files:
        print(f" - {f}")
except:
    print("Cannot list files.")

Testing the Code

With the board connected to your computer and with a connection established with Thonny IDE, click the green run button to run the program on your board.

Run MicroPython script on Thonny IDE

The information about your board will be printed in the MicroPython shell.

Below you can see the report for an ESP32 DOIT board.

ESP32 with MicroPython - get system info

We also tested this script with an ESP32S3, and ESP8266, and a Raspberry Pi Pico board (you can click on the images to enlarge).

ESP8266 with MicroPython - get system info
Raspberry Pi Pico with MicroPython - get system info
ESP32S3 with MicroPython - get system info

Wrapping Up

In this quick guide, we shared a useful sketch that you can use and adapt in your projects to get essential information about your board chip and CPU, as well as information about the memory and filesystem.

To learn more about MicroPython, check out our resources:



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

1 thought on “MicroPython: ESP32/ESP8266 Get Device Info (CPU, MAC Address, Flash Size, PSRAM & More)”

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.