Skip to content

Setting up your Teensy development environment

24 October, 2012

Hello! Welcome to Sim Electronics. I will be gradually writing articles here about my experiences building custom hardware for X-Plane, using the excellent Arduino-compatible Teensy boards and whatever else I come across.

I’ll be ignoring the hardware in this article. This is about how to set up software on your computer so you can write Teensyduino code more easily. I’m writing this guide for Teensy/X-Plane users who are novice programmers, but it will apply for any Teensy or Arduino developers.

I’m using Windows but most of this will be useful on Mac and Linux too.

The official guide to setting up Teensyduino for X-Plane is here.

To summarise, these are the steps:

1 – Install the Arduino IDE, currently v1.0.1, from here. I’d recommend putting it in the same folder you’ll use for Teensy/Arduino projects, for example c:/dev/teensy/_arduino-1.0.1, so we can get to it easily with a much better code editor later. The underscore puts the folder at the top of alphabetically-sorted lists.

2 – Download Teensyduino, currently v1.09, from here. Install it into the Arduino IDE.

3 – Download the TeensyControls X-Plane plugin, currently v1.0, from here. Install it in your X-Plane directory.

4 – Open Arduino, load the TransponderBlink example code, set the ‘Board’ and ‘USB Type’ in the Tools menu to your Teensy model and ‘Flight Sim Controls’, plug in a Teensy, compile, update, launch X-Plane, and watch that little orange light blinking merrily away.

That’s it! You can now write code to link Teensy to X-Plane!

Still here?

**UPDATE** Well you shouldn’t be. I’m learning rapidly about writing Arduino code, and in two weeks I’ve come up with a much better way of using Qt than what I describe here. I’ll leave this here for posterity. **END UPDATE**

Well, yes, there is more to do if you like to keep your sanity. The Arduino IDE is a weird old program. I’ve never seen a code editor which uses the same symbol for l and 1 in the default font, or where shift+backspace acts as delete. It’s been purpose-built by the hardworking Arduino team, designed for simplicity to avoid overwhelming people who are new to programming. But it lacks the features and polish of a normal IDE, like very intelligent auto-complete, easily renaming things, 1s that don’t look like ls, more useful colour-schemes…

I use the Qt Creator IDE for writing Arduino code because I use it for writing X-Plane plugins, but you can probably apply this to other IDEs instead. I’m going to go ahead and give step-by-step instructions for using QT Creator for an easier Teensy/Teensyduino/Arduino programming experience.

Download Qt Creator. Make sure to get the open-source version, not the commercial evaluation version. Currently it is here. There are two choices: download just the IDE, or download the Qt SDK which includes the IDE and the GCC compiler. If you’re interested in writing standalone programs, Qt framework programs, or regular X-Plane plugins, you should get the SDK, but we’ll only need the IDE for Teensy/Arduino stuff.

In Qt Creator, create a ‘Plain C++ Project’, and give it a name like ‘Scratchpad’ or ‘Working project’. Put in your Arduino projects folder, ie c:/dev/teensy/Scratchpad

It will create two files: scratchpad.pro and scratchpad.cpp. You’ll never actually compile this project in Qt, but by creating a project we can get Qt Creator to find all the Arduino library files and nicely integrate them into your source code. Put #include into the scratchpad.cpp file and instantly all the Bounce keywords turn purple. Right-click on Bounce, pick ‘Follow symbol under cursor’, and Qt will open Bounce.h for you, and you can see for yourself exactly what functions you have to play with. Write Bounce myBounce; myBounce. and a helpful unobtrusive popup appears showing you the available member functions of Bounce. It makes writing code so much easier!

To make this happen, copy this lot into the scratchpad.pro file. Click on ‘show source’ to see the big blob of text:

#include "../_arduino-1.0.1/hardware/teensy/cores/usb_flightsim/usb_api.h"

