Collect2: error: ld returned 1 exit status *** [.pio/build/megaatmega2560/firmware.elf] Error 1

Hi @adelvalle62 and welcome to this forum.
ld stands for “linker” and this is a common error when some symbols that the compiler built before somehow cannot be linked together to make an executable.
Typically, those errors are not too hard to fix, in most cases one of the following is the culprit:
Possible causes:

  • missing include guards #ifndef BLA_H #define BLA_H
  • included .cpps instead of headers (which will just copy those to the top of the file, thus will be double included)

Solutions:

  • place guards
  • make sure the headers/sources are found by the compiler and linker using build flags for external folders (not in /lib folder)
  • include headers, not the source file, to avoid double compilation and resulting linker errors

For a more detailed analysis you’d have to post the full error output. Also note, that you’re not the first one to post a topic like this, example. Please search the forum for similar issues that got a solution before posting possibly duplicate threads.
Hope this helps :wink: