Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

rboutrois said:
Few month ago I decided to install a BBS02B on my bike. It's a great motor but I was a bit disapointed with the PAS and I'm confident we can have something better

As I really like the VESC, I am thinking to integrate it in place of the original controller, but it needs a complete redesign and a custom firmware

If you are interested into this integration, I will do the redesign of the electronics, but I'm going to need some help for the firmware..
My idea of using VESC was to take advantage of already existing cheap hardware on Ebay or Aliexpress, so users could have most possible easy access. I don't believe in users having to solder components, etc. I think we should try to use an already available hardware on the market, cheap and widely available.

Currently, I am thinking in using the KT motor controllers, because of all that reasons I told. KT motor controllers are not very good at every points but are well balanced.

What I think we need to develop is the torque sensor. Maybe there is no obviously added value in using an external controller with OpenSource firmware on BBSxx comparing to original firmware that has already good flexibility in configuration, unless we add the torque sensor.
 
I am super interested in this project. For me, torque sensing is mandatory for an ebike.

Because I've got a 100mm bb, a bbshd is a possible choice, and I would prefer it's reliability over the tsdz2, as well as the available aftermarket chainrings and cranks.

I really like that the project is being done with budget in mind, but at least for me, my build is an investment I'm willing to spend a bit more on. I also seemingly have different needs than most people with bbshd: I don't want to go faster than about 30kmph and I don't really want to forego putting in my own effort on my rides.



Sent from my SM-G950F using Tapatalk

 
tchiseen said:
I am super interested in this project. For me, torque sensing is mandatory for an ebike.

Why don't you buy a Bafang Ultra then? BBSxx series is for those who prefer speed sensor over torque sensor, I see no reason to buy it if you prefer another type of assistance.
 
racingame said:
tchiseen said:
I am super interested in this project. For me, torque sensing is mandatory for an ebike.

Why don't you buy a Bafang Ultra then? BBSxx series is for those who prefer speed sensor over torque sensor, I see no reason to buy it if you prefer another type of assistance.
I would consider an "ultra", except that it can't be retrofit. I looked into it, the stated torque values were enough (160Nm, double a bbshd) to make me consider a custom build. But I'm not in possession of a metalwork shop.

The tsdz2 is the other option. They do 100mm BB apparently, but I'm shy simply because of the variety of mechanical problems folks have with it.

Sent from my SM-G950F using Tapatalk

 
Is this still ongoing? I just bought a BBSHD and I'm pretty disappointed at what I've read about the controller.
 
Toadster said:
Is this still ongoing? I just bought a BBSHD and I'm pretty disappointed at what I've read about the controller.
It’s reliable and powerful. What’s to be disappointed about? With an EggRider display you can access controller options.
 
I have a BBSHD on my bike and a BBS02 on my wife's bike, and honestly I do not have any complaints. I will state that I have taken many many versions of software programming versions to get where I am happy. While it will never sense torque, my original problem was that when pedal cadance rises and power from the motor remains constant the pedal feel would dissapear where you were doing nothing other than chasing the pedals. After much work I now have it where as pedal cadance rises the motor output drops. This way my pedal resistance remains and I still get a workout. I have it set where I use mainly PAS levels 3,4 and 5 (on uphills) Level 6 and 7 only for hill climbs. In level 3 and 4 it basically feels like a normal bike, you even forget it is electric. Not that it is not doing anything, you just do not feel it. Of course part of success is maintaining the bike in the correct gear. My system also never heats up!!
 
I would like to see this flexible open source firmware support more kits. The Tongsheng TSDZ2 has some issues that put ppl off:
  1. no fat bike support from the factory. There is a pricey 3rd party extension that only 1 or 2 merchants sell and it frequently breaks.
  2. the motor case is fragile. There are a couple reports of the motor snapping in half.
  3. there's a huge q-factor.
  4. there's a pedal symmetry problem, where the center of the pedals is to the right of the frame.
  5. the motor case has a protrusion that perforates bicycle frames.

People who buy expensive kits are less likely to tamper with them, so if the open source firmware is ported to cheaper kits it will get more widely deployed. I think L-faster would be a good kit to port the software to as well as Bafang BBSHD. Perhaps others like the MXUS would also be good candidates.
 
Cavi

Could you post your Bafang settings? Or upload a config file (somewhere?)? It sounds like your bike rides nicely with those setting. I'm always looking to improve.

Thank you
 
