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.
danielnilsson9   1 mW

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

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

Post by danielnilsson9 » Mar 09 2021 4:02pm

Yes, I'm currently working on the configuration tool to go along with this firmware, a few small things left to do there.

As for the firmware itself there are some minor thing left to do there too but the important stuff is working.

Still need to do:
* Speed limiting according to configuraiton
* Temperature limiting
* Send error codes along to the display
* Turn on/off lights
* Documentation

But the important stuff is working, throttle, pas, communication with the original bafang display etc.

I'm aiming for a public release at the end of the month if nothing else comes up.
There will be two binary files, one for controller revision 1.4 and one for 1.5 since the MCU and the EEPROM layout differs the same binary cannot be used.


I would not recommend building and flashing the firmware at the moment as the status is unknwon at times and config tool not yet useful, especially not if you have controller revision 1.4 since there is no way of going back to the original firmware.

silenec   10 µW

10 µW
Posts: 5
Joined: Jul 31 2017 4:08am

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

Post by silenec » Mar 19 2021 7:12am

Very nice, great work. I wonder how many hardware revisions of BBS02 exist / how hard would it be to support it.

jtrappett   1 µW

1 µW
Posts: 1
Joined: Apr 14 2014 5:39pm

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

Post by jtrappett » Mar 20 2021 7:16pm

cavi wrote:
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!!
I would love to see your settings... or have a copy of the config file ?? I have worked on mine quite a bit also.. basically I use an unlimited setting but PAS level 1 is different to allow some grunt for standing starts.

Waynemarlow   10 kW

10 kW
Posts: 614
Joined: Jul 09 2016 7:22am
Location: Bucks, England

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

Post by Waynemarlow » Mar 24 2021 5:02pm

You may have noticed Garmins release of its Power meter pedals. Now combine them with the BBS02 and you have a pretty good torque based motor. Shame about there cost.

casainho   100 GW

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

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

Post by casainho » Mar 24 2021 5:20pm

Waynemarlow wrote:
Mar 24 2021 5:02pm
You may have noticed Garmins release of its Power meter pedals. Now combine them with the BBS02 and you have a pretty good torque based motor. Shame about there cost.
Maybe there are chinese cheap alternatives for that type of pedals??
- 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

Djoene   10 µW

10 µW
Posts: 6
Joined: Nov 30 2018 1:06pm

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

Post by Djoene » Mar 25 2021 2:19pm

cheapest alternative that i found is like a paste on solution for the crankarm
it works with bluetooth and ant+
not much reviews for this one tough..

https://www.probikekit.co.uk/cycling-po ... lsrc=aw.ds

casainho   100 GW

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

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

Post by casainho » Mar 26 2021 7:31am

Hi danielnilsson9.

I got a donated BBSHD motor controller with wrong firmware on it. When I have time, I wish to install the firmware and connect to a TSDZ2 motor I have and test it. I only have a TSDZ2 motor and I hope it will work... and I can use a throttle as input.

I am on Linux and I also use the Visual Code Studio. I saw that you recommend to install the SDCC, this means SDCC supports this microcontroller? and if so, are you able to debug the code (use breakpoints, see variable values, etc) or you are only flashing the firmware?

I think the BBSHD usually is sold with the 860C or SW102 displays and we developed our own OpenSource firmware for them, and the firmware is flashed with a UART cable, is easy for user as it the same tools as for flashing the motor firmware. Don´t you want to make a fork of the 860C display to make it working for BBSHD and include the specific configurations of your firmware? - the user would then be able to change the configurations on the fly, while riding for instance and would not depend of a computer!

And our firmware have advanced features like battery SOC estimation, with automatic battery resistance calibration, etc.

Note that there are two US shops selling TSDZ2 motor and 860C display, with our OpenSource firmware installed. As BBSHD is also very famous, I think they may want to sell it also and that would improve your project awareness, meaning more success:

- https://www.electrifybike.com/store/c38 ... ducts.html#/
- https://www.eco-ebike.com/collections/t ... f-products
- 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

danielnilsson9   1 mW

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

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

Post by danielnilsson9 » Apr 02 2021 4:13am

casainho wrote:
Mar 26 2021 7:31am
Hi danielnilsson9.

I got a donated BBSHD motor controller with wrong firmware on it. When I have time, I wish to install the firmware and connect to a TSDZ2 motor I have and test it. I only have a TSDZ2 motor and I hope it will work... and I can use a throttle as input.

I am on Linux and I also use the Visual Code Studio. I saw that you recommend to install the SDCC, this means SDCC supports this microcontroller? and if so, are you able to debug the code (use breakpoints, see variable values, etc) or you are only flashing the firmware?

