Hi guys
I really searched a lot and tried many examples but still not working.
I have the servo working via arduino directly but when i use processing it is not.
I am known to processing and use it to control led, webcam and read many sensors from my arduino .... the only thing that is not working .... servo!!!!! help pls
P.S>I tried both ServoFirmata and StandardFirmata .... on Arduino board.
-------------------- Prep & Code -------------
I have updated arduino software to 22 and processing to 1.21I have also update Firmata 2.2downloaded firmata test from firmata.org and tested my servo and its working fine. I used arduino software to upload the last firmata 2.2 (StandardFirmata to arduin) and on Processing I am using this codeand it gives no error but it does not work!!!! import processing.serial.;
import cc.arduino.;Arduino arduino;
int pos=0; //servo position in degrees (0..180)void setup() {
size(360, 200);
arduino = new Arduino(this, Arduino.list()[1], 57600); //your offset may vary
//initialize the servo on pin 9
arduino.servoAttach(9);
// set minimum and maximum pulse times
arduino.servoSetMinPulseTime(9,500);
arduino.servoSetMaxPulseTime(9,2500);}void draw() {
// read mouseX coordinate
int newPos = constrain(mouseX/2,0,180); // update bg & servo position if mouseX changed
if(newPos != pos) {
background(newPos);
arduino.servoWrite(9,newPos);
arduino.servoWrite(10,180-newPos);
pos=newPos; //update servo position storage variable
}
}
You can use any pin you want. You can't give directions to a servo without first attaching the servo to the pin, though. I didn't see any code to attach a servo to pin 10.
it is also working via arduino directly ... only problem is via processing.
This would imply, then, that Processing is not sending meaningful data to the Arduino. What value(s) does newPos have that you are sending to the Arduino.
The other data associated with the servos in that processing application make it appear that Servo::writeMicroseconds() is being used, rather than Servo::write(). The value being written to the servo is not consistent with writeMicroseconds.
I removed the line on pin 10 .. was supposed to second servo ... !
I printed newPos and it gives me different values as I move the mouse ... as expected. .... now this value should go to the servo ....
Not working!
here is the updated code
import processing.serial.;
import cc.arduino.;
Arduino arduino;
int pos=0; //servo position in degrees (0..180)
void setup() {
size(360, 200);
arduino = new Arduino(this, Arduino.list()[1], 57600); //your offset may vary
//initialize the servo on pin 9
arduino.servoAttach(9);
// set minimum and maximum pulse times
arduino.servoSetMinPulseTime(9,500);
arduino.servoSetMaxPulseTime(9,2500);
}
That version of Arduino.java (the Arduino class in Processing) does not have servoAttach, servoSetMinPulseTime, servoSetMaxPulseTime, or servoWrite methods.
What version of the Arduino class in Processing are you using, and where did you get it?
I modified the StandardFirmata sketch to use NewSoftSerial to write to my serial LCD. I added print statements in setPinModeCallback, to print the pin number and mode that was passed in.
I added
arduino.pinMode(9, 4);
to the Processing sketch, since I found that SERVO was #defined with a value of 4.
I ran the Processing sketch, and saw on my LCD that setPinModeCallback was called with pin 9 and mode 3. Obviously, the servo did not move.
So, I changed the pinMode statement to
arduino.pinMode(9,5);
The LCD showed that setPinModeCallback was called with pin 9 and mode 4. When the little window popped up, I moved the mouse around, and the servo moved to.
Beats me why 1 is subtracted from the mode somewhere between the Processing sketch and the setPinMoeCallback function.
Bottom line, though, is that with StandardFirmata uploaded to the Arduino, Processing CAN command the servo.
Hi, thanks for the awesome work. I have been referencing your code and make the servo works as well with the ServoFirmata. However, when I try it with StandardFirmata, the servo gives weird response. The reason I want to use StandardFirmata is because I need to simultaneously read analog signal from a sensor. I can read analog signal with StandardFirmata, but not in ServoFirmata. In short, none of them can work in both ends.
I basically would like to specify pin 2 to 13 as SERVO pins and Analog 0 to 5 as analogRead Pins. Do you know how and what I should reference/modify from the Firmata examples to make my own protocol for the described purpose? Thanks.
Here is the modified code referenced from your code (the arduino is loaded with StandardFirmata):
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int servoPin = 7;
int sensorPin = 0;
float sensorValue = 0;
int pos=0; //servo position in degrees (0..180)
void setup()
{
size(360, 200);
arduino = new Arduino(this, Arduino.list()[1], 57600); //your offset may vary
arduino.pinMode(servoPin,4);
arduino.pinMode(sensorPin,0);
}
void draw()
{
sensorValue = arduino.analogRead(0);
println(sensorValue);
// read mouseX coordinate
int newPos = constrain(mouseX/2,0,180); // update bg & servo position if mouseX changed
if(newPos != pos)
{
background(newPos);
arduino.analogWrite(servoPin, newPos);
println (" newPos = " + newPos );
pos=newPos; //update servo position storage variable
}
}