ofArduino and servo

hi,

I’m a little new to openFrameworks and arduino, but I’ve been experimenting for a few weeks and gained a foothold.

I’ve had success with the provided firmataExample and my duemilanove, and I’m now working on modifying it. I’ve attached a servo to pin 10, and while it responds when I send it pwm, I’d like to just be able to specify the position (between 0 and 180) as is done in the Arduino sketch servo sweep example, etc. Here’s how I’m attempting to do that:

I initialize as follows - looking at the code for sendServoAttach, it appears I don’t need an ard.sendDigitalPinMode(10, ARD_SERVO);

  
void testApp::setupArduino(){  
  
	// this is where you setup all the pins and pin modes, etc  
	for (int i = 0; i < 13; i++){  
		ard.sendDigitalPinMode(i, ARD_OUTPUT);  
	}  
  
	ard.sendDigitalPinMode(13, ARD_OUTPUT);  
	ard.sendAnalogPinReporting(0, ARD_ANALOG);	// AB: report data  
	ard.sendServoAttach(10);  
  
}  

Then call:

  
  
void testApp::updateArduino(){  
  
	// update the arduino, get any data or messages:  
	ard.update();  
  
	ard.sendServo(10,ard.getServo(10)+1); // have tried passing various values  
}  
  

Interestingly, getServo(10) will print the numbers I’ve been sendServo’ing, suggesting that the value is being correctly set … yet the servo does not twitch, nor turn, nor indicate any sign of movement. (Yet with sendPwm it is OK - just harder to control).

Any ideas on what I might be missing?

Thanks.

-san

Couple of quick ideas: what’s the pulse rate for your particular servo? Is it w/in the default 544-2400 range?

Just to confirm: you’re calling the isArduinoReady() before you try to update() method?

Calling ard.sendDigitalPinMode() on that pin might be interfering with the Servo library setup, so try removing the for loop through all the pins.

You could also try asking on the firmata mailing list if you keep running into problems.

Thanks for your suggestions.

It turned out to be an underlying problem that I was able to solve with some patches, explained here: http://www.makingthingsmove.org/blog/

(in case anyone else encounters this, or problem with analog pin readings …)

Nice. So your original code works w/o changes using the updated firmata sketch?