Tuesday 31 January 2012

Pachube: tapping into existing feeds

This tutorial was followed http://community.pachube.com/arduino/usb/processing#pachube-output and the board wired up with an LED attached to PIN9. Sample code tested whether the serial read monitor at the bottom of the window was working, which it was.



Next, the proper code was run and the feed connection worked, but the LED did not light up. The resistor was replaced with a wire, and the LED lit up, but far too brightly and it heated up almost burning out completely creating a burning smell. Trying a very weak 560k ohm resistor instead still did not light up the LED. The feed values are changing, which suggests that the feed itself is working. This will be tried with another feed type.



Because the LED was overheating, I updated the code so that it drew a circle whose size corresponded with the remote sensor values, which are currently ‘159’, which changed from ‘162’. To do this, I used the ‘ellipse’ function from the processing library and added a single line of code. This worked well: see photo below. This could be used to connect to a remote sensor network on another arduino board connected to the internet. Processing is interesting because of the potential for a wide range of visual output that it represents.  There are other options, for example xbee and zigbee. 


As the values change, new circles are drawn, as below. There are two circles inside each-other where the feed has varied. Click to view larger.



Arduino firmata was already uploaded to the board.
The finished code is below:
As before my API KEY is removed.


import processing.serial.*;
import cc.arduino.*;

import eeml.*;

Arduino arduino;
int myValue;

DataIn dIn;

void setup()
{
size(255,255);
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 115200);
dIn = new DataIn(this, "http://pachube.com/api/1228.xml", "MY APIKEY", 5000);
}

void draw()
{
println(myValue);
arduino.analogWrite(9,myValue);
ellipse(125, 125, myValue/2, myValue/2);
}

void onReceiveEEML(DataIn d){
float remoteValue = d.getValue(0);
myValue = int(remoteValue) / 300;
}


No comments:

Post a Comment