Arduino modbus setup

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
}

kindly attach the link of the library

this lib is way too old..
last updated in 2012

i would suggest you to write a request of byte array acc to modbus frame, and transmitt it over rs485 ,
you servo will work perfectly

like this ?

#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

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
}

void loop()
{
  byte request[] = {0x01, 0x06, 0x00, 0x00, 0x00, 0x03, 0x10, 0x27}; //Modbus frame request for writing to a single register

  preTransmission();
  for (int i = 0; i < 8; i++)
  {
    Serial1.write(request[i]); //Send the byte array request over RS485
  }
  postTransmission();

  delay(5000); //Delay for 5 seconds
}

yess
it will work perfectly,
let me know if you face any issue

should be..

byte request[] = {0x01, 0x06, 0x00, 0x00, 0x00, 0x03, 0xC9, 0xCB};

checksum was off..
can use my modbus tester..
fill Salve ID to 1, Function to 6, Start to 1, Qty to value you want the Register.
then click send.. it will display the bytes for you..
have fun..
~q

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.