I'm confused by PlatformIO's handling of Arduino sketches and examples

Hi all,
Still onboarding PlatformIO and this is my first post here. I hope I’ve chosen the right category.

I copied a small example and built and ran it using the Arduino IDE. (Target is a NodeMCU ESP-12E). Next step was to import the .ino file into a PlatformIO project. The code built and only partially worked until I renamed the src/<sketch>.ino to src/main.cpp at which point it built and worked as desired.

First point of confusion is why doesn’t the import process rename .ino files to .cpp when they’re copied to the src/ directory?

Now I’m looking for a library and example code to interface with a BME280 sensor. The one I’d like to try is https://platformio.org/lib/show/166/Adafruit%20BME280%20Library.

Second point of confusion is that the examples are all .ino files which resulted in a non-working example.

Should I expect these examples to run if built using the Arduino tool chain? Is the .ino extension just a shorthand way of indicating that these are intended to be used with the Arduino platform libraries?

Inquiring minds are confused.

BTW my previous example can be viewed at https://github.com/HankB/mqtt_esp8266_PIO

Thanks!

This is because PlatformIO can be used as a replacement for the Arduino IDE. In projects using the Arduino framework, (framework=arduino in platformio.ini) then it can happily compile Arduino projects directly, using the *.ino files. All that is needed is to add #include "Arduino.h" to the ino files.

  • Did you add this line to your ino files?
  • What compile errors did you get?

Many examples are written for the Arduino as ino files. I have come across some which are missing the Arduino.h header file which PlatfomIO requires.

HTH

Cheers,
Norm.

1 Like

That seems to be the issue. I say “seems” because I cannot get it to misbehave now, regardless of the name of the single C++ source file.

I did not include Arduino.h but will certainly do so in the future. Lack of it led to no compile errors. The application built and mostly worked. There were some warnings from libraries relating to signed vs. unsigned comparisons and warnings in the app about deprecated symbols and a size mismatch in an sprintf() but I saw nothing that looked suspicious.

Thanks for the reply.

Yes, that is the only requirement to convert from the Arduino IDE to PlatformIO. No need to rename the files etc. That’s how I started, I used the Atom editor and PlatformIO to replace the IDE which I’ve never got to like. But PlatformIO offers much more if you want it.

Have fun.

Cheers,
Norm.