Creator: Andrew Mascolo Jr (HazardsMind) 3/20/2014

Download

SerialServo.zip
This library MUST be put into the Arduino sketch folder "arduino\libraries\" To import this library, simply go to Sketch -> Import library. If you do not see the library there, it is possible you put the library in the wrong spot or you did not extract the library. ** Double foldering will result in errors

Overview

The purpose for creating this library was to allow those who are designing a project who use certain libraries that prohibit the normal servo library from working. Basically anything that takes over Timer1, like the virtualwire library.

This simple library is designed to work with all JP Serial Servo Controllers, (4, 10, 23 and 34 channels).

There are two baud rates the controller can communicate at 4800 and 19200.

  • If the baud pin is tied to Vdd (+V) or left open then the baud rate needs to be set to 19200.
  • Otherwise it should be tied to Vss (GND) and baud rate should be set 4800

Constructor

SerialServo servo()

This can either be set to Serial to use pin 1 (Tx) to communicate with the controller or it can be used with the SoftwareSerial library, which will allow you to use any digital or analog pin you like.


Functions

Number_of_Channels()

This identifies what controller is used and provides the correct settings for that controller. Default is set to 4.

Move()

This is a simple function that takes two things to work, a channel number (starting from 1) and an angle (0 - 179)

AdjustLeftRight()

If when calibrating the servo and it locks up, you can change the left and right limits. (lowest left can go is 7, highest right can go is 247)

Calibrate()

This function is optional, it checks at 0 degrees, 90 and 180.


Using Serial

#include "SerialServo.h"

SerialServo servo (Serial);

void setup ()
{
  Serial.begin (19200); 
  servo.Number_of_Channels(4);
}  // end of setup

void loop() 
{ 
  for(int i = 0; i < 180; i += 10)
  {
    servo.Move(1, i); // channel 1, move servo based on for loop
    delay(200);
  }
} // end of loop

Using Software Serial

#include "SerialServo.h"
#include <SoftwareSerial.h>

const byte TX = 5;

SoftwareSerial mySerial (-1, TX, false); // set Rx pin to -1 for not used
SerialServo servo (mySerial);

void setup ()
{
  mySerial.begin (19200);
  servo.Number_of_Channels(4);
}  // end of setup

void loop () 
{ 
  for(int i = 0; i < 180; i += 10)
  {
    servo.Move(1, i);
    delay(200);
  }
}


If you have any questions, suggestions or find any bugs, you can send me a PM.

Share