Arduino development on the command line: vim + platformio

arduino_platformio.png

Introduction

Last time It was build and upload from the command line using ʻino, but this time I made a note of the method using platformio`.

About Platformio

Like ʻino, platformio` is introduced on the official page of arduino. Currently, I mainly use this.

The great thing about platformio is that you don't need an IDE. ʻIno required a separate IDE, but platformio` is not. It will be automatically downloaded as a package. Even better, it supports a variety of embedded boards. It seems that the famous places are perfectly suppressed, and recent boards such as STM32 Nucleo are also supported. (http://platformio.org/#!/boards)

Like ʻino, it is written in python and has no major dependencies so it is easy to install. I think it's easier than ʻino because there is no IDE installed.

Introduction of platformio

udev settings (Ubuntu only)

platformio also has a serial monitor function. However, in the case of ubuntu, it is necessary to add the file to the ʻudev` rule due to the authority. (http://docs.platformio.org/en/latest/platforms/atmelavr.html)

Linux Users: Don’t forget to install “udev” rules file 99-platformio-udev.rules (an instruction is located in the file).

[ʻUdevrules file](https://github.com/platformio/platformio/blob/develop/scripts/99-platformio-udev.rules) is fine, but there are sample projects for various boards, sogithubDownload the main body from.

#DL platformio project
$ git clone https://github.com/platformio/platformio.git

Copy 99-platformio-udev.rules in the project

#Copy the udev rules file to your rules folder
$ sudo cp ./platformio/script/99-platformio-udev.rules /etc/udev/rules.d/

Install platformio

Install under the virtual environment of virtualenv. (The virtualenv environment construction is noted in here, so please take a look if you are interested.)

#Create virtualenv
$ mkvirtualenv --no-site-package platformio
(platformio)$ pip install platformio
(platformio)$ pip install --egg scons   #A build tool that replaces make. I think this is also necessary.

Build and upload

Look up the board name

If you specify a board in the initialization option (--board = <board name>), various settings will be made. If you don't know your board name, you can see the list, or you can look it up on the Site (http://docs.platformio.org/en/latest/platforms/atmelavr.html#boards).

(platformio) $ platformio boards
    Platform: atmelavr
    ---------------------------------------------------------------------------
    Type                  MCU            Frequency  Flash   RAM    Name
    ---------------------------------------------------------------------------
    flora8                atmega32u4     8Mhz      28Kb    2Kb    Adafruit Flora
    protrinket3ftdi       atmega328p     16Mhz     28Kb    2Kb    Adafruit Pro Trinket 3V/12MHz (FTDI)
    protrinket3           atmega328p     12Mhz     28Kb    2Kb    Adafruit Pro Trinket 3V/12MHz (USB)
        #Omitted below

You can squeeze it with grep, or you can squeeze it with additional options. I'm ʻuno`, so I'll search here.

(platformio) $ platformio boards | grep uno
    uno                   atmega328p     16Mhz     31Kb    2Kb    Arduino Uno

As another example, nano.

(platformio) $ platformio boards | grep nano
    nanoatmega168         atmega168      16Mhz     14Kb    1Kb    Arduino Nano ATmega168
    nanoatmega328         atmega328p     16Mhz     30Kb    2Kb    Arduino Nano ATmega328

You can specify the type item that appears in the search with the board option.

Create a project: platformio init

