We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpElectronics,  Serial Library › Help me get started with this thing
Page Index Toggle Pages: 1
Help me get started with this thing (Read 2437 times)
Help me get started with this thing
Jul 7th, 2009, 11:02pm
 
I'm interested in controlling cursors and maybe colors with an Arduino and a potentiometer, using Processing.  Simple, dimple, right?

Well, I'm attempting to follow online instructions as closely as possible, but I'm stuck.  I cannot get my analog port to read.

I'm following [/url=OhNeverMindICan'tPostLinks]Arduino Playground's introductory instructions[/url] to get started.  I've installed Firmata Standard on the board.  I've installed the arduino library in the Processor library folder.  I'm pretty sure it's not the hardware, as a simple pot-LED flicker test shows that everything works without Processing involved.  I've set the right serial port, after an error led me down one avenue of research. I'm using this code in Processing to run a classic example as an analog-in-controlled application, simple enough:
Code:
 /*
* Recursive Tree
* by Daniel Shiffman
*
* Renders a simple tree-like structure via recursion
* Branching angle calculated as a function of horizontal mouse  location
*/
import processing.serial.*; // reference the serial library

import cc.arduino.*; // reference the arduino library

Arduino arduino; // create a variable arduino of the Arduino data type

float theta;
void setup() {
 size(200,200);
 smooth();
println(Serial.list()); // List all the available serial ports:

arduino = new Arduino(this, Arduino.list()[3], 57600);

}

void draw() {

 background(0);
 frameRate(30);
 stroke(255);
 // Let's pick an angle 0 to 90 degrees based on the mouse position
/* float a = (mouseX / (float) width) * 90f; // original line */
print (arduino.analogRead(3));
float a = (arduino.analogRead(3) / (float) width) * 90f;

// Convert it to radians
 theta = radians(a);
 // Start the tree from the bottom of the screen
 translate(width/2,height);
 // Draw a line 60 pixels
 line(0,0,0,-60);
 // Move to the end of that line
 translate(0,-60);
 // Start the recursive branching!
 branch(60);

}

void branch(float h) {
 // Each branch will be 2/3rds the size of the previous one
 h *= 0.66f;

 // All recursive functions must have an exit condition!!!!
 // Here, ours is when the length of the branch is 2 pixels or less
 if (h > 2) {
   pushMatrix();    // Save the current state of transformation (i.e. where are we now)
   rotate(theta);   // Rotate by theta
   line(0,0,0,-h);  // Draw the branch
   translate(0,-h); // Move to the end of the branch
   branch(h);       // Ok, now call myself to draw two new branches!!
   popMatrix();     // Whenever we get back here, we "pop" in order to restore the previous matrix state

   // Repeat the same thing, only branch off to the "left" this time!
   pushMatrix();
   rotate(-theta);
   line(0,0,0,-h);
   translate(0,-h);
   branch(h);
   popMatrix();
 }
}


I get no errors, and after adding the
Code:

print (arduino.analogRead(3))

I see that there's just no reading of the pot by Processing.  Is there some way to monitor the inputs and outputs to the board through another sketch?  I don't even know.

Firmata Standard is installed on the board, do I also need to have Arduino running for serial monitoring or something?  

Somebody please help me out Smiley

Thanks!
Re: Help me get started with this thing
Reply #1 - Jul 7th, 2009, 11:27pm
 
I should say that I'm not using a resistor with the potentiometer, either.
Re: Help me get started with this thing
Reply #2 - Jul 8th, 2009, 12:27am
 
Couple ideas:

Make sure Firmata is uploaded to your Arduino (edit: I see you did that :]).

The baud rate to use also depends on which version of Firmata you have.

See here for reference:
http://www.arduino.cc/playground/Interfacing/Processing
Re: Help me get started with this thing
Reply #3 - Jul 8th, 2009, 6:07pm
 
When I use the serial monitor in Arduino, it states my baud is 9600 - do I need to change from there?
Re: Help me get started with this thing
Reply #4 - Jul 9th, 2009, 12:19am
 
Yes. Since you are controlling the Arduino from Processing (rather than running a sketch on Arduino alone), Processing and the board have to communicate.

Version 2 of Firmata runs at 115200 baud.
If you are using the latest version, try:
arduino = new Arduino(this, Arduino.list()[3], 115200);
Re: Help me get started with this thing
Reply #5 - Jul 9th, 2009, 10:42pm
 
You are a genius, sir!  I added your code, and went over to the Arduino and adjusted the Baud rate on the serial monitor (I don't know if that did anything), and it fired right up.  Here's a (sketchy and horribly shot) video of the results.

youtube.com/watch?v=cLNU8ksF0Hc

Don't know if the forum allows for .flv embedding.
Re: Help me get started with this thing
Reply #6 - Jul 9th, 2009, 10:43pm
 
Haven't done my 5 post yet, so here's the URL:

Re: Help me get started with this thing
Reply #7 - Jul 9th, 2009, 10:43pm
 
Page Index Toggle Pages: 1