Tutorial V: ST3215 Serial Bus Servo Control Demo

From Waveshare Wiki
Jump to: navigation, search

Modules Usage Tutorial

ST3215 Serial Bus Servo

ST3215 is a serial bus servo with large torque, and you can refer to the link to view it. The demo about how to easily control the servo is provided as follows.

Demo

Upload Demo

Firstly, you need to download the dependency library. After downloading, you need to extract it to the path of C:\Users\username\AppData\Local\Arduino15\libraries.
ST3215 Serial Bus servo demo.png
After downloading the zip package, open Servo.ino, connect the multifunctional driver board to the computer with a USB cable (here the Type-C port of the USB of the multifunctional driver board is plugged in), click "Tools" -> "Ports", and then click the new COM (COM26 in my case). Click on "Tools" → "Ports", and then click on the new COM.
In Arduino IDE, click "Tools" → "Development Board" → "ESP32" → "ESP32 Dev Module". Upload the demo after selecting the development board and the port. After uploading the demo, connect the serial bus servo to the ST3215 serial bus servo interface on the driver board, connect the XH2.54 power supply interface to the power supply, and run the demo, you can see the servo will swing back and forth.

Demo Analysis

#include <SCServo.h>

SMS_STS st;

#define S_RXD 18    //Setting the Serial Receive Pins
#define S_TXD 19    //Setting the Serial Transmitting Pins

void setup()
{
  //Initialize serial port communication, this serial port is used for communication between the USB cable and the serial monitor on the computer
  Serial.begin(115200);
  //Initializes serial port 1 communication for controlling the serial bus servo's; SERIAL_8N1 is the configuration data, parity, and stop bits; specifies the serial port pins
  Serial1.begin(1000000, SERIAL_8N1, S_RXD, S_TXD);
  //Set the serial port parameter of the SCServo object to Serial1, indicating that the 1000000 serial port is used to control the servo
  st.pSerial = &Serial1;
  delay(1000);
}

void loop()
{
  st.WritePosEx(1, 4095, 3400, 50);    //Set the position, speed and acceleration of servo 1 with a delay of 2s
  delay(2000);
  
  st.WritePosEx(1, 2000, 1500, 50);    //Set the position, speed and acceleration of servo 1 with a delay of 2s
  delay(2000);
}

Resources