A few weeks ago I have bought a 500W 48V (DPC-18 Display) BBS02B kit to make my daily commute (15km one direction) a little bit easier. I'm very happy with the kit, already cycled more than 700 km's in a few weeks.
The thing is, this set is not entirely legal in the Netherlands. So I wanted to have a discrete and easy way to limit the speed of the bicycle (to say max 27 km/h) (not that I am naive enough to think that this would make things legal.. I just liked the challenge
). I was triggered by the fact that serial protocol is used to program the BBS controller.
I have recently started to learn working with Arduino's, and I thought: what if I place an Arduino between the display and the controller that simply forwards all comunnication between the two and when needed, it can send commands to the controller to program another speed limit. To do so, I have build the following circuit:

I have used a RobotDyn Mega 2560 PRO MINI (https://robotdyn.com/mega-2560-pro-mini-atmega2560-16au.html) with the ATmega2560 chip. The RobotDyn is small and the ATmega2560 has a total of four hardware serial ports. I used a Hall sensor as an "invisible" switch to switch between unlimited speed ('by displays command') and limited speed (27 km/h). I used a display extension cable, to make the connections between the display and controller. I power the arduino using a 5v usb output I have on the battery pack. The final project looks like this:



I have glued a metal ring inside the box where the hall sensor is located. This metal ring holds the magnet in place on the outside of the box:

I have added a bluetooth HC05 module to monitor the traffic between the display and the controller and it gives me a way to interact with the Arduino and controller.
So, how does it work? With the box between the controller and display, the BBS works just like normal, all communication is just being forwarded between the display and the controller. When I take away the magnet, the Arduino programs predefined settings (from the Pedal Assist tab on Penoff's tool) where speed limit is set to 27km/h. The arduino follows this sequence:
- If the display is sending any command,wait for it to finish
- program the pedal assist settings and check confirmation by the controller
- change to PAS level 0
- go back to previous PAS level
In order for the settings to be effecitve (with the system on and while cycling), the PAS level has to be changed. Thats what the last two steps are for (go to PAS 0 en restore previous PAS level).
To program the Pedal Assist settings, I send the follolwing (HEX) command to the controller:
16 53 is the command for programming the Pedal Assist settings
0B 03 FF FF 14 04 04 FF 14 08 00 3C are the settings
D2 is a checksum bit.
Out off lazyness, I have used Penoff's software, to generate the command for me. I installed Com0Com (http://com0com.sourceforge.net/) and setup a virtual Com-port pair. On one of the two paired com-ports, I connect with a terminal (such as Hterm), on the other port of the pair I connect Pennoff's tool. Penoff's software is trying to connect with the controller (sending
to receive the general controller information). Using hterm, I respond:
Pennoff's tool now believes it is connected the controller (the response code contains general info about the controller type such as manufacturer, model, hardware version, firmware version etc.)
If you then go to the Pedal Assist tab, adjust the settings to your wishes and press "write", the software sends the command to the controller. You can capture this in the hterm terminal:

This way, I generated the command to program unlimited speed, and limited speed. Of course, you can also learn how the command is structured and build the command yourself.
In the next post, the full Arduino code that I'm currently using and in the post after, I'll describe more about what I have found out about the communication protocol.
Sources I have used:
https://github.com/philippsandhaus/bafang-python
https://endless-sphere.com/forums/viewtopic.php?f=2&t=74692&p=1207355
https://gitlab.com/bafang
https://penoff.me/2016/01/13/e-bike-conversion-software/
http://com0com.sourceforge.net/
https://chromium.googlesource.com/apps/libapps/+/master/hterm
The thing is, this set is not entirely legal in the Netherlands. So I wanted to have a discrete and easy way to limit the speed of the bicycle (to say max 27 km/h) (not that I am naive enough to think that this would make things legal.. I just liked the challenge
I have recently started to learn working with Arduino's, and I thought: what if I place an Arduino between the display and the controller that simply forwards all comunnication between the two and when needed, it can send commands to the controller to program another speed limit. To do so, I have build the following circuit:

I have used a RobotDyn Mega 2560 PRO MINI (https://robotdyn.com/mega-2560-pro-mini-atmega2560-16au.html) with the ATmega2560 chip. The RobotDyn is small and the ATmega2560 has a total of four hardware serial ports. I used a Hall sensor as an "invisible" switch to switch between unlimited speed ('by displays command') and limited speed (27 km/h). I used a display extension cable, to make the connections between the display and controller. I power the arduino using a 5v usb output I have on the battery pack. The final project looks like this:



I have glued a metal ring inside the box where the hall sensor is located. This metal ring holds the magnet in place on the outside of the box:

I have added a bluetooth HC05 module to monitor the traffic between the display and the controller and it gives me a way to interact with the Arduino and controller.
So, how does it work? With the box between the controller and display, the BBS works just like normal, all communication is just being forwarded between the display and the controller. When I take away the magnet, the Arduino programs predefined settings (from the Pedal Assist tab on Penoff's tool) where speed limit is set to 27km/h. The arduino follows this sequence:
- If the display is sending any command,wait for it to finish
- program the pedal assist settings and check confirmation by the controller
- change to PAS level 0
- go back to previous PAS level
In order for the settings to be effecitve (with the system on and while cycling), the PAS level has to be changed. Thats what the last two steps are for (go to PAS 0 en restore previous PAS level).
To program the Pedal Assist settings, I send the follolwing (HEX) command to the controller:
Code:
16 53 0B 03 FF FF 14 04 04 FF 14 08 00 3C D2
16 53 is the command for programming the Pedal Assist settings
0B 03 FF FF 14 04 04 FF 14 08 00 3C are the settings
D2 is a checksum bit.
Out off lazyness, I have used Penoff's software, to generate the command for me. I installed Com0Com (http://com0com.sourceforge.net/) and setup a virtual Com-port pair. On one of the two paired com-ports, I connect with a terminal (such as Hterm), on the other port of the pair I connect Pennoff's tool. Penoff's software is trying to connect with the controller (sending
Code:
11 51 04 B0 05
Code:
51 10 48 5A 58 54 53 5A 5A 36 32 32 32 30 31 31 01 14 1B
If you then go to the Pedal Assist tab, adjust the settings to your wishes and press "write", the software sends the command to the controller. You can capture this in the hterm terminal:

This way, I generated the command to program unlimited speed, and limited speed. Of course, you can also learn how the command is structured and build the command yourself.
In the next post, the full Arduino code that I'm currently using and in the post after, I'll describe more about what I have found out about the communication protocol.
Sources I have used:
https://github.com/philippsandhaus/bafang-python
https://endless-sphere.com/forums/viewtopic.php?f=2&t=74692&p=1207355
https://gitlab.com/bafang
https://penoff.me/2016/01/13/e-bike-conversion-software/
http://com0com.sourceforge.net/
https://chromium.googlesource.com/apps/libapps/+/master/hterm