Hello community.
I need your help, i must to send a hexadecimal data to a VDF.
The problem, when transforming an int value to hex , the value of the transformation is correct but the prefix "0x" does not appear in the final value. This causes the VDF to not recognize the command.
Does anyone know how to add the prefix so that the value is recognized as a hexadecimal data?
Serial.write('0');
Serial.write('x');
{sigh} Details, please
(Like, what exactly is a "VDF"?)
consider output and code
0x1d
// -----------------------------------------------------------------------------
void setup () {
Serial.begin (9600);
char s [20];
sprintf (s, "0x%02x", 29);
Serial.println (s);
}
// -----------------------------------------------------------------------------
void loop () {
}
its a variable frecuency drive.
I tried using:
Serial.write('0');
Serial.write('x');
but the sent data is not recognized as a hexadecimal value by the VFD.
Time for some details.
I believe I've already mentioned this
I think I understand what's going on.... you have a variable, x and say it has a value of 175 (in decimal)
You read something about the VFD needing the data in HEX so you think it needs to see "0xAF" when really it needs to see 10101111 with a start bit of 0 and a stop bit of 1.
the o-scope should show something like resting HIGH then LOW,HIGH,LOW,HIGH,LOW,HIGH,HIGH,HIGH,HIGH,HIGH, resting HIGH
And what formerly AWOL said too.
well i want the VFD to work at 50hz, 26hz, 32hz etc etc. For this, I need to enter an INT value between 0 and 50. Transform that INT value into hexadecimal, I do it with the command:
print(value,HEX);
the value returned by the transformation is 32, which is correct in hexadecimal. BUT the value does not appear with the prefix "0x", where the VFD only recognizes the commands as "0x32". That "0x" is the one I need to add to the print(value,HEX) transform.
I tried it in the form
print('0');
print(x);
But it does not work.
We need details
"32" != 50
'3''2' != 0x32
print sends ascii
try
unsigned char x = value & 0x00FF;
Serial.write(x);
Can you post a link to the VFD manual, or tell us the exact model so we can look up the manual?
As already mentioned, the VFD probably expects BINARY data.
HEX is a human readable representation of binary data.
It's very unlikely that a VFD manufacturer would waste serial bandwidth requiring "0x" be prepended to values, but if the VFD requires ASCII hex, then a simple "Serial.print(x, HEX) isn't going to cut it, because it misses leading zeroes.
But it's more likely you have misinterpreted the manual - a luxury we don't have.
Can you give the make and model of the VFD? Or even better a link to the VFD manual? You may be misinterpreting the protocol but we can't know that without this information!
INVT GD10 is the model of the VFD.
i try send data in binary form, and nothing, the VFD does not respond to a command other than hexadecimal format.
According to this, the device is MODBUS over RS-485.
Can you confirm this, and that you have the appropriate hardware?
Are you certain the MODBUS communications on that model supports ASCII mode? The manual only covers the RTU mode which appears to be binary.
I got the VFD to respond to commands with these lines:
char dato = Serial.read();
if (dato=='r')
{
Serial.println("Run");
delay(50);
Serial1.write(0x01); Serial1.write(0x06); Serial1.write(0x20); Serial1.write(0x00); Serial1.write(0x00); Serial1.write(0x01); Serial1.write(0x43); Serial1.write(0xCA);
}
if (dato=='s')
{
Serial.println("Stop");
delay(50);
Serial1.write(0x01); Serial1.write(0x06); Serial1.write(0x20); Serial1.write(0x00); Serial1.write(0x00); Serial1.write(0x05); Serial1.write(0x42); Serial1.write(0x09);
}
Sending the data with a Max485 module.
Finally I need to enter an INT number that transforms it into a hexadecimal. For this I used the function (x,HEX), but it does not appear with the prefix "0x" so that the VFD responds to the command.
I tried sending the data in binary and hexadecimal without the "0x" prefix, resulting in the VFD not responding to commands.
Your understanding of the protocol is fundamentally flawed
When you send
Serial1.write(0x01); Serial1.write(0x06);
You are sending the binary values 0b1 then 0b110.
You never send "0x".
You could have written
Serial1.write(1); Serial1.write(6); Serial1.write(32); Serial1.write(0); Serial1.write(0); Serial1.write(1); Serial1.write(67);
Any "int" value is going to consist of two bytes (at least, depending on platform)
The VFD is expecting two bytes of data, so you will need to write the upper and lower byte of the int separately. You also need to calculate the correct CRC or the controller will reject the command.