PlatformIO for Arduino on Linux Command Line

So I had a challenge that required me to keep running up and downstairs as I was troubleshooting a new project. I’m having a problem with a temperamental water heater and decided to monitor it remotely. I have a photo-resistor taped to the water heater’s status LED and I use an Arduino Nano to capture and time the LED flashes and gaps. Then I send the results out the Nano’s USB interface to a Linux server I have running in the basement, conveniently close to the water heater.

Not having a laptop, I was using minicom to watch the USB traffic remotely from my desktop on the main floor of the house. Based on my observations of the USB traffic and minimal documentation on the Honeywell WV4460 temperature control, I’d come up with a programming change, take the stairs to the basement, disconnect the USB, pull the Nano and trek back upstairs to reprogram and flash it. While this started to become a chore, things got a little better as I employed a second Nano I had laying around. Now I’d reprogram the second board and just swap them. I still had to run up and down the stairs, but other than the device port changing every time I swapped out a board, it was a bit easier.

About the 10th trip back downstairs I had a thought. (First I thought – how many times is this gonna take to get it right…) My next thought was recalling that a while back I installed PlatformIO and Atom on my windows machine just to take it for a spin programming ESP8266 boards. Since it’s supposed to work with Arduinos and run on Linux so I wondered if it had a CLI. (My Linux server is CLI only with no GUI). Sure enough, it did and since I already have pip installed –
Sudo pip install -U platformio

The directory layout under Linux is the same as on Windows so I created an Arduino workspace named wheat_v3 (for WaterHEATer version 3) and initialized it.
cd ./wheat_v3
platformip init
platformio init --board=nanoatmega328

I then created a main.cpp in the src directory and did a quick copy/past of the Arduino native code, made some minor changes and saved it. Then from the ./wheat_v3 directory this is what my edited platformio.ini looks like:

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
upload_port = /dev/ttyUSB1

I ran platformio run –target upload a few times and cleaned up a few errors. Once the issues were cleaned up I got a clean compile and upload! Now each time I need to make a change to the code on the Nano I just kill the server side application to release the USB port and compile/upload. This is so fast and easy you’ll love it if you’re interfacing a micro-controller with Linux.

Leave a Reply