< Projects

Fork me on GitHub

Open-source BLE VESC connector

Keiran Hines
Keiran Hines
Cover Image for Open-source BLE VESC connector

Why create an open-source VESC BLE Connector?

When I modified my bike to make it an e-bike I needed to solve two problems, firstly how to control the throttle to the motor? The Flipsky ESC I planned on using included support for control via Pulse Period Modulation (PPM) signal, a standard motor control protocol. My original plan was to use an Arduino Pro Micro to send a PPM signal to the ESC. However, an Arduino did not provide a simple solution for setting configuration and getting diagnostic information to and from the ESC. The ESC does have a USB connector on board that I could use for configuration, while this could work, it would not be very practical if I needed to make configuration changes while out for a ride. It also did not provide a useful method for getting live data, such as the remaining battery from the ESC. The other option was to buy the Flipsky Bluetooth dongle based on the nrf51_vesc project, but at $26 USD I decided I would try to accomplish the same same thing with an ESP32 which can be had for around $5 USD.

The Hardware Architecture

The ESC I used was a FLIPSKY Mini FSESC6.7 PRO. The ESP32 I decided on was a TTGO T7 I chose this ESP32 because it was the smallest one I already owned. With this hardware, in theory I should be able to accomplish the same feature set as the nrf51 project whilst adding additional features by way of the ESP32's IO pins. One such feautre I wanted was a simple throttle controller. For throttle control I have settled on a simple press-button to switch throttle modes between a 0, 30, 60 and 100% state. To complete this I powered the ESP32 from the ESCs 3.3v line, used UART-2 on the ESP32 to talk to the ESC, and PIN 2 on the ESP32 to provide user input to change between throttle states.

Pushbutton mounted on handlebars
Pushbutton on handlebars
Hardware and battery mounted on bike frame
Hardware and battery mounted on bike frame
Closed bag in final form
Closed bag in final form

Bluetooth Communication

The VESC mobile application and nrf51 Bluetooth module communicate to the ESC over a simple BLE UART Service. This meant that to atleast get the same functionality as the nrf51 controller All that was needed to setup a BLE connection and pass the UART data from the the BLE to the VESC and back. The nimBLE-Arduino library and the Arduino SDK Serial libraries made short work of this. Setting up the throttle was a little bit more envolved and required understanding how the throttle values was send over UART and then diagnosing why the throttle would stop after a short time. As it turns out the throttle control required two components. Firstly a throttle position to be written. Secondly periodically a 'COMM_ALIVE' payload was required to verify the throttle controller was still connected to the ESC, otherwise the ESC would set the throttle position to 0% as a safety.

The Throttle Control Loop

The control loop I decided on for the throttle controller was quite simple.

  • When the button is pressed, the time is marked, after 500ms if the button is still pressed the throttle is moved up one position from 0 to 30%, 30% to 60% or 60% to 100%.
  • If the button is released before 1s that throttle position is locked on until the button is pressed again for a period less than 500ms.
  • If the button is held for longer than 1s the throttle will be moved to 100% whilst the button is pressed. Once the button is released the throttle will move to the last saved position. To handle the COMM_ALIVE message I decided that once the throttle was set above 0% I would send the COMM_ALIVE payload on every execute loop. This is probably a far more often than required, but I thought it would be better to send COMM_ALIVE more often and make sure the comms were okay, rather than having the throttle randomly drop to 0 if the timing was slightly out of sync.

Examples

Example 1: basic usage

  1. The throttle is not active, and the button is not pressed.
  2. The button is held, after 500ms, the throttle moves to 30%.
  3. Before 1s the button is released. The throttle stays active at 30%.
  4. Sometime later the button is pressed again for 100ms. The throttle is set back to 0%.

Example 2: stepping up gears

  1. The throttle is not active, and the button is not pressed.
  2. The button is held, after 500ms, the throttle moves to 30%.
  3. Before 1s the button is released. The throttle stays active at 30%.
  4. The button is held again, after 500ms, the throttle moves to 60%.
  5. Before 1s the button is released. The throttle stays active at 60%.
  6. Sometime later the button is pressed again for 100ms. The throttle is set back to 0%.

Example 3: Full speed first

  1. The throttle is not active, and the button is not pressed.
  2. The button is held, after 500ms, the throttle moves to 30%.
  3. After 1s the throttle moves to 100%.
  4. Sometime later the button is released The throttle is set back to 0%.

Example 3: Temporary override

  1. The throttle is active at 30%, and the button is not pressed.
  2. The button is held, after 500ms, the throttle moves to 60%.
  3. The button is still held, after 1s the throttle is moved to 100%.
  4. Sometime later the button is released. The throttle will reset to the last saved position of 30%

Wrapping up

After a quick weekends of code, and some on the bike testing my throttle controller worked really well. I am quite happy with the simplicity of the throttle control. I have only had one issue with the ESP32 and VESC app that was reported by a user on GitHub. Since that issue was patched the system has worked relatively painlessly for me. So overall I am calling this project a success, I have a working e-bike, I saved some money, and I learnt more about BLE communication what more could I ask for.

There is still some improvements I would like to make to this project. At some point I want to expiriment with a wireless throttle control button. I am undecided if I want to use BLE for a wireless button or a different wireless protocol. Size and power draw would be of highest priority as there is not a lot of space on a set handlebars to mount a battery and wireless module. One idea I want to test out is an nRF24L01 transceiver and ATTiny85. Feel free to open a discussion on the GitHub page if you have any thoughts on this project or want to know more. As with any open source project use it, fork it, and submit PRs with any improvements you make. Id be interested in seeing what the community can do.