Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Discussions related to motors other than hub motors.
This includes R/C motors, botttom bracket, roller and geared drives.
casainho   100 GW

100 GW
Posts: 5155
Joined: Feb 14 2011 2:43pm

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by casainho » Sep 09 2019 6:03am

rboutrois wrote:
Sep 09 2019 4:27am
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.
- EBike wireless standard: wireless motor, wireless cycling GPS display Garmin Edge and wireless remote with wireless brake sensor
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of OpenSource knowledge and technology for ebikes: Wireless EBike standard ANT+ and Bluetooth, TSDZ2 OpenSource firmware, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

Please consider a donation to help developments: paypal.me/jorgecasa

tchiseen   10 µW

10 µW
Posts: 5
Joined: Aug 04 2019 6:06am

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by tchiseen » Sep 24 2019 4:49am

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


racingame   100 W

100 W
Posts: 118
Joined: Jan 26 2018 9:40am

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by racingame » Sep 24 2019 4:40pm

tchiseen wrote:
Sep 24 2019 4:49am
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.

User avatar
Alan B   100 GW

100 GW
Posts: 7775
Joined: Sep 11 2010 7:43am
Location: San Francisco Bay Area, USA
Contact:

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by Alan B » Sep 24 2019 4:45pm

BBS02 fits most frames.

Bafang Ultra is for frame builders only, requires custom frame built to drive. A pretty exclusive club. Not suitable for existing bike.

tchiseen   10 µW

10 µW
Posts: 5
Joined: Aug 04 2019 6:06am

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by tchiseen » Sep 24 2019 11:37pm

racingame wrote:
tchiseen wrote:
Sep 24 2019 4:49am
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


User avatar
Alan B   100 GW

100 GW
Posts: 7775
Joined: Sep 11 2010 7:43am
Location: San Francisco Bay Area, USA
Contact:

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by Alan B » Sep 24 2019 11:39pm

BBSHD is commonly rated at 160 NM as well.

According to calculations this would occur at about 55 amps motor current - the Kv is 3.27 rpm/volt and Kt is 2.92 newton-meters per amp. These values include the motor and the 21.9:1 gear train so are "at the crank" values.

Cbisbaf   10 mW

10 mW
Posts: 24
Joined: May 04 2019 3:26pm

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by Cbisbaf » Sep 25 2019 7:36am

got more controller photos here hopefully they can help someone.

https://photos.app.goo.gl/c1CuJYxQWtK27Z5J7

casainho   100 GW

100 GW
Posts: 5155
Joined: Feb 14 2011 2:43pm

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by casainho » Sep 25 2019 7:46am

Cbisbaf wrote:
Sep 25 2019 7:36am
got more controller photos here hopefully they can help someone.

https://photos.app.goo.gl/c1CuJYxQWtK27Z5J7
Thanks, those are very good detailed photos!!
- EBike wireless standard: wireless motor, wireless cycling GPS display Garmin Edge and wireless remote with wireless brake sensor
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of OpenSource knowledge and technology for ebikes: Wireless EBike standard ANT+ and Bluetooth, TSDZ2 OpenSource firmware, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

Please consider a donation to help developments: paypal.me/jorgecasa

Cbisbaf   10 mW

10 mW
Posts: 24
Joined: May 04 2019 3:26pm

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by Cbisbaf » Sep 25 2019 8:03am

casainho wrote:
Sep 25 2019 7:46am
Cbisbaf wrote:
Sep 25 2019 7:36am
got more controller photos here hopefully they can help someone.

https://photos.app.goo.gl/c1CuJYxQWtK27Z5J7
Thanks, those are very good detailed photos!!
if you would like dimensions of the board to hopefully one day jlcpcb a fella with the vesc implemented. would love to say i can do that but its way beyond changing a few components.

Toadster   100 µW

100 µW
Posts: 8
Joined: Nov 03 2019 3:30pm
Location: BC, Canada

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by Toadster » Nov 03 2019 3:41pm

Is this still ongoing? I just bought a BBSHD and I'm pretty disappointed at what I've read about the controller.

User avatar
tomjasz   10 GW

10 GW
Posts: 4377
Joined: Mar 29 2014 1:45pm
Location: Out riding, MN USA
Contact:

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by tomjasz » Nov 03 2019 10:12pm

Toadster wrote:
Nov 03 2019 3:41pm
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.
Thanks Justin_le we're here thanks to you. All the best to the mods for their tireless work keeping it on an even keel.

