Bafang BBSHD BBS02 mid drive -- Flexible OpenSource firmware

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.
 
Very nice, great work. I wonder how many hardware revisions of BBS02 exist / how hard would it be to support it.
 
cavi said:
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.
 
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.
 
Waynemarlow said:
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??
 
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-power-meters/avio-powersense-power-meter/12083185.html?affil=thggpsad&switchcurrency=EUR&shippingcountry=BE&gclid=CjwKCAjw6fCCBhBNEiwAem5SO5xQfEahd8f9tX9J0rg4zXxeJ8Yb2XGJWtttGtLBmuSzEcwMr0-fQhoCdeUQAvD_BwE&gclsrc=aw.ds
 
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/TSDZ2_Open_Source_Firmware_%28OSF%29_Upgrade_Products.html#/
- https://www.eco-ebike.com/collections/tsdz2-open-source-firmware-osf-products
 
casainho said:
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/TSDZ2_Open_Source_Firmware_%28OSF%29_Upgrade_Products.html#/
- https://www.eco-ebike.com/collections/tsdz2-open-source-firmware-osf-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. :)
 
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
 
maki1000 said:
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_wireless_controller.html

 
casainho said:
Motor controller (unpotted):
BBSHD%20unpotted%20Display%20Power%20Line.jpg

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
    263.5 KB · Views: 1,838
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?
 
ZeeBass said:
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.
 
ptan9668 said:
casainho said:
Motor controller (unpotted):
BBSHD%20unpotted%20Display%20Power%20Line.jpg

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/danielnilsson9/bbshd-fw/img/controller_pcb/f2.jpg


It's most likely a switching 5V regulator IC given it's location on the board.
 
ZeeBass said:
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.
 
danielnilsson9 said:
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?
 
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 ...
 
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

My crappy test setup here in Singapore: Nano33 BLE with UART to display and UART to Bafang connections
PXL_20210612_101301037.SMALL.jpeg
 
Hey Krusty

krusty said:
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
 
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 said:
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.
 
raylo32 said:
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:
 
Tomblarom said:
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
 
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-POWER-L-XTR-M9000-OR-M9020


geofft said:
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:
 
Back
Top