noviceBuilder said:
I would like to see this flexible open source firmware support more kits. The Tongsheng TSDZ2 has some issues that put ppl off:
  1. no fat bike support from the factory. There is a pricey 3rd party extension that only 1 or 2 merchants sell and it frequently breaks.
  2. the motor case is fragile. There are a couple reports of the motor snapping in half.
  3. there's a huge q-factor.
  4. there's a pedal symmetry problem, where the center of the pedals is to the right of the frame.
  5. the motor case has a protrusion that perforates bicycle frames.

People who buy expensive kits are less likely to tamper with them, so if the open source firmware is ported to cheaper kits it will get more widely deployed. I think L-faster would be a good kit to port the software to as well as Bafang BBSHD. Perhaps others like the MXUS would also be good candidates.

1) I don't know if that is true, I just saw fatbike versions on Aliexpress.
https://www.aliexpress.com/item/32749908969.html

2) Every time I have seen that happen it is user error from people installing it incorrectly. They allow their frame to press against the motor case which, over time and vibrations, causes the failure. This can be avoided by removing the bolt mount on the case and using padding.

3) That's the case with all the DIY mid-drives unless you go with a specialized frame version. You can improve it by investing in better crank arms

4) Agree, don't know if that is enough to put me off the motor though lol

5) See #2

Despite my rebuttal I do agree these motors need some upgrades. I am curious to know why the company does not improve the motors. They would get loads of sales.
 
From Doug Snyder at California eBike LLC

These files in total are 1.5 mb

I can share them by email, use messages here to share your address and I'll post them.

I MAKE NO WARRANTIES NOR GUARANTEES IN THEIR USE

18 amps smooth throttle full power PAS 1-9.el
18 amps smooth throttle full power PAS 1-9.el alias
20170613154521_0298
Arboh 1.4.el
Bafang 52V battery fix
BBS02-48vLimitless.el
BBS02-52vLimitless.el
BBS02.el
BBSHD.el
BBSHD@2ndSEPT_18.el
BBSHD@Altered.el
BBSHD48vLimitless.el
BBSHD52vLimitless.el
DefaultProfile.el
em3evbb02.el
Joel_3.1.el
Joels_Limitless.el
JPLabs_Relaxed PAS.el
Karls special.el
Kepler.el
Kickpasbbshd.el
LmtlsLdcrs48V.el
LmtlsLdcrs52V.el
Luna-BBSHD.el
M 2.0_No-Display_4.5.el
Mye_Folding_Bike_2.2.el
Penoff.el
Rix Ryds.el
 
tomjasz said:
From Doug Snyder at California eBike LLC

These files in total are 1.5 mb

I can share them by email, use messages here to share your address and I'll post them.

I MAKE NO WARRANTIES NOR GUARANTEES IN THEIR USE

18 amps smooth throttle full power PAS 1-9.el
18 amps smooth throttle full power PAS 1-9.el alias
20170613154521_0298
Arboh 1.4.el
Bafang 52V battery fix
BBS02-48vLimitless.el
BBS02-52vLimitless.el
BBS02.el
BBSHD.el
BBSHD@2ndSEPT_18.el
BBSHD@Altered.el
BBSHD48vLimitless.el
BBSHD52vLimitless.el
DefaultProfile.el
em3evbb02.el
Joel_3.1.el
Joels_Limitless.el
JPLabs_Relaxed PAS.el
Karls special.el
Kepler.el
Kickpasbbshd.el
LmtlsLdcrs48V.el
LmtlsLdcrs52V.el
Luna-BBSHD.el
M 2.0_No-Display_4.5.el
Mye_Folding_Bike_2.2.el
Penoff.el
Rix Ryds.el

Biuro@sebastianmaczuga.pl
 
Sounds like an interesting idea. Shame about the D79F9211.

For reference this is the STC in my 2016 vintage BBS02:

Code:
$ stcgal -P stc15
Waiting for MCU, please cycle power: done
Target model:
  Name: STC15F2K60S2
  Magic: F408
  Code flash: 60.0 KB
  EEPROM flash: 1.0 KB
Target frequency: 18.437 MHz
Target BSL version: 7.2.5S
Target wakeup frequency: 36.068 KHz
Target options:
  reset_pin_enabled=False
  clock_source=internal
  clock_gain=high
  watchdog_por_enabled=False
  watchdog_stop_idle=False
  watchdog_prescale=256
  low_voltage_reset=True
  low_voltage_threshold=3
  eeprom_lvd_inhibit=True
  eeprom_erase_enabled=True
  bsl_pindetect_enabled=False
  por_reset_delay=short
  rstout_por_state=high
  uart2_passthrough=False
  uart2_pin_mode=normal
  cpu_core_voltage=unknown
Disconnected!

