Ubuntu's Platformio does not load sketch on Leonardo

Hello,
I am using platformio as IDE for Arduino. I followed this [iurl=https://docs.platformio.org/en/latest/faq.html#platformio-udev-rules]link[/iurl] to run a sketch and it was successfully uploaded in A. Leonardo.
When I started the IDE again, I still have problems uploading the sketch:

        Processing leonardo (platform: atmelavr; board: leonardo; framework: arduino)
        --------------------------------------------------------------------------------
        Verbose mode can be enabled via `-v, --verbose` option
        CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/leonardo.html
        PLATFORM: Atmel AVR (3.0.0) > Arduino Leonardo
        HARDWARE: ATMEGA32U4 16MHz, 2.50KB RAM, 28KB Flash
        DEBUG: Current (simavr) On-board (simavr)
        PACKAGES:
         - framework-arduino-avr 5.1.0
         - tool-avrdude 1.60300.200527 (6.3.0)
         - toolchain-atmelavr 1.50400.190710 (5.4.0)
        LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
        LDF Modes: Finder ~ chain, Compatibility ~ soft
        Found 5 compatible libraries
        Scanning dependencies...
        No dependencies
        Building in release mode
        Linking .pio/build/leonardo/firmware.elf
        .pio/build/leonardo/src/main.cpp.o (symbol from plugin): In function `setup':
        (.text+0x0): multiple definition of `setup'
        .pio/build/leonardo/src/colorReader.cpp.o (symbol from plugin):(.text+0x0): first defined here
        .pio/build/leonardo/src/main.cpp.o (symbol from plugin): In function `setup':
        (.text+0x0): multiple definition of `loop'
        .pio/build/leonardo/src/colorReader.cpp.o (symbol from plugin):(.text+0x0): first defined here
        collect2: error: ld returned 1 exit status
        *** [.pio/build/leonardo/firmware.elf] Error 1
        ========================== [FAILED] Took 1.09 seconds ==========================

What might be wrong?
How can I set the board once and for all?
Thank you

You have a compile error. This is not an upload error, PlatformIO does not even attempt to upload the compiled firmware to the board, because compiling fails.

The error message says that your code attempts to define setup() and loop() twice. You have the files src/main.cpp and src/colorRead.cpp conflicting each other. It’s like you want to upload two sketches at once. Please delete one file with the sketch that you don’t want to run.

1 Like

I still have problem uploading the sketches. Now I have a specific directory with a single sketch:

~/Documents/PlatformIO/Projects/Blinktest$ ls
blink.cpp  include  lib  platformio.ini  src  test

The building gives no error, neither does the upload, but then nothing happens. In theory, the built-in LEDC should blink. However, when I do testing I get an error:

Verbose mode can be enabled via `-v, --verbose` option
Collected 1 items
 
Processing * in leonardo environment
--------------------------------------------------------------------------------
Building...
/tmp/ccIpZcXw.ltrans0.ltrans.o: In function `main':
<artificial>:(.text.startup+0x124): undefined reference to `setup'
<artificial>:(.text.startup+0x12c): undefined reference to `loop'
collect2: error: ld returned 1 exit status
*** [.pio/build/leonardo/firmware.elf] Error 1
========================== [FAILED] Took 1.15 seconds ==========================
Test    Environment    Status    Duration
------  -------------  --------  ------------
*       leonardo       FAILED    00:00:01.146
==================== 1 failed, 0 succeeded in 00:00:01.146 ====================

The sketch is:

#include "Arduino.h"

// initialize digital pin LED_BUILTIN as an output
void setup() {
    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
}

Is this error that avoids the proper upload of the sketch? How can I remove it?
Thank you

The blink.cpp has to be inside the src/ folder. I presume it’s empty now?