Sending commands to Lynxmotion Robotic Arm.

by raulzito234

First to test if the serial port is working upload the following code:

#include

Servo servo1;

void setup() {
    pinMode(1,OUTPUT);
    servo1.attach(14); //servo 1

    Serial.begin(4800);
    Serial.println(" Hello World");
}

void loop() {
    static int v = 0;

    if ( Serial.available()) {
        char ch = Serial.read();

        switch(ch) {
            case '0'...'9':
                v = v * 10 + ch - '0';
                servo1.write(v);
        }
    }
}

Open the Serial Monitor and check if the printed word is Hello World. If it is then proceed to the next step (The baud rate is a common problem that can cause to not print the appropriate word).

To send Commands to the Robotic Arm first upload the following code using the same baud rate as you used above through the arduino software (http://arduino.cc/en/Main/Software):

#include <Servo.h>

Servo servo1;

void setup() {
    pinMode(1,OUTPUT);
    servo1.attach(14); //servo 1
    Serial.begin(4800);
    Serial.println("Ready");
}

void loop() {
    static int v = 0;

    if ( Serial.available()) {
        char ch = Serial.read();
        switch(ch) {
           case '0'...'9':
           v = v * 10 + ch - '0';
           servo1.write(v);
        }
    }
}

Then open the Serial Monitor and use the commands to control it.

To check the official arduino go to http://playground.arduino.cc/Learning/SingleServoExample

Advertisements