How can I get processing to send serial commands to a servo controller?
in
Core Library Questions
•
1 year ago
I trying to get Processing to send serial commands to a USB 16 port servo controller. The model number of this controller is the ZX_SERVO16U. I'm following the syntax for the serial commands as close as I can but the unit isn't responding. I have the port configured at 2400 baud in the device properties too. I realize that the highbyte and lowbyte are actually commands in arduino that pull the first or last 8 bits of a 16 bit word, but I couldn't find a Processing equivalent. When I turn it on, the servo's center, so don't think it's a hardware issue. The pdf that came with the servo controller is
here. Its written in PBASIC I think, and I'm having difficulties translating it. I have tried a serial port terminal program to send the code, but I'm pretty sure my formatting is wrong. If anyone has some sample code to a similar servo controller that would really help too. Any help is really appreciated! Thanks!
- import processing.serial.*;
- Serial com2;
- Byte servoCh, servoRa, lowByte, highByte;
- String SC;
- String D;
- void setup(){
- SC = "!SC";
- D = "\n";
- println(Serial.list());
- com2 = new Serial(this, "COM2", 2400);
- servoCh = 0;
- servoRa = 7;
- lowByte = 0;
- highByte = 2;
- //com2.write(SC + servoCh + servoRa + lowByte + highByte + D);
- }
- void draw() {
- lowByte = 50;
- highByte = 2;
- println("High");
- com2.write(SC + servoCh + servoRa + lowByte + highByte + D);
- println(SC + servoCh + servoRa + lowByte + highByte + D);
- delay(500);
- lowByte = 50;
- highByte = 1;
- println("Low");
- com2.write(SC + servoCh + servoRa + lowByte + highByte + D);
- println(SC + servoCh + servoRa + lowByte + highByte + D);
- delay(500);
- servoCh = byte(servoCh + 1);
- if (servoCh >= 16) servoCh = 0;
- println("Servo:" + servoCh);
- }
1