Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PlatformIO for Arduino project #6

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

RobThree
Copy link

This pull request adds PlatformIO support (https://platformio.org). It also gets rid of 2 compilation warnings. It also incorporates PR #5 by @BizarroBull ('cast result of Serial.read() so it doesn't get treated as signed when bit shifting').

@AndersBNielsen
Copy link
Owner

Not a bad idea but it would break Arduino IDE compatibility (both the .ino and main.cpp would need to be kept in sync).
Any good ways to automate that?

Any other for/against?

@RobThree
Copy link
Author

RobThree commented Aug 17, 2024

I haven't used the Arduino IDE in a (long) while. I'm not sure it still insists on .ino files, but the .cpp file should work otherwise; the only real change I made is I added #include <Arduino.h> for PlatformIO (other minor changes from the top of my head were: declare functions before use, incorporate #5, maybe some formatting).

I'm not sure if this PR would break Arduino IDE compat though? As long as you open only the ArduinoProgrammerFirmwarePrototype directory in Arduino IDE it should work, shouldn't it?

But I agree that having the .ino files and the PlatformIO files in separate directories means having to keep the files in sync. I'm not sure if having a sort-of 'common' directory with shared code that is included in a .ino and the Platformio projects is possible.

If I have time tomorrow I'll try and see what I can come up with (being a primarily .Net developer I'm not sure if what I come up with is the best approach...)

@RobThree
Copy link
Author

RobThree commented Aug 17, 2024

Changing main.cpp to only contain this:

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "../../ArduinoProgrammerFirmwarePrototype/ArduinoProgrammerFirmwarePrototype.ino"

...and adding this to ArduinoProgrammerFirmwarePrototype.ino:

#include <Arduino.h>

... seems to work. But that seems a little bit (very) dirty to me...

@tssva
Copy link

tssva commented Nov 16, 2024

Having a separate cpp file and directory for platformio isn't necessary. As long as the source directory and the ino file have the same name, which they already do in this case, then Platformio will automatically convert the ino file at compile time.

Adding #include <Arduino.h> to the ino file isn't necessary because platformio will do so during the conversion but doing so does help intellisense with code highlighting and completion if you open the project in vscode. The ino file will continue to compile without issue in the Arduino IDE with this change.

There is a decision regarding where to place the platformio.ini and .gitignore file. You can place them in the software/Arduino directory or the software/Arduino/ArduinoProgrammerFirmwarePrototype directory. If there is a chance additional software will ever be placed in the software/Arduino directory I recommend placing them in the ArduinoProgrammerFirmwarePrototype directory.

If placed in software/Arduino the platformio section of platformio.ini should be as follows:

[platformio]
default_envs = uno
src_dir = ArduinoProgrammerFirmwarePrototype

If placed in the ArduinoProgrammerFirmwarePrototype directory the following instead:

[platformio]
default_envs = uno
src_dir = .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants