How could the main.cpp read the parameters at platformio.ini?

It is working fine :smile:

Thank you very much!

main.cpp

#include <Arduino.h>
int i;
void setup() {
    /* Serial.begin(UPLOAD_SPEED,SERIAL_8N1);*/
    Serial.begin(115200);
    delay(1000);
    while (!Serial)
        {
        delay(10);
        Serial.println("================================");
        Serial.println("= Error to initialize USB port =");
        };
    Serial.println("=========================================");    
    Serial.println("= USB port initialize with " + String(UPLOAD_SPEED) + " baud.");
    Serial.println("= This firmware was uploaded from " + String(UPLOAD_PORT));
    Serial.println("= Monitor speed was " + String(MONITOR_SPEED) + " baud.");
    Serial.println("=========================================");
    Serial.println("======= work fine in setup section ================");
    i = 1;
}

void loop() 
{  
    while (i <= 10)
        {
        Serial.println("======= work fine in loop section i = " + String(i));
        i++;
        }
}
platformio.ini

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[upload_settings]
upload_port = COM15
upload_speed = 115200
monitor_speed = 9600
[env:wiscore_rak4631]
platform = nordicnrf52
board = wiscore_rak4631
framework = arduino
; lib_deps = 
;    ArduinoModbus
;    closedcube/ClosedCube OPT3001@^1.1.2
;    boschsensortec/BSEC Software Library @ ^1.6.1480
;    beegee-tokyo/SX126x-Arduino@^1.2.1
build_flags =
   -L".pio/libdeps/wiscore_rak4631/BSEC Software Library/src/cortex-m4/fpv4-sp-d16-hard"
;   -DREGION_AU915
   -D UPLOAD_PORT=\"${upload_settings.upload_port}\"
   -D UPLOAD_SPEED=${upload_settings.upload_speed}
   -D MONITOR_SPEED=${upload_settings.monitor_speed}
extends = upload_settings

1 Like