Controlling a stepper motor using Processing and firmata

Hello,

I am relatively new to arduino and processing. I have a 4-wire bipolar stepper motor which I can control with arduino UNO + the arduino motor shield using the following (standard example) code in the arduino IDE:

#include <Stepper.h>
 
const int spr = 20; // motor steps per revolution
const int pwm_cha = 3;
const int pwm_chb = 11;
const int dir_cha = 12;
const int dir_chb = 13;
const int brake_cha = 9;
const int brake_chb = 8;

Stepper stepper(spr, dir_cha, dir_chb);

void setup()
{
    pinMode(pwm_cha, OUTPUT);
    pinMode(pwm_chb, OUTPUT);
    pinMode(brake_cha, OUTPUT);
    pinMode(brake_chb, OUTPUT);
    digitalWrite(pwm_cha, HIGH);
    digitalWrite(pwm_chb, HIGH);
    digitalWrite(brake_cha, LOW);
    digitalWrite(brake_chb, LOW);

    stepper.setSpeed(50);
 }
 
void loop()
{
  stepper.step(spr);
  delay(2000);
}

The code basically just turns a 20-step (or any other “_”-step) motor for one complete revolution, then pauses for two seconds, and turns for another revolution etc.

My question is this: How do I do just this exact thing using Processing?
(It’s a rather elementary sort of task but I’ve been completely unable to find it anywhere on the arduino or processing fora or reference or anywhere else at all.)

Is there a simple way to port the arduino code from arduino IDE to processing? Can I use the arduino stepper motor libraries in conjunction with processing, or does processing have its own such libraries?

I need to control some other sensors and data analysis in processing based on inputs which vary with the position of the motor, which I only need to sweep through a prespecified number of steps on each run of the program (I don’t need any motor control commands from the keyboard or anything like that). I wanted to streamline the whole motor-control/sensory input/data aquisition into one easy processing sketch.

Any suggestions?

Thanks!

Arduino = C++
Processing = Java

Two completely different languages.

Also, how exactly do you plan on connecting a stepper motor to your PC?

I am aware of this.

I have it wired up to an arduino motor shield atop an arduino UNO, similarly to this picture, except the motor has 4 wires (so with an extra pair of wires going to the "B"+/- connections): http://www.instructables.com/files/deriv/FQB/2TFL/H05NKJYQ/FQB2TFLH05NKJYQ.LARGE.jpg

I object! (see what I did there?) :stuck_out_tongue:

Two completely different languages.

While I agree to the word different, I'm struggling to accept "completely"

cheeeeeeese:
My question is this: How do I do just this exact thing using Processing?

Given that Processing applications run on the PC and obviously processes running on the PC have no direct access to the Arduino hardware, what you're asking makes no sense. The only way to drive the Arduino hardware is by running a sketch on the Arduino that does what you want.

Perhaps what you're trying to do is have Processing provide a user interface that you can use to control the stepper. That's certainly possible, by writing a Processing application that presents a user interface and sends commands to the Arduino's serial port in response to user input, and writing an Arduino sketch that reads commands from the serial port and controls the stepper motor accordingly. Is that anything like what you're trying to do?

PeterH:
Perhaps what you're trying to do is have Processing provide a user interface that you can use to control the stepper. That's certainly possible, by writing a Processing application that presents a user interface and sends commands to the Arduino's serial port in response to user input, and writing an Arduino sketch that reads commands from the serial port and controls the stepper motor accordingly. Is that anything like what you're trying to do?

Yes. This would do.