EBike / EScooter motor controller, easy to DIY build and repair, with room for custom electronics board

That’s a nice project you can solder at home with components from Mouser, Amazon or Aliexpress. Very interesting. Also I like the solder bar buildup on the back.

Regarding regen braking. Im not sure the lib. has integrared a regen algorithm yet. If the controller uses 6pin pwm commutation, then it should be possible. Se the link I posted here: https://community.simplefoc.com/t/nxp-mcu-high-currents-during-align/1693/16

Basically you use the motor and controller to create a boost circuit.

In my opinion it will need a voltage “sensor” voltage devider to ensure stable boost voltage.

Naturally if the controller communicates with the BMS, then the BMS could also tell about actual charging voltage. There might be a voltage drop on the cables.

Edit: Usually a BMS will have a current sensor, at least it should have IMO, so communicating with the BMS could be usefull. Other factors like State of Charge (SOC), battery temperature and the likes would also be useful for a rugged system.

Regarding the regen, yes, it does regen. This board / firmware were tested on a M365 EScooter and there is regen braking when you apply the brake. The motor can rotate to both sides, if the user sets the motor iq_current positive the motor will rotate forward and if suddenly put a iq_current negative, the motor will brake until 0 speed and then will move backwards.

@casainho That´s really cool. Do you think its possible to migrate the regen algorithm to SimpleFoc?

I am not the motor firmware developer, I am mainly being helping on the EScooter M365 firmware, that includes the motor firmware as a module. So, I can not help on the question you ask. I only can share the source code of the motor firmware, in the hope it can help SimpleFOC developers: GitHub - EBiCS/EBiCS_motor_FOC: Motor control firmware implementing FOC for STM32F103

1 Like

Here are the images of fully assembled last version (v0.5_2022-03-19). Well, is missing / yet to be assembled, the battery wires as also the BIG capacitor on the battery wires.

The board needs to be a slightly larger to have more room for the hall sensor connectors / red capacitors and that 3 big capacitors.

The board was not yet tested, I will test it probably on next days:

5 Likes

What is the ide program use, I tried yours but no success.

Hi, this looks to be an awesome project ! I plan to prototype a kind of over board using 2 M365 wheels. Your extensible design would allow me to add a custom “shield” with the accelerometer on top of the STM32. I have a couple of questions:

  • You mentioned that you were going to test this last version. Did it work as expected ?
  • For my prototype I would need an accurate control of the wheels, torque and slow motion. Do you foresee any issue with your ESC ?
  • The “bluepill” STM32F103 looks to reach its end of life, and replaced by the “blackpill” STM32F402. The pins location is not exactly the same. Do you plan a “blackpill” version of your ESC ?

Hi everyone.

I did not work anymore on this project as it was taking to much time. If I had to change the project, I would make it to support VESC firmware and not developing my own firmware!!
Currently, I am using instead VESC motor controllers, mainly the Flipsky 75100 that supports 75V battery and 100A current. I use this VESC as a stand alone motor controller and then I use a ESP32 that runs Python firmware (Circuit Pyhton) to implement the EBike / ESCooter logic and interface with VESC by UART to send the target motor current and speed, and read the motor data, and that works very well!!
Project page: https://opensourceebike.github.io/

Why is the Bafang Controller less optimal compared to VESC? Did you manage to get a smoother ride when changing the controller and firmware?

Just out of curiosity the only reason you would consider vesc is that your own firmware takes too much time and vesc is already developed?

Cheers,
Valentine

Bafang Controller is proprietary, firmware and hardware are closed source, without the possibility for me to change any motor and battery configuration. VESC is OpenSource, popular, a generic motor controller available as a small controller of 2kW up to big ones of 20Kw or more - and so is a tool I can use on my different devices - for now I use on my EBike and recently on my stand up EScooter Xiaomi M365.

And how did the ride compare ?

Yes, I can not keep developing the firmware. I found that VESC is already very advanced, on hardware, firmware and all the software tools. My focus now is more on the high level firmware, in Python language, running on ESP32, to implement the EBike/EScooter logic and use VESC as a stand alone generic motor controller, that I interface using UART communication. I also want to improve the display, that is now also developed in Pyhton running on ESP32, with wireless programming directly from my phone or PC - both for the EBike/EScooter board and display board.

That’s awesome! Keep up the good work.

VESC is in the market for many years now, is very popular, while the Bafang motor controller is specific for the motor model I use, the M500. VESC has very advanced motor control and options, VESC is 1000x better overall.

The ride is way better, because I can now fine tune the motor reaction to the pedal torque measured by the Bafang motor torque sensor!! Also, since I also have my own DIY display, I have full control of the motor and data from the display and my phone, I can change any configuration or the firmware directly from my phone, while I am outside riding.

As you may have seen, my focus has been the STSpin32G4 for some time. It’s looking really promising and I believe it can easily drive a e-bike motor. And no, it’s not on fire. The MT6835 has a small diode.

This is for the NEMA23/34 format, but as you can see, the controller is modular. That is, the control-stage and power-stage is modular.

1 Like

Here is the way I develop wireless the Python firmware on ESP32. The EScooter is some metters way from my PC and I connect to it wireless and I can edit the firmware directly on the browser, on my PC or mobile phone:

From a DIY perspective, VESC is the big reference because is very popular (because is very good!) and the configuration software is very good, and with advanced options. BUT also, you can find at good prices on Aliexpress - 75€ (including shipping, 2 weeks) a controller for 100A 75V - see image bellow. On the firmware side, Python is also easy to learn and very easy to run on this ESP32, you just need to connect the board using a USB cable to your PC or connect by wireless - no need to any other tools, like any specific hardware programmer flasher.

So my suggestion is to go with VESC (or at least compatible with VESC hardware, to then use the VESC firmware + VESC software).

@casainho do you know the loop frequency that VESC rip-off runs at ?

It’s easy to measure just put your entire loop into a

for (int i=0;i<10000;i++){

// stuff inside loop
count++;
}

Measure the time in micros() before and after and, subtract start time from end time and divide it by count.