Working with the Particle IDE

Updated 15 October 2016

In case you haven’t heard, the Internet of Things (IoT) is upon us. More and more devices everyday are being connected to the internet to communicate to people and other devices. Particle have seen the DIY/maker community’s desire for easy to use IoT development tools, and given us their Photon and Electron development boards, along with an incredible cloud based platform with which to use them. In our Welcome to Particle.io article, we took a board look at all the different tools available on the Particle cloud platform. But for us DIY’ers who enjoy building, creating and programming, the place where the most time will be spent is in the Particle cloud based Integrated Development Environment (IDE).

The IDE is where you can write your code, compile it, upload it to your boards, access Particle and community libraries, monitor your devices, and much more. The Particle.io IDE is a nicely laid out, feature rich platform that makes it incredibly easy to get started with Particle, both from other DIY platforms such as Arduino and Raspberry Pi, and those new to programming.

Programming with the Particle IDE

The Particle.io team have made getting started with Particle as easy as possible by using the same style of coding abstraction as the Arduino platform. You can still control I/O pins using digitalWrite, analogRead, and other familiar functions. However whilst the Arduino IDE is based on the C programming language, the Particle IDE uses the C++ programming language which, whilst quite compatible with most C code, has its differences.

To use the features of the Particle cloud platform, you’ll need to create an account with them, and login. Now let’s take a look at the IDE.

Particle IDE Layout

The IDE window is broken up into three main sections:

IDE overview

  1. Scripting area. This is where you’ll construct your program, view any compiler messages, and work with your code.
  2. Menu panel. This area displays the various elements from whatever you’ve selected in the toolbar. It shows all the apps (programs) you’ve created, libraries, device and account token info, plus more. You can select what you want to view in the panel on the left hand side, and browse through the tab on the right hand side of the menu.
  3. Menu toolbar. This is where you can select what you're viewing in the menu panel.

This is the general layout of the IDE, however there are a few special elements to it which, if you haven’t done much coding before, may take some getting used to.

IDE menu panel 1In the top left corner, there are three buttons; save, compile, and flash. The save function is fairly self explanatory, however in order to use your code on a board, you have to compile it. This turns your C++ code into Assembly language code which is readable by microcontrollers. If there are any formatting, syntax, or other errors in your code, the IDE will let you know when you try and compile it, and you will need to address them before you can successfully compile your code. A misplaced ‘;’ can be the difference between hours of reading and re-reading code while asking yourself why you insisted on writing this section at 3am.

Compiling doesn’t actually do anything with your code apart from verify that it is usable and written correctly. To get your program onto a Photon or Electron you will need to use the flash button. This goes through the compilation step listed above, and then flashes it Over the Air (OTA) to your device.

**Note that flashing OTA uses data on your target device, which may not be ideal for an Electron board which has limited data. Check out our Getting Started with Particle Electron for info on how to flash it using the USB cable**

A dialog box will appear letting you know whether the flashing was a success, and the expected function of the on-board LED.

That’s all there is to writing a basic program, so let’s flash the well-worn ‘blink’ program that is the ‘Hello World’ of microcontrollers. If you’re using an Electron, go to the previously linked tutorial to learn how to flash your first program. Copy the following code, or click on the example ‘Blink an LED’ in the code tab.

int led = D7;

void setup() {
    pinMode(led, OUTPUT);
}

void loop() {
    digitalWrite(led, HIGH);
    delay(500);
    digitalWrite(led, LOW);
    delay(500);
}

Power up your Photon board, then click on the device tab, and select which device you wish to target, ensure it’s selected with the yellow star, then click flash.

IDE menu panel 2And that’s all well and good for creating simple apps, however if you want to do much with any microcontroller, you’ll need to use libraries.

Libraries are pre-written blocks of code that you inject into your program by using the #include function, which is the equivalent of copying the entire code into your application. Libraries are designed to handle all of the nitty-gritty code required to control things such as LCD displays, port expanders, MIDI communication etc. The library will have a .cpp and a .h file (otherwise known as header files) and usually an example use program to go with it. Particle have made it as easy as possible to get started by porting over the bulk of the libraries used by Arduino, along with many community created libraries. To search for a library click on the library tab in your menu panel, and use the search tool to find what you’re after. Click ‘Include in App’ which brings the headers files into your app, and lets you use the functionality of that library.

For a great example of using libraries in the Particle IDE, check out our Character Displays with Particle which shows you how to use the LCD and OLED character display libraries.

And there you have it, that’s all there is to using the Particle IDE

Have a question? Ask the Author of this guide today!

Please enter minimum 20 characters

Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

Expect a quick reply during business hours, many of us check-in over the weekend as well.

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.