Close

#1 - PlatformIO

A project log for Game-o-Tron Mini

A roughly credit card sized gaming handheld

david-boucherDavid Boucher 07/26/2017 at 19:270 Comments

Usually, developing for one of the Teensy boards involves installing the Arduino IDE (https://www.arduino.cc/en/Main/Software) and then installing Teensyduino (https://www.pjrc.com/teensy/teensyduino.html) on top of that to add Teensy support. There's not really anything wrong with that, but I don't like the Arduino editor and prefer to use my own choice of editor and compile and upload from the command line.

In the past I have done this by extracting the relevant files from an Arduino/Teensyduino install and writing a custom makefile. Since version 1.5 of the Arduino IDE, there is also the option of compiling from the command line without making any modifications (see https://playground.arduino.cc/Learning/CommandLine).

A few months ago, I discovered PlatformIO Core (http://platformio.org/), which takes the strain out of setting up a build environment for Arduino, Teensy and a lot of other micro controllers and IoT devices and this is what I will be using for this project.

To give you a simple example, here is what is needed for the classic "Blink" program:

[env:teensy31]
platform = teensy
board = teensy31
framework = arduino

(The Teensy 3.1 and 3.2 are functionally identical, so the 3.2 uses the same board specification as the 3.1)

/**
 * Blink
 *
 * Turns on an LED on for one second,
 * then off for one second, repeatedly.
 */
#include "Arduino.h"
#ifndef LED_BUILTIN
#define LED_BUILTIN 13
#endif
void setup()
{
  // initialize LED digital pin as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BUILTIN, HIGH);
  // wait for a second
  delay(1000);
  // turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, LOW);
   // wait for a second
  delay(1000);
}
platformio run -t upload

This will download the necessary files, compile the project and upload it, resulting in a Teensy with a blinking LED.

Of course, this is the simplest possible example, much more complex projects are possible and the PlatformIO site has full documentation on this. There is also a full IDE but I have not tried that.


Discussions