Creating a project is easy. platformio init --board = <board name> will generate an empty subfolder and project file ( platformio.ini). The format of platformio.ini is INI file, and there are various options for detailed settings. (http://docs.platformio.org/en/latest/projectconf.html)

Create an empty folder for your project

(platformio) $ mkdir uno; cd ./uno

Creating an arduino project (this time generated with a general uno board)

(platformio) $ platformio init --board=uno
    #Ask if you want to enable automatic uploads.
    #later`platformio.ini`You can also edit and change the file
    Would you like to enable firmware auto-uploading when project is successfully built using `platformio run` command?
    Dont forget that you can upload firmware manually using `platformio run --target upload` command. [y/N]: y

    #Guidance that you can change the project directory
    The current working directory /home/hoge/uno will be used for the new project.
    You can specify another project directory via
    `platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.

    #Where to make a confit file`/home/hoge/uno`But is it okay? Question.
    #Don't hesitate`y`
    The next files/directories will be created in /home/hoge/uno
    platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-|
    src - Put your source code here
    lib - Put here project specific or 3-rd party libraries
    Do you want to continue? [y/N]: y

    #success
    Project has been successfully initialized!
    Useful commands:
    `platformio run` - process/build project from the current directory
    `platformio run --target upload` or `platformio run -t upload` - upload firmware to embedded board
    `platformio run --target clean` - clean project (remove compiled files)

Look up serialport names: platformio serialports list

The built firmware is uploaded via the serial port. Since the default is / dev / ttyUSB0, if you connect Arudino, the update will fail if it is left as it is because the port name is different. Therefore, it is necessary to check the serial port name and specify it in platformio.ini. There are many ways to find out, but try using the platformio command.

The platformio serialports list command displays a list of serial information. You should know if it is an Arduino port from the Description item. Mostly / dev / ttyACM0 for Ubuntu andtty.usbserial-*for Mac.

(platformio)$ platformio serialports list
    :   #abridgement
    /dev/ttyACM0
    ----------
    Hardware ID: USB VID:PID=1a86:7523
    Description: QinHeng Electronics USB2.0-Serial

Add the Arduino serial port name to platformio.ini. The option name is upload_port.

(platformio)$ echo -e "\nupload_port = /dev/ttyACM0" >> platformio.ini

Write source

The usual LED blinking and serial display. Put the source in ./src.


(platformio)$ vim ./src/sketch.ino
    #define LED_PIN 13
    void setup() {
        pinMode(LED_PIN, OUTPUT);
        Serial.begin(9600);
    }
    void loop() {
        Serial.println("Hello Arduino");
        digitalWrite(LED_PIN, HIGH); delay(100);
        digitalWrite(LED_PIN, LOW);  delay(900);
    }

Try to build: platformio run

If there is no build target platform package, a download message will be displayed, so enter y to get it. The download destination is ~ / .platformio / packages.


(platformio)$ platformio run
    If you like PlatformIO, please:
    - follow us on Twitter to stay up-to-date on the latest project news > https://twitter.com/PlatformIO_Org
    - give us a star on GitHub > https://github.com/platformio/platformio
    Thanks a lot!

    [Wed May  6 13:06:53 2015] Processing autogen_uno (targets: upload, platform: atmelavr, board: uno, framework: arduino)
    ---------------------------------------------------------------------------------------------------------
    The platform 'atmelavr' has not been installed yet. Would you like to install it now? [y/N]: y

    Installing toolchain-atmelavr package:
    Downloading  [####################################]  100%
    Unpacking  [####################################]  100%
    Installing tool-avrdude package:
    Downloading  [####################################]  100%
    Unpacking  [####################################]  100%
    Installing framework-arduinoavr package:
    Downloading  [####################################]  100%
    Unpacking  [####################################]  100%
    Installing tool-micronucleus package:
    Downloading  [####################################]  100%
    Unpacking  [####################################]  100%
    The platform 'atmelavr' has been successfully installed!

When Download is finished, it will be built and uploaded as it is. When you look at the main body, the LED should be blinking.

        : #abridgement
    Reading | ################################################## | 100% 0.13s

    avrdude: verifying ...
    avrdude: 998 bytes of flash verified

    avrdude: safemode: lfuse reads as 0
    avrdude: safemode: hfuse reads as 0
    avrdude: safemode: efuse reads as 0
    avrdude: safemode: Fuses OK (H:00, E:00, L:00)

    avrdude done.  Thank you.

    =================================== [SUCCESS] Took 64.38 seconds ===================================

Try using a serial monitor: platformio serialports monitor

platformio also has a serial monitor function as standard. You don't need to install another minicom or picocom, but I think this is where you have different tastes.

(platformio)$ platformio serialports monitor -p /dev/ttyACM0 -b 9600
    #monitor start
    #Ctrl to exit+ ]
    --- Miniterm on /dev/ttyACM0: 9600,8,N,1 ---
    --- Quit: Ctrl+]  |  Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
    Hello Arduino
    Hello Arduino
    Hello Arduino
    Hello Arduino

Other features

You can easily upload packages and upgrade the main unit from commands.

--platformio upgrade: Update of platformio

(platformio)$ platformio upgrade
    You're up-to-date!
    PlatformIO 1.4.0 is currently the newest version available.

--platformio update: Package update

(platformio)$ platformio update
    Platform atmelavr
    --------
    Updating toolchain-atmelavr package:
    Versions: Current=2, Latest=2 	 [Up-to-date]
    Updating tool-avrdude package:
    Versions: Current=3, Latest=3 	 [Up-to-date]
    Updating framework-arduinoavr package:
    Versions: Current=16, Latest=16 	 [Up-to-date]
    Updating tool-micronucleus package:
    Versions: Current=1, Latest=1 	 [Up-to-date]

In addition, external libraries can be easily installed and there are various functions. For more information, please read the Official Document.

Summary

Here are some basic commands to play right away.

command Description
platformio boards Board list display
platformio init --board=<Board name> Project creation
platformio run Build(Automatic upload depending on settings)
platformio run --target=upload Build and upload
platformio run --target=clean clean
platformio serialports list Serial port list display
platformio serialports monitor -p <device> -b <baud rate> Serial monitor

The end

In the future, I would like to import external libraries and try boards from other platforms. Anyway, I'm happy to be able to easily develop various embedded boards with one command line.

-Arduino IDE v1.6.4 (2015/05/07) from the command line It seems that it supported library installation etc. Still, if you mainly develop from the command line, I think ʻinoandplatformio` are easier to use.

Recommended Posts

Arduino development on the command line: vim + platformio
Keep getting RSS on the command line
You search commandlinefu on the command line
Quickly display the QR code on the command line
Syntax highlighting on the command line using Pygments
Arduino development: vim + ino
Convert XLSX to CSV on the command line
Operate Route53 on the command line using AWS-CLI.
Think about the selective interface on the command line
Search for large files on Linux from the command line
Python standard module that can be used on the command line
Get, test, and submit test cases on the command line in the AtCoder contest
vim command
Look up your Mac's Wi-Fi network name (SSID) on the command line
Correspondence memo when the direction key cannot be used on the python command line
Frequently used (personally) notes on the tar command
The story of misreading the swap line of the top command
My thoughts on python2.6 command line app template
How to pass arguments when invoking python script from blender on the command line
Steps to use the AWS command line interface (Python / awscli) on Mac OS X
How to create an article from the command line
Open Chrome version of LINE from the command line [Linux]
Execute the command on the web server and display the result
Multiply PDF by OCR on command line on Linux (Ubuntu)
(Remember quickly) How to use the LINUX command line
I tried to notify the honeypot report on LINE