Here's a quick example showing one way to configure two digital IO pins to control the Mechaduino. Pull pin 2 low and the Mechaduino moves CW, pin 3 and it moves CCW:
First, run the calibration routine and copy the lookup table in to parameters.cpp.
Next, add the following code in the bottom of the setup function in Mechaduino.ino:
pinMode(3,INPUT_PULLUP); //pin for + direction pinMode(2,INPUT_PULLUP); //pin for - direction enableTCInterrupts(); //start in closed loop mode mode = 'x';
...and then enter this code in the loop:
void loop()
{
if (digitalRead(2) & !digitalRead(3)){
r+= 0.01;
}
else if (digitalRead(3) & !digitalRead(2)){
r-= 0.01;
}
delayMicroseconds(5);
//serialCheck();
//r=0.1125*step_count;
}
In this example we use the position mode 'x', and increment/decrement the setpoint based on the pin state. You could also use the velocity mode 'v' and set the setpoint to a velocity based on the pin state.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Thanks Joe,
I used velocity and it's working well. Looks like max rpm is about 450.
Are you sure? yes | no
Thanks Joe,
I used velocity and it's working well. Looks like max rpm is about 450.
Are you sure? yes | no