Close

CW & CCW Pins Example

A project log for Mechaduino

Mechaduino is an affordable, open-source, industrial servo motor. Position, torque, velocity, and custom modes. Arduino compatible.

jcchurchjcchurch 11/22/2016 at 01:512 Comments

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

bob.bingham wrote 11/24/2016 at 01:17 point

Thanks Joe,

I used velocity and it's working well. Looks like max rpm is about 450.

  Are you sure? yes | no

bob.bingham wrote 11/24/2016 at 01:17 point

Thanks Joe,

I used velocity and it's working well. Looks like max rpm is about 450.

  Are you sure? yes | no