Sending analogWrite() to Arduino via Processing
in
Integration and Hardware
•
2 years ago
I'm controlling 4 DC motors through Processing, using StandardFirmata on the Arduino.
When I test the motors with a simple sketch in Arduino, they work perfect. When I try to actuate the motors through Processing, they do nothing.
- I have checked the syntax of the Arduino library in Processing and I believe I have called the functions correctly.
- I have printed a list of serial ports to confirm that I am listening to the correct port.
- Both StandardFirmata and Processing are set to 9600 baud.
- If I change the analogWrite() to digitalWrite(pin,HIGH), I am able to turn the motors on.
Is there something I am missing when calling arduino.analogWrite() in Processing?
Help, please and thank you!
When I test the motors with a simple sketch in Arduino, they work perfect. When I try to actuate the motors through Processing, they do nothing.
- I have checked the syntax of the Arduino library in Processing and I believe I have called the functions correctly.
- I have printed a list of serial ports to confirm that I am listening to the correct port.
- Both StandardFirmata and Processing are set to 9600 baud.
- If I change the analogWrite() to digitalWrite(pin,HIGH), I am able to turn the motors on.
Is there something I am missing when calling arduino.analogWrite() in Processing?
Help, please and thank you!
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
int motor1 = 3;
int motor2 = 5;
int motor3 = 9;
int motor4 = 10;
int pulseWidth = 200;
void setup() {
size(100,100);
background(0);
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[0], 9600);
arduino.pinMode (motor1, Arduino.OUTPUT);
arduino.pinMode (motor2, Arduino.OUTPUT);
arduino.pinMode (motor3, Arduino.OUTPUT);
arduino.pinMode (motor4, Arduino.OUTPUT);
}
void draw() {
arduino.analogWrite(motor1, pulseWidth);
arduino.analogWrite(motor2, pulseWidth);
arduino.analogWrite(motor3, pulseWidth);
arduino.analogWrite(motor4, pulseWidth);
}
1