Using QtCreator for Arduino development

Introduction

I’ve been using QtCreator for some time now, mostly for Qt projects, and I really like the environment. It’s fast and have plenty of features for c/c++ development such as code completion, symbol navigation, and git integration.

Today I decided to try if I could use QtCreator for Arduino development and it turned out that it wasn’t that difficult. The environment isn’t perfect but it works and it doesn’t take much effort to set up a project.

Disclaimer: I’m not doing Arduino development regularly, I just find it amusing to toggle bits on 8-bit hardware now and then. If you find anything in this post that seems totally wrong please let me know.

Prerequisites

This tutorial assumes that you’re running Ubuntu. It shouldn’t be too difficult to adjust for other Linux distributions.

If you haven’t already installed the latest QtSDK (1.1.3), please download it from http://qt.nokia.com/downloads and do so.

Install arduino-core package from the Ubuntu repository

$> sudo apt-get install arduino-core

This should pull in required dependencies too, such as avr-gcc and avrdude.

Install gtkterm (optional, but recommended)

$> sudo apt-get install gtkterm

Creating a simple ‘Hello World’ project

You can create everything from within QtCreator but I find it easier to do the initial set up from command line.

$> cd <projects folder>
$> mkdir -p helloworld/src
$> cd helloworld/src

If you look at the top of the file /usr/share/arduino/Arduino.mk you’ll find instructions on how to create a suitable Makefile for your project.

Here’s one that I use, just put the content in helloworld/src/Makefile

ARDUINO_DIR  = /usr/share/arduino

TARGET       = main
ARDUINO_LIBS =

MCU          = atmega328p
F_CPU        = 16000000

# Avrdude code
ARDUINO_PORT = /dev/ttyACM0
AVRDUDE_ARD_PROGRAMMER = arduino
AVRDUDE_ARD_BAUDRATE = 115200

include /usr/share/arduino/Arduino.mk

Finally create helloworld/src/app.cpp with the following content:


#include <WProgram.h>

void setup()
{
}

void loop()
{
}

Importing the Hello World project

Start QtCreator and go to ‘File/New File or Project’ (ctrl+n) and then choose ‘Other Project/Import Existing Project’.

Finish the wizard by specifying ‘HelloWorld’ as ‘Project name’ and ‘<projects folder>/helloworld’ as ‘Location’. You might wonder why I specified ‘helloworld’ as project location instead of ‘helloworld/src’. This is because I don’t want QtCreator’s project files to end up in the same folder as my source. Just click on ‘Next’ on the following questions to finish the wizard.

QtCreator creates three files:

  • HelloWorld.conf – Add defines
  • HelloWorld.files – List all files that are part of the project
  • HelloWorld.includes – List all include paths

Add ‘/usr/share/arduino/hardware/arduino/cores/arduino’ to ‘HelloWorld.includes’. This tells QtCreator where to look for Arduino specific header files.

Configuring ‘Clean/Build/Run’
Click ‘Projects’ (ctrl+5) on the bar to the left to activate the project settings page to change the build and run settings.

Clean and Build settings
Change ‘Build directory’ to ‘<projects folder>/helloworld/src’ and modify the settings to reflect the screen shot below.

Run settings
Choose ‘Add Deploy Step’ and use the screen shot below to specify the settings.

If you didn’t install gtkterm you can specify ‘echo’ or something in the ‘Run configuration’.

The Hello World app
Finally I’ll write the code and upload/run it on the Arduino.

Open ‘app.cpp’ and change the code to the following snippet:


#include <WProgram.h>

void setup()
{
    Serial.begin(115200);
}

void loop()
{
    Serial.println("Hello World");
    delay(1000);
}

Press ctrl+r and hopefully you’ll see ‘Hello World’ printed each second in the gtkterm console.

This Post Has 13 Comments

  1. Nice, just started project using Arduino. This is useful. Post more about Arduino development.

  2. Do you think it’s possible to make a Arduino_project template (or project Wizard) for Qt-Creator ?

  3. @wally I think I tried this but unfortunately I don’t remember the out come. Do take a look in the QtCreator template directory, you should find some example for simple C++ apps

  4. @Sinclair excuse me but the file is not found 404.

  5. Please notice, for ubuntu 12.10 (I am not sure since which version) you also need to install package arduino-cli which provides file /usr/share/arduino/Arduino.mk

  6. Very very good, can I debug my programs?

  7. How to switch this QT to window system,could you pls provide me the tutorial? syydbc@gmail.com Thinks

  8. Thanks, works great (QtCreator 3.6.0)

  9. I know this is very belated, but I could not find Arduino.mk on either of my systems despite having arduino-core installed. I subsequently discovered that one also has to download the arduino-mk package:

    sudo apt-get install arduino-mk

    I am using QT4.5 and Arduino 1.8.9 and the IDE environment does differ somewhat, but the options are all present.
    I also had to modify my Makefile (as per instructions in the Arduino.mk) to be as follows:

    Makefile
    —————————
    ARDUINO_DIR = /usr/share/arduino
    ARDMK_DIR = /usr/share/arduino
    # Set to YOUR avrtools path
    AVR_TOOLS_DIR = /usr/share/arduino/hardware/tools/avr

    TARGET = main
    ARDUINO_LIBS =
    BOARD_TAG = uno
    MONITOR_PORT = /dev/ttyACM0

    include /usr/share/arduino/Arduino.mk
    ———————-

    Note that some boards requires /dev/ttyUSBx where x is the sequence number of the allocated USB port handle, .e.g. /dev/ttyUSB0.

    Hope this helps.

Leave a Reply

Close Menu