Has anyone figured out how the functions are split across the two MCUs?

I have thought about using a VESC, but I don't really want to give up the PAS, the "walk assist mode" (when you hold down the minus button), or compatibility with the nice Bafang displays...

Cheers!
 
tomjasz said:
From Doug Snyder at California eBike LLC

These files in total are 1.5 mb

I can share them by email, use messages here to share your address and I'll post them.

I MAKE NO WARRANTIES NOR GUARANTEES IN THEIR USE

18 amps smooth throttle full power PAS 1-9.el
18 amps smooth throttle full power PAS 1-9.el alias
20170613154521_0298
Arboh 1.4.el
Bafang 52V battery fix
BBS02-48vLimitless.el
BBS02-52vLimitless.el
BBS02.el
BBSHD.el
BBSHD@2ndSEPT_18.el
BBSHD@Altered.el
BBSHD48vLimitless.el
BBSHD52vLimitless.el
DefaultProfile.el
em3evbb02.el
Joel_3.1.el
Joels_Limitless.el
JPLabs_Relaxed PAS.el
Karls special.el
Kepler.el
Kickpasbbshd.el
LmtlsLdcrs48V.el
LmtlsLdcrs52V.el
Luna-BBSHD.el
M 2.0_No-Display_4.5.el
Mye_Folding_Bike_2.2.el
Penoff.el
Rix Ryds.el

Hi tomjasz, could you send me those files to cesargaspoint@gmail.com, thank you, Cesar.
 
Done.
Buta simple search for Bafang .el files will find them as well.
 
Now that VESC has native PAS support, it would be awesome to see a VESC controller that could be swapped into the housing where the Bafang controller goes. I have done some simple layouts in the past but haven't done any high current stuff so this is beyond my abilities. Happy to look at if required IO is available on the micro to see if the standard display could be driven without extra circuitry though!
 
I think it would still be interesting to have open source firmware even if we cannot change the code running on the 79F9211 it would still give a few other possibilities for customization.

I have been probing a partially broken controller I have for the last two days trying to figure out how everything is connected and I belive I have a pretty clear picture of the most important stuff now.

Everything I have found out can be viewed here:
https://github.com/danielnilsson9/bbshd-fw

I have also made a rough shematic of the functions connected to the MCUs.
See "drawings/bbshd.pdf"

Basically the split between the MCUs are as follows:

STC15W4K32S4
* PAS
* THROTTLE
* BRAKE
* Display RX
* Display TX
* HALL sensor connections (likely only for error detection and reporting)
* Battery voltage reading (i guess for firmware overvoltage error)
* Temperature sensor (unsure, I think it is connected here, could not trace)
* Serial communication with other 79F9211

79F9211
* HALL sensor connections (for motor control)
* BRAKE (same signal to both MCUs)
* Current sense over shunt resistor (amlified by LM358)
* "Throttle" input directly connected to pin on STC MCU (i think this a filtered pwm signal where the STC MCU tells the motor control MCU how much power to give, not in any way electrically connected to real throttle signal)
* Serial communication with STC15W4K32S4


So, what needs to be done before firmware development can start is to figure out the serial communication protocol between the MCUs. It is likely only used for configuration parameters, e.g. the 79F9211 would need to know about max allowed current etc.
Hopefully it is very simple, I will hook up a logic analyzer and see what is going on.



There must be a reason bafang has choosen the 79F9211 for motor control. I belive the case is that there exists off the shelf implementation of ebike motor control with this MCU since it has been found in multiple chinese controllers.
I also found a code dump on a Chinese site which seems to have been written by Renesas Electronics.

I would not be suprised if the code running on this MCU in the BBSHD controller is based on this code.
There are multiple references to FOC, so at least in that code it seems to be implemented.

The pinout of the schematic in that dump does not really match bafangs implementation so if what I think is true then they have made significant changes to the code.

That code can be found in misc/79F9211-bike-dump
 
GREAT work!!!!!!!!

I did read all your Readme.md and all makes sense to me, seems you are very talented to make a reality this project!!

Do not forget that you can buy dirty cheap programmers and development board for that microcontroller that is programmable, that way you can save a lot of money while developing since the controller for that motor is very expensive.

When you finalize the firmware, you can always improve the Bafang BBSHD by adding the wireless EBike standard (ANT+ LEV) that we are developing for the TSDZ2.

I will keep reading the advances on this project and collaborate on the discussion / sharing of knowledge, when possible.
 
Also note that for FOC, specific parameters of motor must be used, I think. So, maybe the microcontroller that controls the motor also receives a configuration for that parameters values.
 
Back
Top