Photo and sketches with pinouts for Orion limits switches and pen servo


#1

I don’t intend to use MakeBlock software, just looking at the comments inside it make me feel uneasy, I’ll write all my own code. But since MakeBlock’s documentation is awful, and since people here have helped me, I thought I’d post some info that others in my situation would find useful.

This photo shows pins to use in your sketch with limit switches, cables and servos,

Here’s a sketch to test the pen servo movement. Iy’ll move it a little biut every half a second:

#include <Servo.h>

Servo myservo;  // Create the servo object

void setup() {
  myservo.attach(A1);  // Make the servo use pin A1 on Port 7 of the Orion
}

void loop() {
  int degs = random (70,110) ; // Servo "default" is at 90. Make a random number around 90°
  myservo.write(degs);         // Sets the servo position in degrees
  delay(500);                  // Pause so you can see where it has moved
}

And here’s a sketch to test one pair of limit switches. Once uploaded onto the Orion you’ll need to get the serial monitor screen going (icon at extreme right of the toolba). Then every time you push one of the microswitches the sketch will print out the change.

void setup()
{
    Serial.begin(9600);
    pinMode (A3,INPUT_PULLUP);
    pinMode (A2,INPUT_PULLUP);
    Serial.println("start");
}

int iOldY1 = 0 ;
int iOldY2 = 0 ;

void loop()
{    
    int iNewY1 = digitalRead (A3) ;
    int iNewY2 = digitalRead (A2) ;   

    if ((iNewY1 != iOldY1) || (iNewY2 != iOldY2)) {
        Serial.print ("A3=") ;
        Serial.print (iNewY1) ;
        Serial.print ("  A2=") ;
        Serial.print (iNewY2) ;
        Serial.println("") ;
    }

    iOldY1 = iNewY1 ;
    iOldY2 = iNewY2 ;
}

To test the other pair of limit switches just change A3 and A2 everywhere in the sketch above to 12 and 13.

Hope this helps someone!


XY plotter v2 not working at all
Which is the best GitHub for for GCodeParser?
XY Plotter GRemote not Working
Initialization Issues
#2

Hello giovanniguerra, Your info was indeed useful.
I have taken your script and added some additional functionality.

#include <Servo.h>

// Test routine for the X-Y plotter.
// The limit switched are used to active the X & Y steppen motors.
// The servo is toggled when ever the status of the limit switched changes.

Servo penservo;  // Pen Servo

//PIN Settings for ORION Board
int X_STEP_PIN = 10;
int X_DIR_PIN = 11;
int X_MIN_PIN = A3; // Limit switch on the left
int X_MAX_PIN = A2; // Limit switch on the right

int Y_STEP_PIN = 9;
int Y_DIR_PIN = 3;
int Y_MIN_PIN = 13; // Limit switch on the bottom
int Y_MAX_PIN = 12; // Limit switch on the top

int SERVO_PIN = A1;

// Default routine to to a step, taken from "GCodeParser\stepper_control.ino"
void do_step(byte STEP_PIN, byte DIR_PIN, byte dir) {
  switch (dir << 2 | digitalRead(STEP_PIN) << 1 | digitalRead(DIR_PIN)) {
    case 0: /* 0 00 -> 10 */
    case 5: /* 1 01 -> 11 */
      digitalWrite(STEP_PIN, HIGH);
      break;
    case 1: /* 0 01 -> 00 */
    case 7: /* 1 11 -> 10 */
      digitalWrite(DIR_PIN, LOW);
      break;
    case 2: /* 0 10 -> 11 */
    case 4: /* 1 00 -> 01 */
      digitalWrite(DIR_PIN, HIGH);
      break;
    case 3: /* 0 11 -> 01 */
    case 6: /* 1 10 -> 00 */
      digitalWrite(STEP_PIN, LOW);
      break;
  }
  delayMicroseconds(5);
}

void setup() {
  Serial.begin(115200);
  penservo.attach(SERVO_PIN);

  pinMode(X_STEP_PIN, OUTPUT);
  pinMode(X_DIR_PIN, OUTPUT);
  pinMode(X_MIN_PIN, INPUT_PULLUP);
  pinMode(X_MAX_PIN, INPUT_PULLUP);

  pinMode(Y_STEP_PIN, OUTPUT);
  pinMode(Y_DIR_PIN, OUTPUT);
  pinMode(Y_MIN_PIN, INPUT_PULLUP);
  pinMode(Y_MAX_PIN, INPUT_PULLUP);
  Serial.println("Start test: Press the limit switches activate the steppen motors X & Y.");
}

int iPrefXmin = 0 ;
int iPrefXmax = 0 ;
int iPrefYmin = 0 ;
int iPrefYmax = 0 ;
int idegs = 70;

void loop() {

  // Read limit switches
  int iCurXmin = digitalRead (X_MIN_PIN) ;
  int iCurXmax = digitalRead (X_MAX_PIN) ;
  int iCurYmin = digitalRead (Y_MIN_PIN) ;
  int iCurYmax = digitalRead (Y_MAX_PIN) ;

  // When left limit switch is pressed move right, also takes in account the right limit switch (will not move to far).
  if (iCurXmin == 0 && iCurXmax == 1) do_step(X_STEP_PIN, X_DIR_PIN, 1);

  // When right limit switch is pressed move left, also takes in account the left limit switch (will not move to far).
  if (iCurXmax == 0 && iCurXmin == 1) do_step(X_STEP_PIN, X_DIR_PIN, 0);

  // When bottom limit switch is pressed move up, also takes in account the top limit switch (will not move to far).
  if (iCurYmin == 0 && iCurYmax == 1) do_step(Y_STEP_PIN, Y_DIR_PIN, 1);

  // When top limit switch is pressed down up, also takes in account the bottom limit switch (will not move to far).
  if (iCurYmax == 0 && iCurYmin == 1) do_step(Y_STEP_PIN, Y_DIR_PIN, 0);

  // If there is a status change on any of the switches print the current status.
  if ((iCurXmin != iPrefXmin) || (iCurXmax != iPrefXmax || iCurYmin != iPrefYmin) || (iCurYmax != iPrefYmax)) {
    Serial.print("Limit Switches: X-Min=");
    Serial.print(iCurXmin);
    Serial.print(", X-Max=");
    Serial.print(iCurXmax);
    Serial.print(" / Y-Min=");
    Serial.print(iCurYmin);
    Serial.print(", Y-Max=");
    Serial.println(iCurYmax);

    //Change the servo a bit
    idegs = (idegs==70) ? 110 : 70; // Set either to 70 or 110 degrees
    penservo.write(idegs);          // Sets the servo position in degrees
    
    //Store current status as previous state
    iPrefXmin = iCurXmin ;
    iPrefXmax = iCurXmax ;
    iPrefYmin = iCurYmin ;
    iPrefYmax = iCurYmax ;
  }

}

I hope this is useful for someone :slight_smile: .


#3

I’m very sure it will be


#4