Hello,
- First get the stepper motor working independent of Processing.
- Consider how to send the same control values from Processing to Arduino.
- Give consideration to timing and each loop on Processing and Arduino side.
- Get the serial communication working without the hardware.
- Integrate the serial with the hardware.
- Troubleshoot.
There are many ways to monitor the serial data you are sending; I provided a simple example that does not require additional hardware and only a few extra lines of code.
This will help you monitor the data you are sending and echo it back:
Processing Code < Click here to open!
import processing.serial.*;
import controlP5.*;
ControlP5 cp5;
Serial port;
int myColor = color(0, 0, 0);
int sliderValue = 100;
int val, counter;
void setup() {
size(500, 300);
printArray(Serial.list());
// "COM5"
port = new Serial(this, Serial.list()[4], 9600);
delay(1000); // Give the Arduino a chance to reboot before sending data
cp5 = new ControlP5(this);
;
// add a horizontal sliders, the value of this slider will be linked
// to variable 'sliderValue'
cp5.addSlider("sliderValue")
.setPosition(100, 50)
.setRange(20, 200)
;
}
void draw()
{
if (frameCount%60 == 0) // Once a second
{
port.write(sliderValue);
println("Tx: ", sliderValue);
}
if(port.available() > 0)
{
val = port.read();
println("Count: ", counter++);
println("Rx: ", val);
}
fill(sliderValue);
rect(0, 0, width, 100);
}
Arduino Code < Click here to open!
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (Serial.available())
{
int val = Serial.read();
Serial.write(val); // Echo back to Processing
}
}
References:
https://processing.org/tutorials/electronics
https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing/all
Once you grasp the serial communications between Processing and Arduino you can control anything.
Enjoy the journey!
:)