ESP8266 oDrive UART comms

I’m using an Adafruit Huzzah ESP8266 board to talk to the oDrive UART. The oDrive is receiving and responding to commands - I’ve only tried setting position, but it works fine. I’m experiencing problems reading properties from oDrive - I’m getting ‘unknown command’ back when I send ‘r vbus_voltage\n’.

I’ve looked at the oDriveArduino source files and I’m implementing the comms directly without the library. Here’s the essence of the code:

Serial.begin(115200);
printf("r vbus_voltage\n");
delay(1000);
float volts = oDriveReadString().toFloat();
//volts is sent to a web socket so I can check it - it's always 0.00

String oDriveReadString() {
  String str = "";
  static const unsigned long timeout = 1000;
  unsigned long timeout_start = millis();
  for (;;) {
    while (!Serial.available()) {
      if (millis() - timeout_start >= timeout) {
          return str;
      }
    }
    char c = Serial.read();
    if (c == '\n')
      break;
    str += c;
  }
  return str;
}

I gather from the forum that there shouldn’t be an issue with ESP8266 and oDrive logic levels - they are both 3.3 V.

Looking at ascii_protocol.cpp, the only way ‘unknown command’ can be returned is if the first character of the command isn’t recognised (e.g. cmd[0] != ‘r’). I don’t have a clue why my cmd[0] isn’t ‘r’ - I’m sending an ‘r’ as required, and the position command ‘p’ works fine.

Do you have a logic analyzer or oscilloscope to check what is actually going out on the lines?

Why the 1s delay after you send the command?
The odrive will immediately reply after getting that command. It’s probably buffering but still you probably don’t want to do that. I’m doing nothing but serial communication in .net with the odrive and none of my commands to the odrive involve waiting before getting a response.

Also, you should look into arduino stuff to see if there is a read line command rather than reading all characters. Not sure there is one but it there is then it would simplify things a bit.

Long time since I touched serial stuff with arduino but aren’t you supposed to invoke the serial object when printing on the uart bus?

Edit
Serial.print:
https://www.arduino.cc/reference/en/language/functions/communication/serial/print?from=Reference.PrintHex

No readline function but you’d probably want to modify your function and test for the new line character to terminate the function early. Keep the timeout, it’s good failsafe.

Thanks - I have a logic analyser and will check what’s happening as you suggest.