I think the BBSHD usually is sold with the 860C or SW102 displays and we developed our own OpenSource firmware for them, and the firmware is flashed with a UART cable, is easy for user as it the same tools as for flashing the motor firmware. Don´t you want to make a fork of the 860C display to make it working for BBSHD and include the specific configurations of your firmware? - the user would then be able to change the configurations on the fly, while riding for instance and would not depend of a computer!

And our firmware have advanced features like battery SOC estimation, with automatic battery resistance calibration, etc.

Note that there are two US shops selling TSDZ2 motor and 860C display, with our OpenSource firmware installed. As BBSHD is also very famous, I think they may want to sell it also and that would improve your project awareness, meaning more success:

- https://www.electrifybike.com/store/c38 ... ducts.html#/
- https://www.eco-ebike.com/collections/t ... f-products
I think it should be possible to connect to tsdz2 motor but I haven't tested. The config tool is windows only though but the default config will give you throttle support.

Yes SDCC support the 8051 architecture so no trouble. I'm using the full visual studio (not code) but it's basically a makefile project just as your tsdz2 firmware so I'm sure you will have no issue getting it to compile on linux.

I haven't investigated if it it possible to get a debugging environment, I have only done flashing and print debugging...

I will not expand this project beyond supporting standard bafang compatible displays. But anyone is free to take it further if they want. :)

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 » Apr 17 2021 5:48am

If you manage to add a pressure sensor and software like in TSDZ2, it will be the best motor for a regular bicycle frame! good luck you are great

casainho   100 GW

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

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

Post by casainho » Apr 17 2021 6:29am

maki1000 wrote:
Apr 17 2021 5:48am
If you manage to add a pressure sensor and software like in TSDZ2, it will be the best motor for a regular bicycle frame! good luck you are great
Pressure sensor can be the already existing commercial solutions for pedals torque sensors, that send the value by ANT or Bluetooth, then, an EBike wireless controller that we are using on the TSDZ2, could receive the torque value from the wireless pedals torque sensor and send to the BBSHD motor controller:

https://opensourceebike.github.io/ebike ... oller.html

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

ptan9668   1 µW

1 µW
Posts: 1
Joined: Apr 28 2021 1:25pm

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

Post by ptan9668 » Apr 28 2021 1:43pm

casainho wrote:
Sep 01 2019 10:42am
Motor controller (unpotted):
Image
A bit of an unrelated question, but it seems my 5V regulator isn't getting any input voltage. I traced it back the the little IC just below the large bulk cap. Unfortunately, I must've scratched off the markings on the IC so I have no idea what it is. Any chance you still have your unpotted controller to reference off of? I would really appreciate the help!

See attached for the IC in question, circled in green:
Attachments
Screenshot 2021-04-28 144121.png
Screenshot 2021-04-28 144121.png (832.97 KiB) Viewed 717 times

ZeeBass   1 µW

1 µW
Posts: 3
Joined: Apr 01 2021 11:17pm

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

Post by ZeeBass » May 04 2021 3:07pm

Been looking through your git on this. Would this support the Eggrider display now or in the future including the ability to program on the fly?

casainho   100 GW

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

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

Post by casainho » May 04 2021 3:16pm

ZeeBass wrote:
May 04 2021 3:07pm
Been looking through your git on this. Would this support the Eggrider display now or in the future including the ability to program on the fly?
We developed our OpenSource firmware from scratch to the SW102 / Eggrider display, would be fast to make a firmware version to support this firmware for BSSHD.
- 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

danielnilsson9   1 mW

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

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

Post by danielnilsson9 » May 05 2021 2:47pm

ptan9668 wrote:
Apr 28 2021 1:43pm
casainho wrote:
Sep 01 2019 10:42am
Motor controller (unpotted):
Image
A bit of an unrelated question, but it seems my 5V regulator isn't getting any input voltage. I traced it back the the little IC just below the large bulk cap. Unfortunately, I must've scratched off the markings on the IC so I have no idea what it is. Any chance you still have your unpotted controller to reference off of? I would really appreciate the help!

See attached for the IC in question, circled in green:

There are detailed images in the wiki repo:
https://github.com/danielnilsson9/bbshd-fw/wiki

Here is one of the IC you are looking for:
https://raw.githubusercontent.com/wiki/ ... pcb/f2.jpg


It's most likely a switching 5V regulator IC given it's location on the board.
Last edited by danielnilsson9 on May 05 2021 2:53pm, edited 2 times in total.

danielnilsson9   1 mW

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

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

Post by danielnilsson9 » May 05 2021 2:51pm

ZeeBass wrote:
May 04 2021 3:07pm
Been looking through your git on this. Would this support the Eggrider display now or in the future including the ability to program on the fly?
Eggrider could probably be supported but the set of configuration parameters differs from the original firmware so would require changes to/by eggrider.


General progress update
I hit some issues when I started testing with motor mounted on bike.
Sometimes throttle ADC reading goes crazy for a whole second and I have not figured out the cause or
what to do about it yet... Only happens with actual load, not when motor is freewheeling on desktop.

casainho   100 GW

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

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

Post by casainho » May 05 2021 3:04pm

danielnilsson9 wrote:
May 05 2021 2:51pm
General progress update
I hit some issues when I started testing with motor mounted on bike.
Sometimes throttle ADC reading goes crazy for a whole second and I have not figured out the cause or
what to do about it yet... Only happens with actual load, not when motor is freewheeling on desktop.
Both things seems unrelated... And did you figure out if that only happens when accelerating the motor or at motor constant speed? Did you tested to lower the battery or motor current to see if it still happens?
- 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

kaiz47   1 mW

1 mW
Posts: 11
Joined: Aug 29 2019 8:10pm

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

Post by kaiz47 » May 12 2021 9:13pm

i follow this thread since my first ebike. this project seems very advanced now, and i'm very tempted to try this on my new 52v bbshd, but there is a detail that i may have missed : will it work with my 850c display ? i've seen mentionned the eggrider or the dcp18 but i don't remember reading something about my 850c.
and is this reversible ? just in case ...

krusty   10 µW

10 µW
Posts: 5
Joined: Jun 12 2021 4:42am

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

Post by krusty » Jun 12 2021 6:02am

Wow, I just discovered this thread much to my surprise! I started a few months ago on a project of replacing my display with an Android app + bluetooth module. Somehow I never came across this discussion and since I never thought replacing the drive firmware would be feasible I've been using Bafang's horrible data protocol with its total lack of documentation.

My hardware setup is pretty similar to what I saw earlier in this thread: I use an Arduino Nano33 BLE module that connects by UART to the controller. Most of the time it just runs an event loop to poll for current, velocity and errors at a regular basis since this is what the standard displays do (the Bafang will never make a peep if it isn't queried.) Responses are decoded locally and sent to the app via bluetooth LE. It can also receive any kind of message from the app, send it on to the Bafang and relay back any response. This allows for reprogramming all the controller settings at one button press on the app, and it also moves the heavier development work into Android instead of Arduino.

I've attached a screenshot of the app main page: when you press the one of the mode buttons it sends all the drive parameters to the Bafang (the settings themselves are customizable on a different page.) I was planning on cleaning all this up at some point and putting it out there but I got distracted by other stuff and haven't done any real work on it in months. Also a problem is I'm currently working in Singapore where the eBiking sucks so my motivation has been low. I'd really hoped to do some work on it here and I even brought the motor controller with me but it turns out hobby projects aren't much fun when you can't test them in any practical way.

If there's any interest in this project and sharing the dev work on it I'd be happy to put it out there. But first I would want to refactor it since I would be embarassed by the code in its current state--its very much a testbed and not yet meant for human consumption.

Long time lurker, first time poster...
-Krusty

App main page
Screenshot_20210612-180858.png
Screenshot_20210612-180858.png (137.42 KiB) Viewed 183 times
My crappy test setup here in Singapore: Nano33 BLE with UART to display and UART to Bafang connections
PXL_20210612_101301037.SMALL.jpeg
PXL_20210612_101301037.SMALL.jpeg (366.64 KiB) Viewed 183 times

password   100 µW

100 µW
Posts: 8
Joined: Jun 03 2021 1:04pm

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

Post by password » Jun 13 2021 1:15am

Removed content.
Last edited by password on Jun 15 2021 8:53am, edited 3 times in total.

Tomblarom   10 mW

10 mW
Posts: 27
Joined: Jul 20 2018 1:33pm

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

Post by Tomblarom » Jun 14 2021 4:18am

Hey Krusty
krusty wrote:
Jun 12 2021 6:02am
If there's any interest in this project and sharing the dev work on it I'd be happy to put it out there.
Your work is very interesting. Maybe you can renew the TSDZ2_wireless app from opensourceebike.github.io, with your findings? The app is a great start, but it lacks at displaying logged data and advanced interface customization. Just wanted to point into that direction. :)

I my opinion it doesn't make sense to put further development into systems that are Bafang UART based. They announced to only produce CAN based controller and communication in the near future, at least for Bafang Ultra G510. Due to this, an alternative firmware like this OpenSource (TDSZ) firmware is a must.

Cheers

raylo32   100 W

100 W
Posts: 219
Joined: Jan 04 2019 3:09pm

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

Post by raylo32 » Jun 14 2021 5:27am

