Skip to content

Instantly share code, notes, and snippets.

@runningdeveloper
Last active March 28, 2022 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save runningdeveloper/220f52645619b94825b1ae429acfcba5 to your computer and use it in GitHub Desktop.
Save runningdeveloper/220f52645619b94825b1ae429acfcba5 to your computer and use it in GitHub Desktop.
Script to make an Arduino IDE project from a PlatformIO project

Why

Your friends are comfortable in the Arduino IDE, but you using vscode and PlatformIO because it is easier (libraries, config and shortcuts). So you need to give them an ino file and the correct versions of the libraries. And you want to eliminate them from running an incorrect version the project.

Usage

Only tested on a Mac using zsh.

  1. Paste the make-arduino.sh into the root of your PlatformIO project. Give it execute permissions if needed chmod u+x make-arduino.sh.
  2. Then adjust the script with the project name and any string replacements you need.
  3. Run it ./make-arduino.sh and give it a version. This will put it in a folder called build and add a zipped version.
  4. Send this to the Arduino IDE friend.
  5. Uzip folder.
  6. Included in the project is a libs folder. This is to remove the issues with having to find the libraries and the correct versions through the Arduino IDE. You take the the contents of the libs folder and paste it into the Arduino IDE libraries folder, usually at Documents/Arduino/libraries
  7. Double click the my-project-name.ino and you should be good to go.

Hope it works for u. There is probably an easier way?

#!/bin/bash
read -p "Enter version: " version
if [ -z "$version" ]
then
echo "Error please add a version"
else
echo "Make arduino ide version $version"
projectName="my-project-name"
# can replace strings in your project like passwords or settings, this is an array can add more
stringReplacements=("s/string to be replaced/replacement string/g")
# makes a folder called build for the results of this script
mkdir build
# main program
mainName="$projectName-$version"
mkdir build/$mainName
# copying your custom libraries to the output folder
cp ./lib/**/src/* build/$mainName
# copying the source files
cp ./src/* build/$mainName
# rename the main.cpp to ino so it opens in arduino ide
mv build/$mainName/main.cpp build/$mainName/$mainName.ino
# replacing any strings like passwords and things
for ((i = 0; i < ${#stringReplacements[@]}; i++))
do
sed -i '' "${stringReplacements[$i]}" build/$mainName/*.cpp build/$mainName/*.h build/$mainName/*.ino
done
# copy the libraries from pio folder to a libs folder (paste into the /Arduino/libraries folder)
mkdir -p build/$mainName/libs
cp -R ./.pio/libdeps/**/* build/$mainName/libs
# rename if there are spaces
for i in build/$mainName/libs/*
do
mv "$i" ${i// /_}
done
# copying your flash data folder to the output folder
mkdir -p build/$mainName/data
cp -R ./data/* build/$mainName/data
# zip it so you can send
zip -r build/$mainName.zip build/$mainName
echo "Made build/$mainName"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment