Variant USART - EFeru/hoverboard-firmware-hack-FOC GitHub Wiki

This variant can be used to control the board from another board(e.g. Arduino, ESP32, ESP8266,RASPBERRY PI) or a computer via a serial protocol.
The example Arduino sketch will send commands and process the feedback.

You can also test this variant with following Web Tool, it let's you control the board and trace feedback values.
This Python code inspired by the code shared in this issue can also be used to control the firmware.

⚙️ Configuration/Parameters

Voltage Control Mode is used by default.
Use CONTROL_SERIAL_USART2 and FEEDBACK_SERIAL_USART2 for left sensor cable(default).
CONTROL_SERIAL_USART3 and FEEDBACK_SERIAL_USART3 for the right sensor cable(5v tolerant).

SIDEBOARD_SERIAL_USART2 or SIDEBOARD_SERIAL_USART3 parameters can be used instead of CONTROL_SERIAL_USART2 or CONTROL_SERIAL_USART3 to enable a different protocol implemented on the sideboard firmware. It can also be used with the Web tool for testing the different control modes/types.
You can adjust USART2_BAUD or USART3_BAUD parameters if you need different baud speed.

Please also check the parameters that are common to all the variants.

🔌 Wiring:

  • Connect blue wire to RX, green wire to TX and black wire to GND of Arduino on left sensor cable(long one
  • Only USART3(right sensor cable) is 5v tolerant

⚠️ On some boards, the black wire is 15v !!! Check with a multi-meter to make sure 15V and ground are not swapped
⚠️ Red wire from sensor cable delivers 15v !!!

Usart configuration:

By default, USART is configured with 115200 baud(parameter USART2_BAUD or USART3_BAUD), 8 data bits, no parity, one stop bit.
Prefer hardware serial on Arduino if possible.

🕹️ Input Command Structure:

Commands are send as binary frames with following structure:

  • Start frame(unsigned int16) : 0xABCD
  • Steer(signed int16) : Steer input or Left input with tank steering[-1000 - 1000]
  • Speed(signed int16) : Speed input or Right input with tank steering[-1000 - 1000]
  • Checksum(unsigned int16) : XOR checksum

The least significant byte comes first (little endian).

⛔ Error rejection

The FOC firmware will discard frames if:

  • Command length is not correct
  • Start frame is not correct
  • Checksum is not correct
  • 1 character inactivity on RX line while receiving the frame (Idle Line Detection)

A timeout will be triggered if no correct frame is received during the time specified with parameter SERIAL_TIMEOUT in config.h (160ms by default).

🎛️ Calibration:

Calibration is not required with USART control, but can be done if you use an input devices(e.g. Joystick or Throttle handle) on the Arduino and are not taking care of calibrating center value and min/max range there.

💬 Feedback:

Following feedback is sent every 10ms:

  • Start frame(unsigned int16) : 0xABCD
  • Cmd1(signed int16) : Steer or Brake(hovercar) after normalizing and mixing
  • Cmd2(signed int16) : Speed or Throttle(hovercar) after normalizing and mixing
  • SpeedR(signed int16) : Measured right wheel speed in RPM
  • SpeedL(signed int16) : Measured left wheel speed in RPM
  • Battery Voltage(signed int16) : Calibrated Battery Voltage *100
  • Temperature(signed int16) : Temperature in °C *10
  • Led(unsigned int16) : Used to control the leds on the sideboard
  • Checksum(unsigned int16) : XOR checksum

The least significant byte comes first (little endian).

This fork also has hall ticks as feedback, this one has the total current.

🧰 Troubleshooting:

If the board is beeping

  • Make sure the baud rate is 115200
  • Make sure you are using the sensor cable(left=CONTROL_SERIAL_USART2 or right=CONTROL_SERIAL_USART3) selected in config.h
  • Assuming RX or/and TX can be defective on your mainboard(port is defective on the MCU, 101 smd resistor is missing or has too high resistance), you can switch to other sensor cable in config.h
  • On some boards the wire colors might differ, try switching blue and green wires
  • Your Arduino TX/RX might not be working, you can verify that by trying with and FTDI and the Web tool to confirm the mainboard/firmware is not the issue
  • You might have to reduce the baud rate if you use software serial on the Arduino
⚠️ **GitHub.com Fallback** ⚠️