I have the Stages power crankset on my main road pedal bike. Man, if you guys could get those or the Garmins to work with a BSHD that would be the bomb for sure. Yes, they are expensive, costing more than the motor kit itself. But it would make an almost perfect torque sensing e-bike.
Waynemarlow wrote:
Mar 24 2021 5:02pm
You may have noticed Garmins release of its Power meter pedals. Now combine them with the BBS02 and you have a pretty good torque based motor. Shame about there cost.
Last edited by raylo32 on Jun 14 2021 5:38am, edited 1 time in total.

raylo32   100 W

100 W
Posts: 219
Joined: Jan 04 2019 3:09pm

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

Post by raylo32 » Jun 14 2021 5:37am

....

geofft   1 kW

1 kW
Posts: 381
Joined: Nov 09 2012 9:41am
Location: Berkshire UK

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

Post by geofft » Jun 14 2021 7:33am

raylo32 wrote:
Jun 14 2021 5:27am
I have the Stages power crankset on my main road pedal bike. Man, if you guys could get those or the Garmins to work with a BSHD that would be the bomb for sure. Yes, they are expensive, costing more than the motor kit itself. But it would make an almost perfect torque sensing e-bike.
I'm really surprised that no third party manufacturer has produced a workable BBS02/HD torque sensing setup as yet. For sure it's technically difficult and probably couldn't be done on the cheap, but I think there would be a large ready market for a decent system considering all the Bafang mid-drives there are out there.... :shock:
BBS02 V2 48v 750w, 12s lipo.
Q128H (36v 201rpm), KT36/48SVPR 6-fet, LCD3, 48v 12s lipo.

krusty   10 µW

10 µW
Posts: 5
Joined: Jun 12 2021 4:42am

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

Post by krusty » Jun 14 2021 1:18pm

Tomblarom wrote:
Jun 14 2021 4:18am
Hey Krusty

Your work is very interesting. Maybe you can renew the TSDZ2_wireless app from opensourceebike.github.io, with your findings? The app is a great start, but it lacks at displaying logged data and advanced interface customization. Just wanted to point into that direction. :)

I my opinion it doesn't make sense to put further development into systems that are Bafang UART based. They announced to only produce CAN based controller and communication in the near future, at least for Bafang Ultra G510. Due to this, an alternative firmware like this OpenSource (TDSZ) firmware is a must.

Cheers
I couldn't agree more on the future of the Bafang UART comms setup; not just because Bafang is ditching it but because is fundamentally a terrible design. I wonder if maybe it was written by a summer intern and the reason they don't publish any specifications is out of embarassment rather than because they think its some kind of trade secret.

That's the main reason I was excited to learn it was possible to rewrite the firmware: it gives an opportunity to level up the communications as well. It seems to me we could design an open source message protocol to make it much easier to write cross-platform (i.e. manufacturer) applications and maybe even force some kind of standards on the industry. This would be huge since when left to themselves every manufacturer is sure to do its own thing and no company's part will ever work with any other company's part. That isn't even good for those makers unless they somehow manage to create an Apple-ish "ecosystem" and lock people in to suck more money out, but I can't really see that happening with bikes. Instead we will just get the usual balkanization that benefits nobody, resulting in tons of perfectly good hardware getting pitched into landfills due to incompatibility.

The message protocol I'm thinking of would actually be independent of the comms bus itself: that could be UART/CAN/whatever. It's the message layer that needs to be standardized (with plenty of room for future flexibility.) Initially I think this would mostly focus on comms between the display and motor controller, but it should be able to talk to the battery/BMS, smart charger and any other stuff as well. It could be built on some existing wrapper such as Protobuf or it could be much simpler like binary key/value pairs. In truth those details don't matter to much so long as it isn't too complex and leaves room to grow with the times. The really important thing is that all the definitions would be in the public domain, ideally ending up in a decade or so as something like: "ISO E79131432, Electric Bicycle Communications Standard".

-Krusty

raylo32   100 W

100 W
Posts: 219
Joined: Jan 04 2019 3:09pm

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

Post by raylo32 » Jun 14 2021 1:45pm

Me, too. This would improve the riding experience so much. BTW, I was wrong about the cost of the Stages. They make a wide range of products to fit power measuring crank arms to most common and popular cranksets. For instance, this one for Shimano MTB cranksets for $199. These things transmit the power signal via BT LE to Garmins, Wahoos, etc. I am not a RF or code geek but it seems like these power signals should available to be tapped by the OSF geniuses.

https://store.stagescycling.com/STAGES- ... 0-OR-M9020

geofft wrote:
Jun 14 2021 7:33am
I'm really surprised that no third party manufacturer has produced a workable BBS02/HD torque sensing setup as yet. For sure it's technically difficult and probably couldn't be done on the cheap, but I think there would be a large ready market for a decent system considering all the Bafang mid-drives there are out there.... :shock:

Post Reply