Hey there, I'm having some trouble connecting my servo controller board with my Arduino board, and I'm not sure what's causing the issue. The library I'm using for my LX-16A motor from Hiwonder isn't working right - I keep getting a read timeout error, and the write function isn't working either. I've been using this library: https://github.com/madhephaestus/lx16a-servo and I'm pretty sure I've got the code right, but it's still not working. Can anyone give me some advice on how to troubleshoot this? By the way, here's a picture of how I've got the board connected:
Welcome to the forum
Your topic was MOVED to its current forum category which is more appropriate than the original as it has nothing to do with Installation and Troubleshooting of the IDE
Please post the sketch that you are running, using < CODE/ > tags when you do
const int txPin = 1; // TX pin of the Arduino connected to the data input of the bus servo controller
const int baudRate = 9600; // baud rate of the bus servo controller
void setup() {
Serial.begin(baudRate);
}
void loop() {
// move servo 1 to position 1000
int servoId = 1;
int position = 1000;
moveServo(servoId, position);
delay(1000);
// move servo 1 to position 2000
position = 2000;
moveServo(servoId, position);
delay(1000);
}
void moveServo(int servoId, int position) {
// prepare the command packet
byte commandPacket[] = {0x55, 0x55, 0x06, 0x03, servoId, position & 0xFF, position >> 8, 0x00};
// calculate the checksum
byte checksum = 0;
for (int i = 2; i < 7; i++) {
checksum ^= commandPacket[i];
}
commandPacket[7] = checksum;
// send the command packet to the servo controller
for (int i = 0; i < sizeof(commandPacket); i++) {
Serial.write(commandPacket[i]);
}
}
no "includes"?
Please post details of the servo controller that you are using. Why do you need to use the controller board rather than controlling the servo directly from the Uno ?
What baud rate does the servo/controller work at ? What baud rate is the sketch using ?
are you disconnecting USB while testing? because you using 0/1 Pins which used for USB converter on UNO
but actually you able hold reset button and send uart commands directly from Serial Monitor of IDE to servo control board.
I use this type of controller: https://www.hiwonder.com/collections/servo-controller/products/serial-bus-servo-controller
Thank you! I will take your suggestion.
The baud rate is 9600.
I have contacted Hiwonder technical support team, and they sent me a new program. The problem was resolved but thank you for your kind reply:)
classic "I got the solution, see ya'" . @ashlyg and others: If you find a solution to your problem, please post your solution to help others!
@ashlyg would be nice if you can drop your code and the solution as I am currently struggling with these motors along with that controller
I have a code that works on my side. Sometimes you have to press the "Run" button on the card for it to work. It's not perfect, but functional. I hope it helps you, and if you can improve it don't hesitate.
#include <SoftwareSerial.h>
// Define baud rate
const int baudRate = 9600;
// Define pins for serial communication (adjust if needed based on your setup)
const int txPin = 1;
const int rxPin = 0;
// Create a SoftwareSerial object
SoftwareSerial serial(txPin, rxPin);
void setup() {
// Initialize serial communication
serial.begin(9600);
}
void loop() {
// Send servo move command to write 0 degrees to servo ID 0x01
sendServoMoveCommand(0x01, 1000, 500);
// Wait for some time before sending the next command (optional)
delay(1000);
sendServoMoveCommand(0x01, 0, 1000);
delay (1000);
}
// Function to send data in the specified format
void sendData(byte data[], int length) {
for (int i = 0; i < length; i++) {
serial.write(data[i]);
}
}
// Function to create and send a command for servo movement
void sendServoMoveCommand(byte servoID, int angle, int time) {
byte data[10];
// Frame header
data[0] = 0x55;
data[1] = 0x55;
// Calculate data length
data[2] = 0x08;
// Command byte
data[3] = 0x03; // CMD_SERVO_MOVE
// Angle (high and low byte)
data[4] = 0x01; // Low byte
data[5] = time & 0xFF; // High byte
// Set servo ID
data[6] = (time >> 8) & 0xFF;
data[7] = servoID; //ID
data[8] = angle & 0xFF; // High byte of time
data[9] = (angle >> 8) & 0xFF;
// Send the data
sendData(data, 10);
}
Im currently using this same board and an arduino Uno. Im using the HTS-35H Servo and I'm struggling. I have been trying to learn how to write some simple code for this servo. I just want to be able to input what angle I want and I want it to do it for 2 of these separately but I don't know where to start. If someone could guide me in the direction I need to head to learn how to code this I would be grateful. I was hoping it would be something as simple as just telling the control board what servo to move and in what direction but it seems like it wont be that easy. Got any pointers?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.