Getting Started wit...
 
Notifications
Clear all

Getting Started with PlatformIO

74 Posts
32 Users
28 Likes
10.7 K Views
(@dronebot-workshop)
Workshop Guru Admin
Joined: 5 years ago
Posts: 1076
Topic starter  

Get started with PlatformIO, a great alternative to the Arduino IDE. Examples with Arduino, ESP32 & XIAO microcontrollers.

Article with references & code: https://dbot.ws/platformio

Today we are going to be programming microcontrollers with PlatformIO, a development environment with many advantages over the Arduino IDE.

I’ll show you how to install PlatformIO under Visual Studio Code (VS Code), a free programming environment from Microsoft (yes, Microsoft also makes free software!). Full instructions for Linux, Mac OS X, and MS Windows.

After we add the PlatformIO plugin to VS Code I’ll show you examples of using it with an Arduino Uno, an ESP32 development module, and a Seeeduino XIAO. You’ll quickly see the advantages of using this amazing programming environment.

I’ll also show you how to use the PlatformIO Library Manager, and how it differs from using libraries with the Arduino IDE. To do this we’ll also build a dual servo motor controller with an LCD display.

Here is the Table of Contents for today's video:

00:00 - Introduction
02:22 - PlatformIO Basics
06:51 - Install VS Code - Linux
08:28 - Install VS Code - Mac OS X
10:13 - Install VS Code - MS Windows 10
11:55 - Install PlatformIO plugin for VS Code
13:56 - PlatformIO Basics with Arduino Uno
18:29 - PlatformIO Basics with ESP32
21:09 - PlatformIO Basics with Seeeduino XIAO
25:18 - Functions with PlatformIO vs Arduino IDE
31:17 - PlatformIO Library Management Basics
33:43 - Dual Servo Controller Demo Hookup
36:01 - Dual Servo Controller Code & Demo
46:44 - Understanding the platformio.ini file

Hopefully, after viewing this video you’ll be tempted to give PlatformIO a try. It can really speed and improve your coding tasks once you get used to it, and you’ll be seeing more of it here in the DroneBot Workshop.

"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
Quote
(@jfabernathy)
Member
Joined: 3 years ago
Posts: 141
 

I enjoyed this video and have VS and Platform IO installed thanks to your recent suggested software for a Linux workstation video. I can play with it on my Xiao and I'm going to try to add my Adafruit Metro ESP32-S2.  That board's Arduino IDE is not fully ready yet and you can't install it with the Board Manager.  You have to use a lot of github cloning to the right directory.  I got that done for Arduino IDE, but not sure how to translate that to VS Platform IO.  It's something to work on.  The good news is that the Metro ESP32-S2 has tons of memory and the CircuitPython support is getting better by the day for it.

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

Excellent video Bill.  Have been using Platform IO off and on for awhile now, but this really explained a few of the puzzling parts that I still was stumbling over.

I do have a question about the libraries though.  You showed how to add a library on a per project basis, but what if you wanted a global library?  Obviously you could just add the library to each project as it was needed, but that just adds an extra step, or more to creating each project.

SteveG


   
ReplyQuote
(@dronebot-workshop)
Workshop Guru Admin
Joined: 5 years ago
Posts: 1076
Topic starter  
Posted by: @codecage

I do have a question about the libraries though.  You showed how to add a library on a per project basis, but what if you wanted a global library?  Obviously you could just add the library to each project as it was needed, but that just adds an extra step, or more to creating each project.

Glad you liked the video Steve, and I'm also glad you asked a question about libraries.

I've received a pretty good response to the PlatformIO video and so I'm planning to do a second one, answering some more of those questions. Another "library-related" question would be "how do I install a library that is in a ZIP file?".

I also want to explain "workspaces" (once I completely understand them myself LOL) and how to manage file locations and how to import existing Arduino projects into PlatformIO.

Your specific question is a bit complicated, as PlatformIO removed the "Global Library" install feature from the GUI a few months ago. However, it can still be accomplished from the Command Line Interface (CLI), which you can access through the Terminal in Platform IO.

pio lib -g install <library name> 

I believe that it was removed as the logic behind PlatformIO is that you don't really want to do that, as the per-board method is more versatile. Judging from the complaints they are getting on their forum not everyone agrees!

Posted by: @jfabernathy

I got that done for Arduino IDE, but not sure how to translate that to VS Platform IO.

That's also a good topic to add to a follow-up video. You may find that it "solves itself", an example is that the Seeeduino XIAO was not supported by PlatformIO a few months ago but is now.

The Seeeduino XIAO Wiki, while mentioning that the XIAO is now supported, does still have instructions for adding the board manually to PlatformIO. Perhaps they would help you with your Adafruit Metro ESP32-S2.

BTW, I was fortunate to get that video released when I did. We were having our first storm of the winter and about 35 minutes after I published it we lost electricity (although my collection of UPSs kept me going) and didn't get it back until the evening!

Neither snow nor rain nor heat nor gloom of night stays the DroneBot Workshop from the swift upload of their PlatformIO video (with apologies to the US Post Office LOL)

😎

Bill

.

 

 

"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
Centari, Spyder, huckOhio and 1 people reacted
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@dronebot-workshop

Is it me or is the link to the article accompanying the video not reachable?

Link to Article 

SteveG


   
ReplyQuote
huckOhio
(@huckohio)
Member
Joined: 5 years ago
Posts: 180
 

Didn't work for me.


   
ReplyQuote
(@dronebot-workshop)
Workshop Guru Admin
Joined: 5 years ago
Posts: 1076
Topic starter  
Posted by: @codecage

