ModBus RTU control (Arduino master) a VFD (Slave)

Hi

This is my first time that i am going to try something like this so i kindly looking for some help in order to understand how to make it work .

i am using an Arduino Nano and a RS485 module

First of all here is some info from my VFD manual about the ModBus communication :

Manual says that Forward command = 01H 06H 2000H 0001H 43CAH

ModBus RTU control VFD

Address : 01H (is the address of the VFD)
Function : 06H (write function code)
Starting data address : 20H
: 00H (2000H is the address of control command)
Data(2Byte) : 00H
: 01H (0001H is forward command)
CRC CHK Low : 43H
CRC CHK High : CAH (43CAH (is 16bits CRC check code)

As i can understand the "H" is not taking in count in Arduino code (no Hexadecimal with H)
Right?

One problem is not sure how to convert all the Hexadecimal in right format for Arduino (i haven't used so much these functions in my previous projects - codes in order to have more experience with them)

/*

   ModBus RTU control VFD

   Address               : 01H  (is the address of the VFD)
   Function              : 06H  (write function code)
   Starting data address : 20H
                         : 00H  (2000H  is the address of control command)
   Data(2Byte)           : 00H
                         : 01H  (0001H is forward command)
   CRC CHK Low           : 43H
   CRC CHK High          : CAH   (43CAH (is 16bits CRC check code)

*/




#include <SoftwareSerial.h>

#define SSerialRX        10  //Serial Receive pin
#define SSerialTX        11  //Serial Transmit pin
#define SSerialTxControl 3   //RS485 Direction control
#define RS485Transmit    HIGH
#define RS485Receive     LOW
#define Pin13LED         13

byte Button = 8; //  push button Forward
byte StopButton = 7; //  push button Forward

// From manual vfd Forward command = 01H 06H 2000H 0001H 43CAH

// From manual vfd Stop command = 01H 06H 2000H 0003H C20BH

byte request1[] = {00, 00, 20, 00, 00, 00, 43, 00}; // not the right values
byte request2[] = {00, 00, 20, 00, 00, 00, 43, 00}; // not the right values

SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
byte byteSend;

void setup()
{
  // Start the built-in serial port, probably to Serial Monitor
  Serial.begin(9600);
  Serial.println("SerialRemote");  // Can be ignored

  pinMode (Button, INPUT_PULLUP);      //Define the pin as input

  pinMode (StopButton, INPUT_PULLUP);      //Define the pin as input

  pinMode(Pin13LED, OUTPUT);
  pinMode(SSerialTxControl, OUTPUT);

  // digitalWrite(SSerialTxControl, RS485Receive);  // Init Transceiver


  RS485Serial.begin(9600);


}
void loop()
{


  if (digitalRead(Button) == LOW)
  {
    digitalWrite(SSerialTxControl, RS485Transmit);
    RS485Serial.write(request1, sizeof(request1));
  }

 if (digitalRead(StopButton) == LOW)
  {
    digitalWrite(SSerialTxControl, RS485Transmit);
    RS485Serial.write(request2, sizeof(request2));
  }


}

any suggestions will be welcomed
Thanks in advance

As i can understand the "H" is not taking in count in Arduino code (no Hexadecimal with H)
Right?

The 'H' postfix is translated into a '0x' prefix in the Arduino world, so '2000H' gets '0x2000'.

One problem is not sure how to convert all the Hexadecimal in right format for Arduino (i haven't used so much these functions in my previous projects - codes in order to have more experience with them)

I strongly suggest to use one of the Modbus libraries available for Arduino (ModbusMaster or ModbusRTU are good choices, SimpleModbusMaster is not recommended).

Hi and thanks for your reply

i changed the code due to your suggestion about the "H" question i had and now i can control the vfd !! :slight_smile:

// From manual vfd Forward command = 01H 06H 2000H 0001H 43CAH



byte request1[] = {0x01, 0x06, 0x20, 0x00, 0x00, 0x01, 0x43, 0xCA}

i had to change also in VFD settings the "DATA Format" in order to work with the code from Arduino.

from "even parity (E, 8, 1) to No parity (N, 8, 1)

About the suggestion to use one of the libraries , i have tried at the begging of this project to use the "ModbusMaster library" but i couldn't understand what had to do. I haven't find any good documentation how to use it.

For some reason this code i am using now i can understand better what had to do or change in order to make it work. But i guess that for my next goal , to control the VFD with "Return frame" option and also can read the status of the VFD in the way that Arduino can act dependently i had to find a way to understand the usage of the library as it will make it much easier i suppose

Ps: i am a Self-taught in Arduino code and in code general as i haven't got any previous background training.