INCLUDEPATH += ../_arduino-1.0.1/libraries/AccelStepper
INCLUDEPATH += ../_arduino-1.0.1/libraries/AltSoftSerial
INCLUDEPATH += ../_arduino-1.0.1/libraries/ArdOSC
INCLUDEPATH += ../_arduino-1.0.1/libraries/Bounce
INCLUDEPATH += ../_arduino-1.0.1/libraries/CapSense
INCLUDEPATH += ../_arduino-1.0.1/libraries/DmxSimple
INCLUDEPATH += ../_arduino-1.0.1/libraries/DogLcd
INCLUDEPATH += ../_arduino-1.0.1/libraries/EEPROM
INCLUDEPATH += ../_arduino-1.0.1/libraries/Encoder
INCLUDEPATH += ../_arduino-1.0.1/libraries/Ethernet
INCLUDEPATH += ../_arduino-1.0.1/libraries/Firmata
INCLUDEPATH += ../_arduino-1.0.1/libraries/FlexiTimer2
INCLUDEPATH += ../_arduino-1.0.1/libraries/FreqCount
INCLUDEPATH += ../_arduino-1.0.1/libraries/FreqMeasure
INCLUDEPATH += ../_arduino-1.0.1/libraries/FrequencyTimer2
INCLUDEPATH += ../_arduino-1.0.1/libraries/IRremote
INCLUDEPATH += ../_arduino-1.0.1/libraries/Keypad
INCLUDEPATH += ../_arduino-1.0.1/libraries/ks0108
INCLUDEPATH += ../_arduino-1.0.1/libraries/LedControl
INCLUDEPATH += ../_arduino-1.0.1/libraries/LedDisplay
INCLUDEPATH += ../_arduino-1.0.1/libraries/LiquidCrystal
INCLUDEPATH += ../_arduino-1.0.1/libraries/LiquidCrystalFast
INCLUDEPATH += ../_arduino-1.0.1/libraries/list.txt
INCLUDEPATH += ../_arduino-1.0.1/libraries/LowPower
INCLUDEPATH += ../_arduino-1.0.1/libraries/Metro
INCLUDEPATH += ../_arduino-1.0.1/libraries/MIDI
INCLUDEPATH += ../_arduino-1.0.1/libraries/MsTimer2
INCLUDEPATH += ../_arduino-1.0.1/libraries/NewSoftSerial
INCLUDEPATH += ../_arduino-1.0.1/libraries/OneWire
INCLUDEPATH += ../_arduino-1.0.1/libraries/Ping
INCLUDEPATH += ../_arduino-1.0.1/libraries/PS2Keyboard
INCLUDEPATH += ../_arduino-1.0.1/libraries/PWMServo
INCLUDEPATH += ../_arduino-1.0.1/libraries/SD
INCLUDEPATH += ../_arduino-1.0.1/libraries/Servo
INCLUDEPATH += ../_arduino-1.0.1/libraries/ShiftPWM
INCLUDEPATH += ../_arduino-1.0.1/libraries/SoftPWM
INCLUDEPATH += ../_arduino-1.0.1/libraries/SoftwareSerial
INCLUDEPATH += ../_arduino-1.0.1/libraries/SPI
INCLUDEPATH += ../_arduino-1.0.1/libraries/ST7565
INCLUDEPATH += ../_arduino-1.0.1/libraries/Stepper
INCLUDEPATH += ../_arduino-1.0.1/libraries/TimerOne
INCLUDEPATH += ../_arduino-1.0.1/libraries/TimerThree
INCLUDEPATH += ../_arduino-1.0.1/libraries/TinyGPS
INCLUDEPATH += ../_arduino-1.0.1/libraries/Tlc5940
INCLUDEPATH += ../_arduino-1.0.1/libraries/VirtualWire
INCLUDEPATH += ../_arduino-1.0.1/libraries/Wire
INCLUDEPATH += ../_arduino-1.0.1/libraries/x10
INCLUDEPATH += ../_arduino-1.0.1/libraries/XBee

And put this line at the top of scratchpad.cpp:

#include "../_arduino-1.0.1/hardware/teensy/cores/usb_flightsim/usb_api.h"

That last line gives us information about the various Teensyduino flight sim classes. Don’t copy it into Arduino with the rest of your code or it will complain at you. If you paste over it when taking code into Qt Creator, I’ve put a copy at the top of scratchpad.pro for convenience. The # marks it as a comment, so it is ignored in the .pro file. I just copy it back to the scratchpad.cpp file rather than try to undo the paste.

If you haven’t put the Arduino install folder in the same directory as your Arduino projects and the Scratchpad project folder, and put an underscore in the Arduino folder name, you’ll need to alter all those paths. I made them with minimal effort by sending the output from the Windows DIR command to a text file, and prepending the path to the filenames using a spreadsheet.

My workflow is to begin a new project with the Arduino IDE, normally by copying one of the examples or a previous project. I copy the source code into my Qt Creator Scratchpad project, overwriting whatever was there before, edit and write my code in comfort, and then copy-paste the whole lot back into Arduino to save, compile and run it. Believe me, it is an improvement on doing any significant work in the Arduino IDE.

I hope this has been helpful! If you have any feedback or suggestions, I can be reached via simulationelectronics@gmail.com.

– Jack 24/Oct/2012
(Updated 3/11/12, general rewrite.)

Advertisements

From → Guides

4 Comments
  1. Kendall permalink

    Awesome blog Jack! This should flatten the coding learning curve for me considerably! If anyone is looking for a good place to buy project enclosures may I suggest this;

    http://www.tentec.com/categories/Enclosures/

    I have no affiliation with this company at all, just a satisfied customer for many years in one of my other hobbies, Amateur Radio.

    N8ZK – Kendall

  2. Kendall permalink

    Question Jack. Will the QT Creator IDE install and procedures you’ve linked here work on a Mac? Alternatively, could I do the work in Windows and then transfer to the Mac? I run X-Plane and Teensy on a Mac. Thanks Sir!

  3. Hi Kendall. I think so. Qt is definitely cross-platform, and Qt Creator must work the same way on each OS. I don’t think any of this is Windows-specific!

    • Kendall permalink

      Yeah I realized that after I remembered Phillips dissertation about SCS. This is exciting though as its a common step with SCS and will help me learn about both! Thanks Jack!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s