PlatformIO Community

Identifier 'Serial' undeclared

I’m using a Sublime Text project, trying to build a test program for my Teensy 4.0. The code below fails to compile because Serial is undeclared, and I can’t seem to find anywhere what header I need to include to get that declaration.

#include <Arduino.h>

void setup() {
    digitalWrite(13, 1); // Turn on the LED so I can see that the board is powered
    while (!Serial);
    Serial.println("Monitor connected");

void loop() {
    if (Serial.available()) Serial.write(;

I also tried Serial1, to see if it was only the USB serial port that didn’t work, but that was also an undeclared identifier. I’m coming from Teensyduino, which doesn’t require any header to access the serial ports, but I wanted to try PlatformIO because the serial monitor doesn’t seem to work in Teensyduino. Can anyone please tell me how to expose the serial ports?

1 Like

Have you enabled the serial port as per It seems you need to do this.


I thought PlatformIO enabled the USB serial port by default? That link describes how to do it in Teensyduino, which is not what I’m using anymore. Besides, the hardware serial ports 1-7 are always enabled and are immediately available by the time your code runs… but Serial1 is also an undeclared identifier, so it’s not just a problem with my USB setting.

100% my fault, I accidentally named the file main.c instead of main.cpp so none of the class declarations were visible. It has been many many years since I made a mistake like that…

1 Like