Preamble
PlatformIO is a python tool to build and upload sketches for multiple Hardware Platforms, at the moment of writing these are Arduino/AVR based boards. This is the only tool working with Raspberry Pi running Arch Linux so far, and I have been searching for some tool like this for a long time.
NB: The over-bearing minion is there because every time my little one sees it, she giggles.
Installation
Install virtualenv first, detailed instruction here.
1 2 3 |
sudo pacman -S python2-virtualenv |
Its recommended to use a virtual environment because platformio uses python2 because its based on SCons which does not support python3.
1 2 3 4 5 |
$ virtualenv2 --python=python2 venv #for python2 $ source ./venv/bin/activate $ pip install platformio |
You may need to install PlatformIO with python installer script for it to work.
1 2 3 |
sudo python2 -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" |
Usage
-
Ativate virtualenv
123source ~/venv/bin/activate -
Install platforms
123platformio platforms install atmelavr -
Start with a empty directory
1234platformio init --board=uno --board=megaatmega2560#platformio boards -
Search for the board types using `platformio boards` command if needed.
123platformio boards |grep mega2560 -
Modify platformio.ini file if needed.
12345678910111213platform = atmelavrframework = arduinoboard = unotargets = upload[env:ArduinoMega2560]platform = atmelavrframework = arduinoboard = megaatmega2560upload_port = /dev/ttyACM0targets = upload - Put your source code *.pde or *.ino files to src directory.
-
Link rest of library files in lib directory, link the whole directory instead of individual .cpp and .h files.
1234cd ./lib;ln -s ~/Arduino/libraries/LGDP4535/ln -s ~/Arduino/libraries/zTouchScreen/ -
Change working directory to the project’s root where is located Project Configuration File (platformio.ini) and use these commands:
12345678# process/build project from the current directoryplatformio run# if you don't have enabled auto-uploading, then you can upload firmware manuallyplatformio run --target upload# to clean cached/compiled filesplatformio run --target cleanOutput from platformio run:
123456789101112131415161718192021tan@taurus ~/proj/arduino/coordinate$ source ~/venv/bin/activate(venv)tan@taurus ~/proj/arduino/coordinate$ platformio run[Thu Oct 15 11:22:19 2015] Processing megaatmega2560 (platform: atmelavr, board: megaatmega2560, framework: arduino)--------------------------------------------------------------------------------avr-g++ -o .pioenvs/megaatmega2560/src/tmp_ino_to.o -c -fno-exceptions -fno-threadsafe-statics -g -Os -Wall -ffunction-sections -fdata-sections -MMD -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO_AVR_MEGA2560 -DARDUINO=10605 -DPLATFORMIO=020302 -I.pioenvs/megaatmega2560/FrameworkArduino -I.pioenvs/megaatmega2560/FrameworkArduinoVariant -I.pioenvs/megaatmega2560/Adafruit_GFX -I.pioenvs/megaatmega2560/LGDP4535 -I.pioenvs/megaatmega2560/zTouchScreen src/tmp_ino_to.cppavr-g++ -o .pioenvs/megaatmega2560/firmware.elf -Os -mmcu=atmega2560 -Wl,--gc-sections,--relax .pioenvs/megaatmega2560/src/tmp_ino_to.o -L.pioenvs/megaatmega2560 -Wl,--start-group -lm .pioenvs/megaatmega2560/libFrameworkArduinoVariant.a .pioenvs/megaatmega2560/libFrameworkArduino.a .pioenvs/megaatmega2560/libAdafruit_GFX.a .pioenvs/megaatmega2560/libLGDP4535.a .pioenvs/megaatmega2560/libzTouchScreen.a -Wl,--end-groupavr-objcopy -O ihex -R .eeprom .pioenvs/megaatmega2560/firmware.elf .pioenvs/megaatmega2560/firmware.hex"avr-size" --mcu=atmega2560 -C -d .pioenvs/megaatmega2560/firmware.elfAVR Memory Usage----------------Device: atmega2560Program: 15002 bytes (5.7% Full)(.text + .data + .bootloader)Data: 340 bytes (4.2% Full)(.data + .bss + .noinit)========================= [SUCCESS] Took 1.50 seconds =========================Output for upload:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889(venv)tan@taurus ~/proj/arduino/coordinate$ platformio run --target upload[Thu Oct 15 11:22:26 2015] Processing megaatmega2560 (platform: atmelavr, board: megaatmega2560, framework: arduino)--------------------------------------------------------------------------------BeforeUpload(["upload"], [".pioenvs/megaatmega2560/firmware.hex"])Auto-detected UPLOAD_PORT/DISK: /dev/ttyACM0"/home/tan/.platformio/packages/tool-avrdude/avrdude" -v -p atmega2560 -C "/home/tan/.platformio/packages/tool-avrdude/avrdude.conf" -c wiring -b 115200 -D -P /dev/ttyACM0 -U flash:w:.pioenvs/megaatmega2560/firmware.hex:iavrdude: Version 6.1, compiled on Mar 24 2014 at 14:07:14Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/Copyright (c) 2007-2014 Joerg WunschSystem wide configuration file is "/home/tan/.platformio/packages/tool-avrdude/avrdude.conf"User configuration file is "/home/tan/.avrduderc"User configuration file does not exist or is not a regular file, skippingUsing Port : /dev/ttyACM0Using Programmer : wiringOverriding Baud Rate : 115200AVR Part : ATmega2560Chip Erase delay : 9000 usPAGEL : PD7BS2 : PA0RESET disposition : dedicatedRETRY pulse : SCKserial program mode : yesparallel program mode : yesTimeout : 200StabDelay : 100CmdexeDelay : 25SyncLoops : 32ByteDelay : 0PollIndex : 3PollValue : 0x53Memory Detail :Block Poll Page PolledMemory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------eeprom 65 10 8 0 no 4096 8 0 9000 9000 0x00 0x00flash 65 10 256 0 yes 262144 256 1024 4500 4500 0x00 0x00lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00Programmer Type : WiringDescription : WiringProgrammer Model: AVRISPHardware Version: 15Firmware Version Master : 2.10Vtarget : 0.0 VSCK period : 0.1 usavrdude: AVR device initialized and ready to accept instructionsReading | ################################################## | 100% 0.01savrdude: Device signature = 0x1e9801avrdude: safemode: lfuse reads as FFavrdude: safemode: hfuse reads as D0avrdude: safemode: efuse reads as FFavrdude: reading input file ".pioenvs/megaatmega2560/firmware.hex"avrdude: writing flash (15002 bytes):Writing | ################################################## | 100% 2.42savrdude: 15002 bytes of flash writtenavrdude: verifying flash memory against .pioenvs/megaatmega2560/firmware.hex:avrdude: load data flash data from input file .pioenvs/megaatmega2560/firmware.hex:avrdude: input file .pioenvs/megaatmega2560/firmware.hex contains 15002 bytesavrdude: reading on-chip flash data:Reading | ################################################## | 100% 1.93savrdude: verifying ...avrdude: 15002 bytes of flash verifiedavrdude: safemode: lfuse reads as FFavrdude: safemode: hfuse reads as D0avrdude: safemode: efuse reads as FFavrdude: safemode: Fuses OK (E:FF, H:D0, L:FF)avrdude done. Thank you.========================= [SUCCESS] Took 6.12 seconds ========================= -
Project Structure after processing
123456789101112131415./.pioenvs/├── ArduinoMega2560│ ├── FrameworkArduino│ ├── FrameworkArduinoVariant│ └── src├── ArduinoUno│ ├── FrameworkArduino│ ├── FrameworkArduinoVariant│ └── src└── megaatmega2560├── FrameworkArduino├── FrameworkArduinoVariant└── src -
Deactivate virtualenv
123deactivate
Work with ArduinoJson
ArduinoJson works can be installed from Arduino IDE library manager. Issue tracker here.
The easy way
1 2 3 |
platformio lib --global install "ArduinoJson" |
The hard way
- Install using the library without Arduino with instruction adapted from official wiki.
-
Step 1: Download source code into platform project lib folder:
123git clone https://github.com/bblanchon/ArduinoJson.git -
Generate the Makefile for your environment
1234cd ArduinoJsoncmake . -
Step 3: Build
123make - delete test folder, alternatively install with zip package.
-
update library
123platformio lib update - all set for platformio compile.
Notes
-
If you are running Archlinux and running into this error: libncurses.so.5: cannot open shared object file, refer here.
1234rm ~/.platformio/packages/tool-avrdude/avrdudeln -s /usr/bin/avrdude ~/.platformio/packages/tool-avrdude/avrdude -
For the following error: error while loading shared libraries: libreadline.so.6: cannot open shared object file: No such file or directory It seems libreadline.so.7 is backward compatible enough for most utilities to keep working after running:
123sudo ln -s /usr/lib/libreadline.so.7 /usr/lib/libreadline.so.6 - Works with Raspberry Pi running Arch Linux.
- Does not work without virtualenv, Scons error – got to do with the python3 issue.
- Does not work with Arduino IDE running.
- I often ran into this problem: the serial port will be disabled after a while, i.e. – disappeared from ls /dev/ and Arduino IDE port listing. My working solution is to unplug and then plug it into another USB port.
OCT
About the Author:
Beyond 8 hours - Computer, Sports, Family...