I would like to share my latest work. As my EBike uses the Bafang M500 motor, there is no OpenSource firmware for it and the original firmware has limitations and lack of features. Bafang has a few different motors and versions, and so I decided to not develop the firmware for a specific model. Instead, I will used the popular OpenSource VESC motor controller as a DIY build to replace the original motor controller -- the beauty of this is that VESC runs any motor, so the work I am doing can be reused to TSDZ2, mainly the V2 version where there is no OpenSource firmware for it. This solution of using VESC is future prof, quick and easy to reuse to any other motor / EBike brand.
I am also use a simple DIY EBike board, to read the sensors as the throttle, torque sensor and brake. Then this board will map the torque sensor value to motor current / torque value, that is sent to VESC. This is the same logic on our OpenSource firmware for TSDZ2. This time, I decided to do it in Python an high level language, so will be easy for any software developer to understand and contribute with improvements.
The Bafang motors uses a torque sensor with CANBUS communications but TSDZ2 do it differently. Someone would need to look at TSDZ2 motor controller board circuit to read the torque sensor and then it could be added to this EBike board.
I got the Bafang M500 motor running using a throttle. The code I did, reads the throttle value and maps that value to a motor current value, that I send to VESC using command COMM_SET_CURRENT.
[youtube]QEnLWcn1LbE[/youtube]
Here is the current EBike board. Black and red wires powers the EBike board from the VESC. Yellow and white wires are UART tx and rx, for communication with VESC.
The throttle has 3 wires. The blue is the throttle output analog signal and the others are GND and 3.3V that powers the throttle. There is one resistor of 100K, as seen on the following schematic:
And this is the current Python code of the EBike board: