Sending Arduino Data to COSM using Processing

Motivation I created this tutorial because the existing resources did not work for me, as several changes have been made to COSM over time (but not their documentation). This tutorial explains how to send data from Processing on the computer to COSM. COSM graphs this data which can be embedded in personal or professional websites.

Overview For this project, I connected a potentiometer to 5V and ground and connected the middle pin to A0 on the Arduino. Every second, the Arduino sends the reading of that analog voltage as an 8-bit decimal value to the computer using the Arduino Serial library. Processing then takes this data and sends it to COSM using a DataOut stream.

Using COSM This part is simple. Go to cosm.com and create a free account. After that, go to you console and create a "Device/Feed". Choose "Something Else" when it asks what type of feed you are adding. Note: You could choose an "Arduino" feed if you wanted. Tell it that you will manually push data to COSM, then give it a title and some tags.

Edit the feed and add a datastream. You will now have to go to your "Keys" and generate an API Key to used later.

To find the proper URL for the processing code, follow these simple instructions:  Go to your console. Pick the feed you want to send data to. In the box that shows your feed ID, click "XML" under feed formats. Copy and past the URL from your browser. 

Don't worry too much about writing down the feed number right now. Instead, let's move on with some coding.

Arduino Code For this project, I set up a very basic program to send the potentiometer data to the computer.

Upload this to the Arduino. Now we can start working on the processing side of this project.

Processing Code

This project requires the EEML library. The latest version can be found at http://www.eeml.org/library/. We will also use the Processing Serial library which comes with Processing.

Now let's add some variables for communicating with the Arduino and COSM. The DataOut variable is what will talk with COSM.

As with any Processing code, you will need the setup and draw functions.

Make sure to change the "COM13" to the proper port. This what it looks like on Windows and look quite different on a Mac or Linux system (sorry I can't help more here). Notice that two data output streams are created, each with their own tags.

It is absolutely vital that you replace the URL with the proper location and the X's with your API key given to you by COSM.

Now let's actually do something when the Arduino sends data to Processing.

The dOut.update(...) function sends the data to COSM and the dOut.updatePachube retrieves a response from COSM determining if the data was received properly, or if there was an error.

This was the final step in the project and you should be able to run the processing program.