Hello everybody,
I have a motor driver which can be controlled over RS232 and using ESP32-wroom to control driver.
I have a command to control motor and a query command to check driver status.
I have to write "AB EC 10 00 00 00 E8 93" this is a command to control motor speed and position and after sending this command driver sends back a acknowledge data as 11 byte. After that I send data to query the motor position with a query command " AC 08 00 00 00 00 00 00" and this return the rotor position data with 6 byte data.
Here is the code
void loop()
{
currentTime = millis();
if (currentTime - lastTime >= 100)
{
lastTime = currentTime;
ads.setMux(ADS1115_REG_CONFIG_MUX_SINGLE_0);
ads.triggerConversion();
AdcValue = ads.getConversion();
Serial2.write(0xAB);
Serial2.write(0xEC);
Serial2.write(0x10);
Serial2.write(0x00);
Serial2.write(0x00);
Serial2.write(0x00);
Serial2.write(0xE8);
Serial2.write(0x93);
delay(5);
if (Serial2.available() > 9)
{
for (int i = 0; i < 11; i++)
{
myinput = Serial2.read();
MotorDatainput[i] = myinput;
}
}
delay(25);
Serial2.write(0xAC);
Serial2.write(0x08);
Serial2.write(0x00);
Serial2.write(0x00);
Serial2.write(0x00);
Serial2.write(0x00);
Serial2.write(0x00);
Serial2.write(0x00);
delay(25);
if (Serial2.available() > 5)
{
Serial.print("****");
MotorPos[0] =Serial2.read();
MotorPos[1] =Serial2.read();
MotorPos[2] =Serial2.read();
MotorPos[3] =Serial2.read();
MotorPos[4] =Serial2.read();
MotorPos[5] =Serial2.read();
}
Serial.print("<");
Serial.print(AdcValue);
Serial.print("<");
Serial.printf("%02x",MotorDatainput[0]);
Serial.printf("%02x",MotorDatainput[1]);
Serial.printf("%02x",MotorDatainput[2]);
Serial.printf("%02x",MotorDatainput[3]);
Serial.printf("%02x",MotorDatainput[4]);
Serial.printf("%02x",MotorDatainput[5]);
Serial.printf("%02x",MotorDatainput[6]);
Serial.printf("%02x",MotorDatainput[7]);
Serial.printf("%02x",MotorDatainput[8]);
Serial.printf("%02x",MotorDatainput[9]);
Serial.printf("%02x",MotorDatainput[10]);
Serial.print("<");
Serial.printf("%02x",MotorPos[0]);
Serial.printf("%02x",MotorPos[1]);
Serial.printf("%02x",MotorPos[2]);
Serial.printf("%02x",MotorPos[3]);
Serial.printf("%02x",MotorPos[4]);
Serial.printf("%02x",MotorPos[5]);
Serial.println();
}
}
the output should be
****<adcvalue<ABEB000001010000009C01<AC080000003B
but output is below:
****<adcvalue<AC080000003B0000009C01<ABEB00000101
what am I doing wrong? I could not figure out the error. I have to send data as wanted over udp and still stuck on getting data correctly.
Thanks