Im working on my university of controlling and monitoring VFD through Arduino. Im using Arduino Mega and have been successful in transmitting data to my VFD (slave) via RS485 ASCII protocol but have not been able to receive data from the VFD. It goes like this, when i have to read the output frequency of the VFD, i will send a command from the Arduino to the VFD to give me the output frequency, so the VFD will act on the command and it should send back its output frequency in ASCII format, but its sending me exactly the same command that i sent to receive the frequency (e.g if i send 010321030001D7, and if the frequency is lets say 50, i should receive 01030213885F, but im receiving exactly the same data that i sent i.e 010321030001D7). No such scenario is mentioned in the manual of the VFD or anywhere. I have attached the schematic, code and Delta VFD-S1 manual (you can refer page 62 chapter 5). Need help from you guys...
const unsigned char readfreq[17]={':','0','1','0','3','2','1','0','3','0','0','0','1','D','7','\r','\n'};
const int REpin = 5;
const int DEpin = 6;
void setup()
{
Serial.begin(9600);
Serial2.begin(9600,SERIAL_7N2); //VFD
pinMode(REpin, OUTPUT);
pinMode(DEpin, OUTPUT);
digitalWrite(DEpin,HIGH); // enable Rs485 transmitter
digitalWrite(REpin,HIGH); // disable Rs485 receiver
}
void loop()
{
while(Serial2.available()!=0) //checking if there is something present in serial2
{
Serial2.read(); //reading serial2 to clear out the serial buffer
}
digitalWrite(DEpin,HIGH); // enable Rs485 transmitter
digitalWrite(REpin, LOW); //enable Rs485 receiver
for(int i=0; i<17; i++)
{
Serial2.write(readfreq[i]); //Sending the command to VFD so that it sends back some data to arduino
}
while(Serial2.available()!=0)
{
Serial.println(Serial2.read()); //reading the data sent from the VFD to arduino
}
}
I tried enabling trasmitter first and then enabling the receiver after sending command, now im getting no output at all and now Serial2.available()=0.
i replaced
digitalWrite(DEpin,HIGH); // enable Rs485 transmitter
digitalWrite(REpin, LOW); //enable Rs485 receiver
for(int i=0; i<17; i++)
{
Serial2.write(readfreq[i]); //Sending the command to VFD so that it sends back some data to arduino
}
with
digitalWrite(DEpin,HIGH); // enable Rs485 transmitter
digitalWrite(REpin, HIGH); //disable Rs485 receiver
for(int i=0; i<17; i++)
{
Serial2.write(readfreq[i]); //Sending the command to VFD so that it sends back some data to arduino
}
digitalWrite(DEpin,LOW); // disable Rs485 transmitter
digitalWrite(REpin, LOW); //enable Rs485 receiver
Mmmm... enable transmitter and then immediately enable receiver. Most such systems just connect the *RE and DE line together, that is why one is made active high and the other active low. Then you can switch communication direction with one pin.
VFD is responding to other commands like RUN or STOP, but i dont need to receive anything from the VFD in these commands. But when I need to receive data from the VFD for Reading Frequency command, VFD is not showing any errors or anything else, which makes me believe it is actually sending back data and im somehow making errors in extracting it. The command is correct because the VFD is returning data in RS485 Monitoring software, but not in arduino.
const unsigned char readfreq[17] = {':', '0', '1', '0', '3', '2', '1', '0', '3', '0', '0', '0', '1', 'D', '7', '\r', '\n'};
const int REpin = 5;
const int DEpin = 6;
void setup()
{
Serial.begin(9600);
Serial2.begin(9600, SERIAL_7N2); //VFD
pinMode(REpin, OUTPUT);
pinMode(DEpin, OUTPUT);
digitalWrite(DEpin, HIGH); // enable Rs485 transmitter
digitalWrite(REpin, HIGH); // disable Rs485 receiver
}
void loop()
{
while (Serial2.available() != 0) //checking if there is something present in serial2
{
Serial2.read(); //reading serial2 to clear out the serial buffer
}
modeTX();
for (int i = 0; i < 17; i++)
{
Serial2.write(readfreq[i]); //Sending the command to VFD so that it sends back some data to arduino
}
Serial2.flush(); // wait for everything to be sent
modeRX();
while (Serial2.available() != 0)
{
Serial.println(Serial2.read()); //reading the data sent from the VFD to arduino
}
}
void modeTX() {
digitalWrite(REpin, HIGH); // disable Rs485 receiver
digitalWrite(DEpin, HIGH); // enable Rs485 transmitter
}
void modeRX() {
digitalWrite(DEpin, LOW); // disable Rs485 transmitter
digitalWrite(REpin, LOW); // enable Rs485 receiver
}
How did you come up with the transmit message? Did you calculate the checksum correctly? What about the wiring? Are you sure the RE and DE pins are actually connected properly?
BRO i just received the output. I beleive Serial2.flush() was the key. Thankyou so much bro i had almost gave up!!.
Code:
const unsigned char readfreq[17]={':','0','1','0','3','2','1','0','3','0','0','0','1','D','7','\r','\n'};
const int DEpin = 6; //i shorted RE and on pin 6
void setup()
{
Serial.begin(9600);
Serial2.begin(9600,SERIAL_7N2); //VFD
pinMode(DEpin, OUTPUT);
digitalWrite(DEpin,LOW); // disable Rs485 transmitter
}
void loop()
{
digitalWrite(DEpin,HIGH); // enable Rs485 transmitter
for(int i=0; i<17; i++)
{
Serial2.write(readfreq[i]); //Sending the command to VFD so that it sends back some data to arduino
}
Serial2.flush();
digitalWrite(DEpin,LOW); // disable Rs485 transmitter
delay(3000);
while(Serial2.available()!=0)
{
Serial.println(Serial2.read()); //reading the data sent from the VFD to arduino
}
}