IxD IoT

working with the IxD IoT

This is a quick guide for how to work with your photon. This page also contains links to other resources that you will find helpful.

Coding for the photon

The photon is based on the Arduino platform, but with a few variations. Most of the code you use for Arduino you can also use for the Photon.

Particle has it's own online system (IDE) for you to create code and upload it to your photon. It's available through your Particle login.


Goto particle build


In this IDE you can create code, save it, access libraries of existing code, and send code to your photon (this is called 'flashing'). Once you're in build, in the main frame you will see a standard form template for code. You will see two 'functions': setup and loop.

void setup()

			      	
	void setup() {
		
		// the code inside here runs once only, 
		// when the photon is first turned on

	}
		      	

This function is used for the initial set up each time your photon turns on. It runs only once, right after the photon is turned on.

void loop()

			      	
	void loop() {
		
		// the code in here runs after setup() is complete and will
		// run over and over, until the photon is turned off

	}
		      	

This function is where the main work happens. Loop() does just that, loop over and over again. The code that you put in here will run and then keep repeating as long as the photon is turned on. It's where most of the work happens.

For example, if you want to take a temperature reading every 20 minutes and then send it to the database, you would create code inside loop() that:

  • Takes a reading from the sensor
  • Packages that reading into a bundle of information including things like where the photon is located, who owns it, and what type of information the reading is
  • Publishes (sends) that information to the database
  • Wait 20 minutes

Then loop() would make this code repeat until the photon is turned off.

Finding sample code

particle library icon a ribbon

The first place to look for code or for help is through google. Let's face it, it's impossible to know everything. Plus things in this field change so rapidly, that you can't keep up with everything. In this community, we share and help each other out through bulletin boards like StackOverflow. It's the way things work and it works well.

Search either particle photon yoursensor or arduino yoursensor. Both will give you useful examples.

The next place to look is in the Particle library. In particle build, on the left side there is an icon that looks like a ribbon (similar to the one above). Clicking on that allows you to search the library for sample code. A few tips:

  • Search for the type of sensor you have, using the codes that are written on the sensor.
  • When you find something, you will often see a number of tabs open across the top. Look for one that is titled 'example.ino' or something similar.
  • Use the button Use this example. It creates a copy of that example into a new "sketch" (fancy name for the file containing your code) and you can then save it into your own space in particle build.

making things work

save and verify

Now that you have written your code, you have to flash (send) your code to the photon. Here's the process you should follow:

particle library icon a ribbon Save your code by clicking the folder icon on the left side of build.

particle library icon a ribbon Check or verify your code by clicking the tick icon on the left side of build. This runs through your code to see if there are any errors that will prevent your code from running.

target and flash

particle library icon a ribbonTarget your device by clicking the icon that looks like a gun sight, the select your photon. Click just to the left of your photon and a yellow star should appear.

particle library icon a ribbon Check or verify your code by clicking the tick icon on the left side of build. This runs through your code to see if there are any errors that will prevent your code from running.

Other useful resources

Photon documentation

Particularly see the firmware and and cloud functions sections. Click on the + symbol next to these headings to see more detail.

Photon documentation

Particle community

This is a great resource. People who use particle products ask questions about everything and get answers from all over the place. You can find out almost anything from here. Make sure you read through all of the comments in response to a request for help ... there can be important information in the discussion!

Make sure that you are looking at questions and answers about photon. Particle have other products. They are similar but there are some subtle differences.

Particle community