First Example Blink Fails for Obvious Reason

So, newbie to PlatformIO here, but fairly experienced C coder. I hopefully did the IDE install correctly following the guide. Then I began the Blink project as instructed in the Quick Start:

 * Blink
 * Turns on an LED on for one second,
 * then off for one second, repeatedly.
#include "Arduino.h"

void setup()
  // initialize LED digital pin as an output.

void loop()
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BUILTIN, HIGH);
  // wait for a second
  // turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, LOW);
   // wait for a second

The first compilation attempt ended with the error message:

src\main.cpp:14:11: error: 'LED_BUILTIN' was not declared in this scope

Of course, this is because the example code does not contain a #define for LED_BUILTIN. Adding that easily fixed the problem, but that’s not my point. I’m now wondering if I did the install correctly and completely? Should the compiler have “magically” known that LED_BUILTIN was GPIO13 on the board I specified (Adafruit Feather 32u4)? It sure did a lot of configuring when I picked the board, just wondering if there should have been some “hidden” include<> file that defines LED_BUILTIN and it didn’t happen because I installed something incorrectly? Why else would the very first example program not #define LED_BUILTIN?

Anyway, after #define LED_BUILTIN, the compile and upload worked and the LED is blinking away. This brings me to the next question. How did PlatformIO --> Upload know which serial port to use? Where do I set that?



Platformio installed correctly :slight_smile:
How can the compiler “magically” know what you would like to pins to be called??
You have called GPIO13 as “LED_BUILTIN”, someone else might decide to refer to it another way.
(A rose by any other name… :-P)
As far as I know, only the mbed online compiler comes with that predefined names for certain pins.

To answer your second question, “pio device list” shows a list of all the available serial ports to the system.
platformio chooses the first available serial port for attempting to upload the program. You can specify a serial port of your choice in the platformio.ini file using the “upload_port” flags.

I agree. Therefore the VERY FIRST EXAMPLE code for using this IDE should have included:

// Please uncomment the following line and replace 'xx' with the pin # you LED is connected to
//#define LED_BUILTIN xx

So, no way to select the Serial Port # from the GUI?

I really want to like and use this IDE. It seems to have great features and a beautiful presentation. But, if they want to lure newbies away from the Arduino IDE, they need to think like a newbie. That starts with an installation process that’s just as easy and a clearly written transition guide. Nowhere in the process should be the words: “edit the .ini file” or “use the command line interface”.

It is not intended to be a direct replacement/competition to the arduino IDE. More of a replacement for a
vim editor, in a manner of speaking. It is, in my experience, as excellent compromise between a newbie and a pro. Works well for both, is intuitive and user-friendly. :slight_smile:

No, in response, there is no way to select the serial port from the gui. You can list the serial ports from GUI. You can initiate a serial monitor from the gui, but you cant select one.

Thanks a lot for the report! Fixed:

Can I suggest to update the documentation of the IDE with this same fix (#ifndef LED_BUILTIN fix), as this issue just caused me several hours of pain and suffering and almost abandoning this awesome project, before finally figuring out that LED_BUILTIN is not globally defined for all boards that have and LED actually on PIN 13, but I guess only on the official Arduino boards? I still haven’t figured out where this is actually defined, but it seems the LED on PIN 13 is common enough that something like this should not break for a common dev board.

I followed the IDE Blinky tutorial using an Adafruit feather32u4 board, which does indeed have an LED on pin 13, fully expecting the simple blinky main.cpp code to compile, and struggled for a while trying to figure out why things were not working.

This needs to be made obvious - as the IDE QuickStart guide is usually the very first thing that people like me usually do.

The doc I am talking about is here:

Thanks, fixed!