User Tools

Site Tools


phidgets_for_processing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

phidgets_for_processing [2012/11/14 04:21] (current)
130.239.232.31 created
Line 1: Line 1:
 +=== Phidgets ===
  
 +Phidgets are a set of "plug and play" building blocks for "low cost" USB sensing and control from your PC. 
 +
 +All the USB complexity is taken care of by libraries. Applications can be developed quickly by programmers using their favorite language: C/C++, C#, Cocoa, Delphi, Flash AS3, Flex AS3, Java, LabVIEW, MATLAB, Max/MSP, MRS, Python, REALBasic, Visual Basic.NET, Visual Basic 6.0, Visual Basic for Applications,​ Visual Basic Script, and Visual C/​C++/​Borland.NET.
 +
 +We will look into how this can be used in Processing.
 +
 +== Webservice ==
 +To convey the input from the Phidget hardware to your Flash-project you need to install drivers and run a webservice. Download your flavor from [[http://​www.phidgets.com/​drivers.php|here]]. ​
 +
 +Run it, connect a phidget and watch what the webservice rads from it when you manipulate it.
 +
 +== Library ==
 +The basic functions of all Phidgets is stored in a file that you need to download.
 +
 +1.Make a folder to keep your phidget-related files in. This will contain files that you will re-use for phidget projects, not your Processing sketches.
 +
 +2.Download phidget21.jar from http://​www.phidgets.com/​ - programming tab. Put it in your phidget folder.
 +
 +
 +== Dealing with events ==
 +Since different Phidgets trigger stuff in different ways we need some code for each type of Phidget.
 +
 +1.Download the Processing code for the phidgets Accelerometer,​ Encoder and Interface kit from[[http://​pages.cpsc.ucalgary.ca/​~boyd/​pmwiki/​pmwiki.php?​n=Teaching.ProcessingPhidgets|this]] page. Put them in your phidget folder. For RFID reader-phidget copy and save the code beneath in the same folder with the name phidgetRFID.pde.
 +
 +2.Create a new Processing sketch. Save the sketch, giving it a suitable name. 
 +
 +3.From the Sketch menu in Processing, select Add File ... From the file selection dialogue, select phidget21.jar from your folder of phidget-related files. This will add a folder name code to your Processing sketch folder, and a copy phidget21.jar will appear there.
 +
 +7.From the Sketch menu in Processing, select Add File ... From the file selection dialogue, select the Processing code for your phidget, such as phidgetIK.pde. You will see a new file tab appear for your sketch with the Processing code, and the file will be copied to your sketch folder.
 +
 +== Finally, we get to do stuff ==
 +Now you can write code in the first blank tab of your project. ​
 +Some simple examples to get started:
 +
 += Accelerometer =
 +<code java>
 +phidgetAccelerometer accelerometer;​
 +float accelValue;
 +void setup()
 +{
 +  // set screen size
 +  size(400, 300);
 +  fill(0,​0,​255);​
 +  ​
 +  // get phidget IK started and wait up to 1s for attach
 +  accelerometer = new phidgetAccelerometer();​
 +  ​
 +  accelerometer.waitForAttachment( 1000 );
 +  ​
 +}
 +
 +void draw()
 +{
 +  background( 200 );
 +  ​
 +  // show acceleration. our accelerometer has two axes -> getAcceleration(0) and getAcceleration(1).
 +  //​accelerometer.getAccelerationMin( 0 ), accelerometer.getAccelerationMax( 0 )
 +    accelValue = accelerometer.getAcceleration(0);​
 +    float x = map(accelValue,​ -1.0,1.0 ,0, 400 );
 +    accelValue = accelerometer.getAcceleration(1);​
 +    float y =  map(accelValue,​ -1.0,0.8 ,0, 300 );
 +    println(accelValue);​
 +    ellipse( x, y, 10, 10 );
 +  ​
 +  if (keyPressed) {
 +    accelerometer.close();​
 +    exit();
 +  }
 +}
 +</​code>​
 +
 += RFID reader =
 +<code java>
 +
 +
 +RFIDPhidget rfid = null;
 +
 +String tag = "";​
 +
 +void setup()
 +{
 +  size(550,​450);​
 +
 +  // setup Reader
 +  setupReader();​
 +  ​
 +}
 +
 +void draw()
 +{
 +  if(tag.equals("​01023c13aa"​))
 +  {
 +    println("​Hi mom!"​);​
 +  }
 +}
 +
 +void close()
 +{
 + ​closeReader(); ​
 +}
 +</​code>​
phidgets_for_processing.txt · Last modified: 2012/11/14 04:21 by 130.239.232.31