Was looking around at some code examples and I stumbled on to someones comments around Platform.IO as a replacement to the Arduino IDE. I really don’t like the Arduino IDE so was keen to have a look at it. I tried Visual Micro (allows Arduino development in Visual Studio) once, but found it a bit buggy and slow. It may be fine these days?
Any way, i though’t i’d put in the time and learn Platform.IO, and I am very glad i did!. It took a little bit of messing around but it was worth it. Never going back to Arduino IDE now I am setup 🙂
Here’s the process I went through to get going on Windows 10:
Download Visual Studio Code – Its only 43mb – i was thinking Visual Studio, It will take 2 hours to install, but Visual Studio Code is really lightweight.
Run Visual Studio as Admin (right click, run as Admin – needed to do the next bit).
I changed the color scheme to light as I am old school 🙂 – File > Preferences > Color Scheme
Install Platform IO extension in to Visual Studio code – follow these instructions here (this is why running as Admin as it failed for me the first time without running as Admin)
All going well, you should be ready to go and when you open Visual Studio Code, you should see the PlatformIO home screen, and a little Home icon on the bottom left of the bottom status bar.
Create a Project
Click on + New Project
Give it a name
Select a board – you can search here.. this is what i really liked, heaps of support for modern boards. I initially tried the WEMOS LOLIN board – ESP32 with an OLED Screen on it. Have also tried with just basic NodeMCU 1.0 boards too.
For this example, using a Wemos D1 Mini.
Set Arduino as the platform.
Once you press Finish, if this is your first project, it can take some time to open and install all the libraries and toolchains etc.
I thought mine had locked up, but after maybe 7-8 mins, it kicked into life. Now every time i start a new project it’s fast.
Had the same thing when i started a new ESP32 project – it has to go and get all the bits and bobs to make it go so it’s slow the first time.
Moral – let it do its thing.
Getting your head around it
Here’s my notes from my initial – getting my head around it and how it works like Arduino IDE.
First off, the main ‘sketch’ is under the src > main.cpp file
We can get something really basic happening here just writing to the terminal. Use this code:
Now before we upload our basic sketch, configure the board port and speed.
Open the platformio.ini file from the left hand nav at the bottom
If you need to find what port your board is connected on, check under Device Manager in Windows:
Start > type Device Manager
Expand out Ports (COM & LPT)
Once you have set your correct port in the INI file, you can build and upload.
The bottom nav bar is where you find the build, upload and show terminal buttons, similar to Arduino IDE.
The tick = build, the right arrow = upload, and the plug icon = show terminal window.
Press the tick button to build.
You should now have a compiled version of our simple sketch. If you have any error, you will see in the Terminal window what’s wrong. Hopefully you should have no errors with basic sketch above.
Now upload (presuming plugged in) your sketch the the board using the right arrow on bottom Nav.
Once you are uploaded, you can then switch on the terminal monitor by pressing the plug icon in the bottom nav:
Here you can see our simple app displaying ‘Hello Universe’ in a loop every second:
Yay, that’s the basics of Platform IO… now for the next bit.. handling libraries.
This is the bit i like about Platform IO, took my head a bit to get.
First off, there’s a library manager system built in like the later versions of Arduino IDE.
Let’s say we want to add Blynk support.
Switch the PIO Home tab, and click on the Libraries button on the left hand side.
Here you can search for a library.
Click in to the Library to read more, get examples, and Install.
Once the library is installed, it will be put in to your file system here:
This is the folder where libraries are stored.
You should be able to then just add a reference to your library you added:
I found though when you include manual libraries, sometimes they get a green squiggle under them.
In this case, you have to go add a reference to the libraries path.
When you see a green squiggle under the #include line, go check the c_cpp_properties.json file in your project.
Make sure the path to the library you want to use is in this file in the top section.
NOTE: the folder path is separated by forward slashes instead of back slashes.. you need to follow this format.
In this example below, i can see the Blynk library was automatically added when we added the library through the library manager search/install process.
If i wanted to download a manual library from the internet and use it in my sketch, i would follow these steps:
For example, lets say i want to use this WifiManager library that has been modified to support ESP32 and isn’t necessarily available in the Library Manager.
I’d download the ZIP file from here: https://github.com/zhouhan0126/WIFIMANAGER-ESP32
I’d right click and unblock the ZIP, then i’d extract it to here:
I’d go and insert a reference line in the bottom of the includePath section of my c_cpp_properties.json file (changing the \’s for /’s) to the path of the library.
Now i’d add my #include as normal to my sketch and build.
Hope that helps someone get started quickly.
The intellisense, problems tab (so you can immediately see issues), and general workflow is so much nicer than the Arudino IDE.