Is it me or is the link to the article accompanying the video not reachable?

Posted by: @huckohio

Didn't work for me.

Ooops - I blame it on some bozo who should check his typing before he posts things!

😳

Thanks for pointing that out, I fixed it here and on YouTube.

😎

Bill

"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
ReplyQuote
(@scuba-dev-guy)
Member
Joined: 3 years ago
Posts: 3
 

I recently got WSL2 setup on my computer, which turned out to be a huge PITA. Must have watched at least five different videos that walked through the process step by step and it still did not work on my computer. Kept at it though and it seems to be working correctly now.

I had also heard about PlatformIO and was looking for videos on that as well and then the very next day this video is released. Looking forward to Wed when I will have some time to set it up and try it out. 


   
ReplyQuote
Spyder
(@spyder)
Member
Joined: 5 years ago
Posts: 846
 

Thanks Bill !

I really like the idea of having only one IDE to be completely confused by rather than a dozen


   
ReplyQuote
(@sj_h1)
Member
Joined: 4 years ago
Posts: 167
 

What about debug. It would seem to me the best reason to use PIO would be the debug feature. I would love to see something on that.

 


   
ReplyQuote
(@dronebot-workshop)
Workshop Guru Admin
Joined: 5 years ago
Posts: 1076
Topic starter  

@sj_h1

I had actually planned on putting Debug into the video and article but it was getting too long, plus this was a "getting started" video, and debug is not a beginner's tool.

I will include it in the next PlatformIO video.

😎

Bill

"Never trust a computer you can’t throw out a window." — Steve Wozniak


   
Centari reacted
ReplyQuote
(@ramon)
Member
Joined: 3 years ago
Posts: 7
 

Thank you for this introduction to PlatformIO, i didn't knew abouth it before and it looks very good, easy and usefull.

I've replaced the original Arduino IDE a long time ago for Sublime Text 3 with the so called Stino plugin, but it sometimes has some bugs like it can't find the librarie folders or even Arduino.h or Wire.h but besides that it works fine.

I'm sure i gonna use and explore PlatformIO for the next few weeks.

 

Greetings Ramon

 

 


   
ReplyQuote
noweare
(@noweare)
Member
Joined: 4 years ago
Posts: 119
 

The platformio website talks a lot about platfromio core (cli) which is the command line interface whereas platfromio IDE is the graphical interface. It can be confusing if you don't realize that and your trying to get help.


   
ReplyQuote
Centari
(@centari)
Member
Joined: 4 years ago
Posts: 44
 

first time actually posting, hope I get it right.  I just got done with the video and install process.  Much Thanks!

First point;  If installing on Linux, watch the error messages when compiling. I ended up with

"Warning! Please install `99-platformio-udev.rules`.
More details: https://docs.platformio.org/page/faq.html#platformio-udev-rule s"

which scrolled rather quickly.  I just barely caught it.  Just follow the More details link.  The fix is well explained and copy paste solution in your terminal.

 

Second point;  Functions can be written at the end of the program, but if you choose to do so you need a 'function prototype' at the top in the global variables part of the program.  (ahead of 'void setup()' ).  It consists of the return type / function name / (variable(s) type(s) passed to the function).

In the below shortened code with few comments, similar to what Mr. DroneBot gave us, both the function, and function prototype are commented for an example.  This habit is useful when you start writing header files and functions in separate files on larger programs.  It leads to being able to re-use code (functions and classes) that you've already written once, and not have to parse it out of a monolithic monster program.

I ran it in PlatformIO to make sure my memory was still working and it worked fine.  (not the machines memory, definitely mine. They say memory is the second thing to go..... I can't quite remember what the first thing was..... )  Classes are prototyped the same way as functions in header files, as I recall.  In the next week or two, I'll try to make a 'real' program to present as an example.   Hope this helps, wish me luck.  (I took a couple C courses over 20 years ago, and dropped it when they kept filling up the C++ courses without letting me in.  I was supposed to have priority seating after completing the C courses.  Rather frustrating at the time.  In short, I'm no guru.  Just throwing in my 2 cents hoping it may be useful.)

 

#include <Arduino.h>

 

// function prototype
void blink_led(int,int);

 

int LEDpin=13;

 

void setup() {
// put your setup code here, to run once:
pinMode(LEDpin,OUTPUT);
}

 

void loop() {
// put your main code here, to run repeatedly:
for(int x=1;x<8;x++){
blink_led(LEDpin,500);
}

 

for(int x=1;x<4;x++){
blink_led(LEDpin,200);
}
}

 

// function, prototyped above.
void blink_led(int LED,int delaytime)
{
digitalWrite(LED,HIGH);
delay(delaytime);
digitalWrite(LED,LOW);
delay(delaytime);
}
 

   
bobcroft and codecage reacted
ReplyQuote
noweare
(@noweare)
Member
Joined: 4 years ago
Posts: 119
 

Another thing I like is that in PIO I don't have to make sure the serial port in enabled when downloading. It could just be a linux thing but in Arduino I would try to download but couldn't because the serial port was unchecked.

A couple of other things I like include the open/closed bracket lines that match up.   And you know how the  arduino ide would have the objects files in a temp directory somewhere. Well, they are in your project with PIO. I guess Arduino just didn't want to overwhelm the user with a lot of directories.

What I do have to figure out is the *.json files, what all those settings really mean and what's available. I think you have to know those to get the most out of PIO.

 

 


   
ReplyQuote
Page 1 / 5