In this post, we will see how to program Arduino and many other processors with the popular Open Source text editor Atom and the PlatformIO IDE package, a programming environment specially designed for IoT applications.
By now you know that we are big fans of Arduino and the entire ecosystem it has generated. But we frequently say that one of its weakest parts is its IDE. Despite its multiple updates, it remains very limited and lacks most of the features we would expect in a current development environment.
On the blog, we have already seen several alternatives to the standard Arduino IDE, such as Programming Arduino with Eclipse, or The best IDE for Arduino, Visual Studio with Visual Micro. This time it’s Atom + PlatformIO’s turn.
Atom is an Open Source text editor developed by GitHub Inc, which has recently become very popular. This is due, among other reasons, to its enormous capacity for customization and extension through modules.
On the other hand, PlatformIO is a development environment designed for IoT applications, which runs on the Atom or Microsoft Visual Studio Code editor. It is compatible with over 400 development boards, including Arduino (AVR), ESP8266, STM32.
Install Atom
The first step is to install the Atom text editor. The installation is very simple, just go to the address https://atom.io/ and download the installer for your operating system.
Run the installer and wait patiently for it to install (it can be a bit of a long process, so be patient).
Install PlatformIO
Now we are going to install PlatformIO IDE in Atom. To do this, start Atom and select “Install a Package”, then “Open Installer” and in the text box type “platformio-ide”.
Several results will appear in the search. Make sure to select the “platformio-ide” package correctly, and click on “Install”.
Wait patiently for the PlatformIO IDE to install (it takes quite a while). During the installation, a message will indicate that we need to install Clang, which allows for code completion while writing.
Leave the PlatformIO installer as it is, and on the other hand, download Clang from this address and install it. In the process, make sure to select the option “Add LLVM to system path”.
We can continue with the installation of PlatformIO. Go back to Atom, and wait patiently again for the polar ice caps to thaw as the process takes a while.
Once the installation process is complete, Atom will indicate that we need to restart the program. Accept, and close Atom.
We have now successfully set up Atom + PlatformIO!
Create our first project in PlatformIO
Let’s test our new Atom + PlatformIO IDE environment by starting a new project, to make sure everything is correctly configured.
When you open Atom, a PlatformIO tab will appear. Select ”+ New Project” to create a new PlatformIO project. If at any point it asks you to register, you can do so, or simply click “Skip”.
In the next window, select a board and the folder where you want to save the project.
If everything has gone well, PlatformIO will display a message indicating that the project creation was successful.
The project has a basic structure
- platformio.ini, a file containing the project configuration
- src, a folder where we put our source code
- lib, a folder to add our own libraries
Blink on Arduino
Finally, let’s test by creating the “blink” program, which as we know is the equivalent to the “hello world” in Arduino, and simply makes the LED integrated into most development boards blink.
To do this, create a file containing our code by right-clicking on the “src” folder. Add a new file called “blink.ino”.
Inside, paste the code for the well-known blink, which simply makes the LED integrated in most Arduino boards blink.
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Now click on compile and check that the work is completed correctly. Finally, you can upload it to the board by clicking the corresponding button.
Download the code
All the code from this post is available for download on Github.