Hi everyone,
I need some help to figuring out , why I can’t send data for changing the Speed, from Processing to my stepper motor via Arduino.
It’ should be very easy …
I saw in the forum other people doing things with steppers
but, I can’t make it works correctly!
The idea is super simple, I just need a slider using ControlP5 to change the speed of a stepper motor.
Processing
import processing.serial.*;
import controlP5.*;
ControlP5 cp5;
Serial port;
int myColor = color(0, 0, 0);
int sliderValue = 100;
void setup() {
size(500, 300);
// printArray(Serial.list());
// "COM5"
port = new Serial(this, Serial.list()[1], 9600);
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() {
port.write(sliderValue);
fill(sliderValue);
rect(0, 0, width, 100);
}
Arduino:
#include <AccelStepper.h>
int s =10;
int newS;
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
void setup()
{
Serial.begin(9600); // initialise the serial monitor
//Serial.setTimeout(10); // rallenta
stepper.setMaxSpeed(1000);
stepper.setSpeed(s);
}
void loop()
{
if(Serial.available() > 0){
newS = Serial.parseInt();
stepper.setSpeed(newS);
}
stepper.runSpeed();
}
Could someone pointing me out what I have to change in my code please?
- First I run Arduino and the stepper starts spinning
- I run the Processing Sketch, and the arduino stops
So, arduino is receiving a wrong data type? Too many?
Thanks in advance for your help,
best