Hi, I have an AC Servo that has 10000 steps per revolution. I used step and dir before i now want to try modbus. Using modbus, i want to an Arduino c program that moves the AC Servo one revolution. Using a C25B RS485 to TTL converter; Is my "Arduino to AC Servo" hardware setup correct? will the Code result in a spin of one revolution?
The wiring is:
Arduino UNO - 5 to C25B - RO
Arduino UNO - 6 to C25B - DI
Arduino UNO - 9 to C25B - RE
Arduino UNO - 10 to C25B - DE
Arduino UNO - 5V to C25B - VCC
Arduino UNO - GND to C25B - GND
AC Servo Driver - A to C25B A
AC Servo Driver - B to C25B B
AC Servo Driver - G to Arduino UNO GRD
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
#define MAX485_RE_NEG 9
#define MAX485_DE 10
//define the rx and tx for Serial1
const byte rxPin =5;
const byte txPin =6;
SoftwareSerial Serial1 (rxPin, txPin); //Define another Serial channel, to use the main for debuggin
ModbusMaster node; // Define a ModbusMaster object called node
void preTransmission()
{
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
void postTransmission()
{
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
void setup()
{
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
Serial.begin(9600);
Serial1.begin(9600); //Define both serial channels at 9600 bps
node.begin(1, Serial1); //Start the serial comm over node object, with Serial1...
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
node.writeSingleRegister(0, 10000); //Write 10000 steps to the register address 0
delay(5000); //Delay for 5 seconds
node.writeSingleRegister(0, 0); //Write 0 steps to the register address 0, to bring the servo back to its starting position
delay(5000); //Delay for 5 seconds
}