2

I have a working Arduino code. The code works as intended when I upload it to an Arduino Nano using the old bootloader via the Arduino IDE. However, when I upload the same code via PlatformIO, the code uploads successfully but does not work as intended. There are no errors or warnings during the upload process, and I am having trouble figuring out what could be causing the issue.

Now for troubleshooting I am using simple blink example.

#include <Arduino.h>
// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(1000);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);                      // wait for a second
}

1st PlatformIO configuration .ini

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
debug_port = COM3
monitor_speed = 115200

I have also tried following but no luck.

2nd PlatformIO configuration .ini

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
board_oldbootloader = true
debug_port = COM3
monitor_speed = 115200

Any suggestions on how to debug this problem or what might be causing the issue? Thank you.

7
  • The blink function gets programmed by the IDE. In case I program with Arduino IDE the code gets uploaded to the board and works as intended (i.e. LED blinks). In case I program with PlatformIO the code gets uploaded to the board but doesn't work as intended (i.e. (The LED doesn't blink).
    – DeXter
    Commented Feb 20, 2023 at 17:43
  • It's very weird. I have tried different solutions but nothing seems to work.
    – DeXter
    Commented Feb 20, 2023 at 17:48
  • turn on the LED in setup ... leave loop() empty ... what happens?
    – jsotola
    Commented Feb 20, 2023 at 18:44
  • print the value of LED_BUILTIN to serial monitor to see its value ... also, try referring to the LED pin by number
    – jsotola
    Commented Feb 20, 2023 at 18:50
  • My apologies. Not familiar, 1st ever question.
    – DeXter
    Commented Feb 20, 2023 at 18:55

1 Answer 1

2

I had a similar behavior for a while and nothing I would change in the PlatformIO .ini configuration file seemed to help. I tried to re-init and clean the project, but also didn't seem to help.

Eventually, what worked for me was to start a new fresh PlatformIO project and migrate the files over.

I suspect that under certain conditions (that may be related to the project settings), PlatformIO fails to upload the script, yet it claims that the upload was successful.

Not the answer you're looking for? Browse other questions tagged or ask your own question.