cavi   10 W

10 W
Posts: 79
Joined: Jan 20 2020 7:00pm

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by cavi » Apr 13 2020 8:29pm

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!!

noviceBuilder   1 mW

1 mW
Posts: 17
Joined: Apr 03 2020 5:00pm

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by noviceBuilder » Apr 15 2020 11:15am

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.

fireflyer451   10 mW

10 mW
Posts: 30
Joined: Aug 28 2019 7:00am

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by fireflyer451 » Apr 15 2020 12:21pm

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

Aquakitty   100 W

100 W
Posts: 171
Joined: Jun 10 2017 3:07pm

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by Aquakitty » Apr 15 2020 11:08pm

noviceBuilder wrote:
Apr 15 2020 11:15am
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.
Rans Enduro Sport w/Sturmey-Archer XFRD8, TSDZ2 open source mod 48v
GT Verb Comp f/s TSDZ2 open source 48v
Diadora Ampio bargain f/s TSDZ2 48v
2020 Diamant 247 belt drive 1000w 9C 48v
Hardtail made from random bits I had laying around, ginormous old Marzocchi fork, BBS02

User avatar
tomjasz   10 GW

10 GW
Posts: 4377
Joined: Mar 29 2014 1:45pm
Location: Out riding, MN USA
Contact:

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by tomjasz » Apr 17 2020 2:10pm

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
Thanks Justin_le we're here thanks to you. All the best to the mods for their tireless work keeping it on an even keel.

maki1000   1 µW

1 µW
Posts: 4
Joined: Oct 07 2019 8:38am

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by maki1000 » Jul 03 2020 3:20pm

tomjasz wrote:
Apr 17 2020 2:10pm
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

timk   10 mW

10 mW
Posts: 31
Joined: Apr 12 2016 11:01pm
Location: Brisbane, Australia

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by timk » Aug 29 2020 11:48pm

Sounds like an interesting idea. Shame about the D79F9211.

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

Code: Select all

$ 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!

cesarras   1 µW

1 µW
Posts: 1
Joined: Dec 21 2020 9:17am

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by cesarras » Dec 21 2020 9:19am

tomjasz wrote:
Apr 17 2020 2:10pm
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.

User avatar
tomjasz   10 GW

10 GW
Posts: 4377
Joined: Mar 29 2014 1:45pm
Location: Out riding, MN USA
Contact:

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by tomjasz » Dec 21 2020 7:40pm

Done.
Buta simple search for Bafang .el files will find them as well.
Thanks Justin_le we're here thanks to you. All the best to the mods for their tireless work keeping it on an even keel.

timk   10 mW

10 mW
Posts: 31
Joined: Apr 12 2016 11:01pm
Location: Brisbane, Australia

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by timk » Dec 26 2020 6:49am

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!

danielnilsson9   1 mW

1 mW
Posts: 12
Joined: Jan 05 2021 3:09pm

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by danielnilsson9 » Jan 05 2021 3:34pm

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

timk   10 mW

10 mW
Posts: 31
Joined: Apr 12 2016 11:01pm
Location: Brisbane, Australia

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by timk » Jan 05 2021 3:51pm

Nice work Daniel!

casainho   100 GW

100 GW
Posts: 5155
Joined: Feb 14 2011 2:43pm

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by casainho » Jan 05 2021 6:02pm

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.
- EBike wireless standard: wireless motor, wireless cycling GPS display Garmin Edge and wireless remote with wireless brake sensor
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of OpenSource knowledge and technology for ebikes: Wireless EBike standard ANT+ and Bluetooth, TSDZ2 OpenSource firmware, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

Please consider a donation to help developments: paypal.me/jorgecasa

casainho   100 GW

100 GW
Posts: 5155
Joined: Feb 14 2011 2:43pm

Re: Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

Post by casainho » Jan 05 2021 6:05pm

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.
- EBike wireless standard: wireless motor, wireless cycling GPS display Garmin Edge and wireless remote with wireless brake sensor
- TSDZ2 FAQ: issues and repairs, etc
- TSDZ2 OpenSource firmware

Developer of OpenSource knowledge and technology for ebikes: Wireless EBike standard ANT+ and Bluetooth, TSDZ2 OpenSource firmware, KT motor controllers and displays: Bafang 850C color, SW102 Bluetooth and KT-LCD3.

Please consider a donation to help developments: paypal.me/jorgecasa

Post Reply