ChristophPech / bbsDisplay

bafang Arduino display
GNU General Public License v3.0
8 stars 2 forks source link

Need help to understand the Bafang Display protocol #2

Open MarcoLauria27 opened 3 months ago

MarcoLauria27 commented 3 months ago

Hi, Christoph, thanks for your code. Very interesting project. I'm building a project based on Casainho's eBike project using a FlipSky mini VESC controller to control the new TongSheng TS8 motor. The idea is that it would be an universal motor controller. The settings to the VESC are done by an ESP32 who read the PAS, cadence and Torque sensor. The ESP is programmed for 9 levels and interface with a Bafang Display. The only reference I found to the UART Bafang display protocol was from you, the txt you published with your code. I implemented the code based on the txt but keep getting a communication error from the Bafang Display. Can you help me understand the parameters to be given to the display. From your txt, if speed is in Km/h, I can't understand the formula for ths ispeed in your code. i would be in Km/h and if ispeed is meant to be some sort of rotation speed, then you cannot multiply i to the tire circunference. To do this, i would need to be rotational and in this case, the 2 bytes would not be based on Km/h as in the txt. Also, the Power is in watts in the 1st byte and checksum on the second. In this case, wouldn't the max power be 256W and the second byte always be the same as the 1st one? In the battery, the txt is in V but the byte 0 is percent, and them checksum. The battery is in volts or percentage and wouldn't the second byte be always the same as the 1st one as checksum of a number smaller than 256 is the number. Your help is greatly appreciated.

ChristophPech commented 3 months ago

Hi. The txt says power is in Watts, but it's actually Amps, see gfx.cpp line 63. I wrote the text before figuring out the actual units of the values.

iSpeed is the final calculated value in km/h. The i (long i=(int(b0)<<8)|b1;) is some kind of rotational value, I don't know what it is exactly, I thought maybe Hall sensor impulses per second divided by 100. I couldn't find out the logic behind everything, when I reverse engineered it, I looked at what the bafang display showed and what the communication was, then derived the formulas from it.

Yes, battery is percent, and the checksum in this case is the same value. Why they sometimes added some value to the checksum and sometimes not, is beyond me.

Happy to help.

MarcoLauria27 commented 3 months ago

Thanks Christoph, for your prompt reply. Appreciate. It's sad that we cannot find this display protocol documented anywhere and have to guess what is the response. One last question if I may, the i (rotational value) is calculated combining the 1st 2 bytes sent to the display. If that's the case, the information sent to the display is not Km/h (shown in txt) but this rotational value.

Based on your formula for iSpeed, i would be the wheel rotation in rpm (if ispeed is im m/h) or that/1000 if i is in Km/h. 6/100=60/1000, wheel circumference in mm/1000=wheel circunference in m. wheel speed in rpm *60 = wheel speed in rph rph in m = speed in m or the wheel speed would need to be rpm/1000.

It makes sense since there is a speed sensor in the wheel. The controller calculates the speed based on this value and probably sent that rotational speed to the display so that it recalculate it based on the wheel diameter set on the display. Best Regards, Lauria.

ChristophPech commented 3 months ago

That seems reasonable, I think you solved that mystery. Also for calculating the power in Watts, the display needs to measure the battery voltage on it's own, which is what I did with my DIY display.

MarcoLauria27 commented 3 months ago

I realized that since the display shows power but do not request voltage info from the bike. It needs to have an ADC in the display to be able to calculate that.