Color Messages to Terminal via Serial Monitor

I currently output status messages during arduino development (using vs code) to Platformio’s Terminal via the arduino’s serial monitor print and println commands and everything works just fine. I would like to highlight certain critical messages by prefixing them with a code string that would produce a color message.

Is this possible? If so, would you please point me in the right direction so I could implement color messages to the Platformio terminal.

I notice that when compiling a module, one of the first things to appear on the Platformio Terminal is the module name IN COLOR! - exactly like what I am trying to do. So it seems to be possible. I just don’t know how the module name was produced in color.

Thank you…

Duplicate of Some bizare characters prints on serial monitor with ESP-IDF hello world example – basically you’re looking for how to transmit ANSI color codes from the firmware and have them displayed correctly in the VSCode terminal.

Thanks MAX…

In detail, what I did was append ‘monitor_flags = --raw’ to the end of my platformio,ini, then prefixed the critical messages with “\e[1;31m” and suffixed them with “\e[1;37m” and, voila, red messages…

3 Likes

Using monitor_flags = --raw does indeed work to get colored messages in the terminal, but it does have an ugly side effect - Log files requested by setting:

monitor_filters =
	log2file
	time
	default

are being created, but remain completely empty!

Can I get both colored messages and a full log file?

(IDF framework produces a lot of such colored debug messages, which are nice in colors and awkward to read otherwise)

For anyone else coming to this in 2023, the monitor_flags property is no longer available. Instead there is a dedicated monitor_raw = yes property you can set.

4 Likes

awesome, thanks a lot!

If anyone comes here in 2026, using ESP-32 with espidf platform-io on Mac Os, this thread helped me but the working syntax I used is adding this line in platformio.ini :
monitor_filters = direct

from this PlatformIO documentation .

I also had to add an ESP-32 flag which was apparently disabled by default for my ESP32- C6:

-D CONFIG_LOG_COLORS=1

Here’s my full platformio.ini file:

[env:esp32-c6-devkitc-1]
platform = espressif32
framework = espidf
board = esp32-c6-devkitc-1
monitor_speed = 115200
monitor_filters = direct
build_flags = 
    ; -D CORE_DEBUG_LEVEL=0
    -D CONFIG_LOG_COLORS=1