Serial Monitor output during setup()

When using PlatformIO for an Arduino project I can click the Serial Monitor button and view serial output in the loop() function. However, I am having trouble viewing serial output in the setup() function because the Serial Monitor needs to re-opened after each recompilation / upload, at which time the setup() has already completed. An obvious workaround to the problem is to add a delay–and this works–but this undesirable.

Is there a more practical solution to this issue? Perhaps a way to keep the Serial Monitor open and connected between compilation / uploads? Or even dump the serial output to the Terminal output?

Thanks and best regards.

Keeping the monitor open is no solution because this will block the upload.

But you can use the “Upload and Monitor” feature, which will open the monitor after uploading. That’s the “Up-Arrow” icon in the toolbar.

If you don’t have this icon:

  • Click the VS Code Gear Icon
  • Choose “Settings”
  • Search for “PlatformIO” under Extensions
  • Scroll down to “Toolbar” and click “Edit in settings.json
  • Scroll down to the settings for "platformio-ide.toolbar"
  • Paste in:
        {
            "text": "$(arrow-up)",
            "tooltip": "PlatformIO: Upload and Monitor",
            "commands": [
                "workbench.action.terminal.kill",
                "platformio-ide.uploadAndMonitor"
            ]
        },
1 Like

Thank you very much @sivar2311. Your solution worked perfectly. I did not have that icon but was add to add it manually with your instructions.

Best regards.

1 Like