Platformio on the Raspberry Pi

platformioI’ve recently, thanks to some toys sent to me by Alex of raspi.tv, Aaron of PiSupply & Gareth of 4tronix (great guys, grovel, smarm, grovel), Lisa of Lisa fame (Ta muchly) & Digikey (thank you social media person) come into quite a bit of Arduino hardware which needs programming to do something useful. As i’m set in my ways & too old to change I prefer to work in a text environment with 1 to many terminal windows open rather than use an IDE so instead of using the Arduino IDE I looked around for something that was more like the traditional method of software development that I prefer. I remembered that I had stumbled across PlatformIO a few months ago when I was testing that the AVR part of project would still build after a few changes that i’d made to handle ARM devices. It doesn’t do to break other peoples code just so that yours will build. At the time I was quite impressed with it although I only had a quick play with it and once i’d checked I hadn’t broken other people’s code I put it to one side other than telling other people to give it ago and basically fanboi’ing it. :)

As i’d misplaced the sd card for my Raspberry Pi Model B+ that i’d installed PlatformIO on the first thing I had to do was install it on my current dev sd card. If you are installing PlatformIO on x86 Linux it installs exactly as described on the documentation but on the Raspberry Pi (Raspbian Wheezy), and maybe other ARM devices it requires you to install three things first (or later unless you want to have to check the FAQ to see how to fix the errors when you first try to use platformio in anger) see:https://github.com/platformio/platformio/issues?utf8=%E2%9C%93&q=error+while+loading+shared+libraries and avrdude erroring due to missing libftdi shared lib.

Install libmpc-dev, libelf1 & libftdi1

sudo apt-get install libmpc-dev libelf1 libftdi1

Once those three packages are installed follow the Super Quick (Mac/Linux) insttructions. e.g.

sudo python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"

After the install is completed you are ready to start using platformio to build & upload yor program to your Arduino.

First you need to create a subdirectory to hold all your Arduino projects. For reasons mine is called Thing but obviously you can use any name you want. It would probably be a good idea to call it Arduino :)

cd ~ ; mkdir Arduino ; cd Arduino

and then create a subdir for your actual project. i’m building a cheerlights example by Carl Monk

mkdir cheerlights ; cd cheerlights

and then initialise platformio for the project, the Arduino that i’m using is an Uno so i’ll pass that information to the platformio initialise command.

platformio init --board uno

platformio-init
Put your source code( .c or .cpp or .h or .ino or … into the src directory

platformio-src
and then build the source using the run command

platformio-run

uh oh an error. i’m missing at least one library that cheerlights.ino needs.
platformio-uhoh1
Luckily this is where platformio really shines. Installing libraries is just like using a standard package manager such as apt.

I need at least the U8glib library so the judicious use of the platformio library search function will tell me what to install.

platformio lib search U8*

platformio-libsearch
and to install the required lib pass it’d ID number which in this case is 7 to the platformio library install command.

platformio lib install 7

platformio-libinst
[i happen to know that i’m also missing FastLED so I installed that too]

After about 400 seconds give or take the program is uploaded to the Arduino & it’s little RGB pixel starts changing colour based on the current cheerlights colour

avrdude: Version 6.1-svn-20130917, compiled on Nov 30 2013 at 16:47:29
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch

System wide configuration file is "/home/pi/.platformio/packages/tool-avrdude/avrdude.conf"

Using Port                    : /dev/ttyUSB0
Using Programmer              : arduino
Overriding Baud Rate          : 115200
AVR Part                      : ATmega328P
Chip Erase delay              : 9000 us
PAGEL                         : PD7
BS2                           : PC2
RESET disposition             : dedicated
RETRY pulse                   : SCK
serial program mode           : yes
parallel program mode         : yes
Timeout                       : 200
StabDelay                     : 100
CmdexeDelay                   : 25
SyncLoops                     : 32
ByteDelay                     : 0
PollIndex                     : 3
PollValue                     : 0x53
Memory Detail                 :

Block Poll               Page                       Polled
Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

Programmer Type : Arduino
Description     : Arduino
Hardware Version: 3
Firmware Version: 4.4
Vtarget         : 0.3 V
Varef           : 0.3 V
Oscillator      : 28.800 kHz
SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: reading input file ".pioenvs/uno/firmware.hex"
avrdude: writing flash (20006 bytes):

Writing | ################################################## | 100% 3.00s

avrdude: 20006 bytes of flash written
avrdude: verifying flash memory against .pioenvs/uno/firmware.hex:
avrdude: load data flash data from input file .pioenvs/uno/firmware.hex:
avrdude: input file .pioenvs/uno/firmware.hex contains 20006 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 2.25s

avrdude: verifying ...
avrdude: 20006 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 (E:00, H:00, L:00)

avrdude done.  Thank you.

==================================================================== [SUCCESS] Took 359.54 seconds ====================================================================
[email protected] ~/Thing/cheerlights $

[i need to ask permission to post a photo of this device but if given it i’ll put it here]

This only scratches the surface of installing and using PlatformIO, you can do things like use the same source tree and build for multiple targets but listing the various boards in the init command, you can use private libraries as well as those in the platformio library repo & all kinds of other fun things including that it works not only with most arduino boards it also can build for lots of other boards too see: http://platformio.org/#!/boards. If you like the idea of platformio then I recommend that you read through the docs and also although it works very well on a model B/B+ Raspberry Pi as it’s written in python, lots and lots of Python it’s a little slow so i’d recommend using a Pi2B. Yes I am a PlatformIO Fanboi :)

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

 

russelldavis.org © 2014 Frontier Theme