Skip to main content

6.1 Arduino IDE

Installation Steps:

A. Hardware Setup

  1. Power Supply:
    • Use a DC power supply with 6-12.6V (12V recommended).
    • For multiple servos, ensure sufficient current to power all units.
  2. Connection:
    • Connect the servo to a Arduino board.
    • Use a USB cable to connect the driver board to your computer for configuration.

B. Software Configuration:

Arduino IDE Setup

  1. Install Arduino IDE:
    • Download and install Arduino IDE version 2.1.0.
    • During installation, approve any driver prompts.
  2. Add ESP32 Board Manager URL:

  1. Install Required Libraries:
    • Open Tools > Manage Libraries.
    • Install:
      • Adafruit SSD1306
      • Adafruit NeoPixel
  2. Download and Prepare Source Files:
    • Download the servo driver open-source program (e.g., ServoDriverST and SCServo).
    • Copy the SCServo folder to DocumentsArduinolibraries.
  3. Upload the Program:
    • Open ServoDriverST.ino in Arduino IDE.
    • Set board as ESP32 Dev Module.
    • Select COM port.

  • Configure settings under Tools, including baud rate and partition scheme.

  • Upload the program and verify success with the message "Leaving... Hard resetting via RTS pin."

Secondary Development

A. Initialization:

#include <SCServo.h>

SMS_STS st;



void setup(){

Serial1.begin(1000000); // Initialize serial port

st.pSerial = &Serial1;

}

B. Change Servo ID:

#include <SCServo.h>

SMS_STS st;



void setup(){

Serial1.begin(1000000);

st.pSerial = &Serial1;

st.unLockEprom(1); // Unlock EPROM

st.writeByte(1, SMS_STS_ID, 2); // Change ID from 1 to 2

st.LockEprom(2); // Lock EPROM

}

C. Ping Command:

  • Test servo connectivity using:
st.Ping(TEST_ID);

D. Real-Time Feedback:

  • Obtain position, speed, load, and voltage for closed-loop control.

E. Write Postion :

#include <SCServo.h>  
SMS_STS st;
void setup()
{
Serial1.begin(1000000);
st.pSerial = &Serial1;
while(!Serial1) {}
}

void loop()
{
st.WritePos(1, 1000, 1500, 50); // Control the servo with ID 1 to rotate to the position of 1000 at a speed of 1500 and start and stop the acceleration of 50.
delay(754);//[(P1-P0)/V]*1000+100

st.WritePos(1, 20, 1500, 50); // Control the servo with ID 1 to rotate to the position 20 at a speed of 1500 and start and stop the acceleration at 50.
delay(754);//[(P1-P0)/V]*1000+100
}

F. Synchronous write :

#include <SCServo.h>  
SMS_STS st;

// the uart used to control servos.
// GPIO 18 - S_RXD, GPIO 19 - S_TXD, as default.
#define S_RXD 18 //Custom IO pins of the serial port. If a custom serial port is not used, replace Serial1.begin(1000000, SERIAL_8N1, S_RXD, S_TXD); with Serial1.begin(1000000);
#define S_TXD 19

byte ID[2];
s16 Position[2];
u16 Speed[2];
byte ACC[2];

void setup()
{
Serial1.begin(1000000, SERIAL_8N1, S_RXD, S_TXD);
st.pSerial = &Serial1;
delay(1000);
ID[0] = 1; // Save the IDs of the servos that need to be controlled into the ID[]
ID[1] = 2; // Save the IDs of the servos that need to be controlled into the ID[]
Speed[0] = 3400; // Set the servo speed, Speed[0] should correspond to the servo with ID[0]
Speed[1] = 3400; // Set the servo speed, Speed[1] should correspond to the servo with ID[1]
ACC[0] = 50; // Set the start/stop acceleration. The smaller the value, the lower the acceleration. The maximum value that can be set is 150.
ACC[1] = 50;
}

void loop()
{
Position[0] = 3000; // Set the target position for the servo with ID[0] (which has an ID of 1) to a range of 0-4095
Position[1] = 3000; // Set the target position for the servo with ID[0] (which has an ID of 1) to a range of 0-4095
st.SyncWritePosEx(ID, 2, Position, Speed, ACC);//servo(ID1/ID2) speed=3400,acc=50,move to position=3000.
delay(2000);

Position[0] = 100;
Position[1] = 100;
st.SyncWritePosEx(ID, 2, Position, Speed, ACC);//servo(ID1/ID2) speed=3400,acc=50,move to position=100.
delay(2000);
}

G. Get Servo Feedback:

#define S_RXD 18  
#define S_TXD 19
#include <SCServo.h>

SMS_STS sms_sts;

void setup()
{
Serial1.begin(1000000, SERIAL_8N1, S_RXD, S_TXD);
Serial.begin(115200);
sms_sts.pSerial = &Serial1;
delay(1000);
}

void loop()
{
int Pos;
int Speed;
int Load;
int Voltage;
int Temper;
int Move;
int Current;
if(sms_sts.FeedBack(1)!=-1){
Pos = sms_sts.ReadPos(-1);
Speed = sms_sts.ReadSpeed(-1);
Load = sms_sts.ReadLoad(-1);
Voltage = sms_sts.ReadVoltage(-1);
Temper = sms_sts.ReadTemper(-1);
Move = sms_sts.ReadMove(-1);
Current = sms_sts.ReadCurrent(-1);
Serial.print("Position:");
Serial.println(Pos);
Serial.print("Speed:");
Serial.println(Speed);
Serial.print("Load:");
Serial.println(Load);
Serial.print("Voltage:");
Serial.println(Voltage);
Serial.print("Temper:");
Serial.println(Temper);
Serial.print("Move:");
Serial.println(Move);
Serial.print("Current:");
Serial.println(Current);
delay(10);
}else{
Serial.println("FeedBack err");
delay(500);
}

Pos = sms_sts.ReadPos(1); // Get the position feedback
if(Pos!=-1){
Serial.print("Servo position:");
Serial.println(Pos, DEC);
delay(10);
}else{
Serial.println("read position err");
delay(500);
}

Voltage = sms_sts.ReadVoltage(1); //Get the voltage feedback
if(Voltage!=-1){
Serial.print("Servo Voltage:");
Serial.println(Voltage, DEC);
delay(10);
}else{
Serial.println("read Voltage err");
delay(500);
}

Temper = sms_sts.ReadTemper(1); //Get the temperature feedback
if(Temper!=-1){
Serial.print("Servo temperature:");
Serial.println(Temper, DEC);
delay(10);
}else{
Serial.println("read temperature err");
delay(500);
}

Speed = sms_sts.ReadSpeed(1); //Get the speed feedback
if(Speed!=-1){
Serial.print("Servo Speed:");
Serial.println(Speed, DEC);
delay(10);
}else{
Serial.println("read Speed err");
delay(500);
}

Load = sms_sts.ReadLoad(1); //Get the load feedback
if(Load!=-1){
Serial.print("Servo Load:");
Serial.println(Load, DEC);
delay(10);
}else{
Serial.println("read Load err");
delay(500);
}

Current = sms_sts.ReadCurrent(1); //Get the current feedback
if(Current!=-1){
Serial.print("Servo Current:");
Serial.println(Current, DEC);
delay(10);
}else{
Serial.println("read Current err");
delay(500);
}

Move = sms_sts.ReadMove(1); //Get the movement feedback
if(Move!=-1){
Serial.print("Servo Move:");
Serial.println(Move, DEC);
delay(10);
}else{
Serial.println("read Move err");
delay(500);
}
Serial.println();
}

For more information, visit https://www.waveshare.com/wiki/ST3215_Servo .