Bafang M500/M600 thread

Waynemarlow said:
Looking really good Caisanho, it always staggers me just how fast you can develop this sort of thing.

A question, have you thought of splitting the display from the other components, just linking the display by a small 6 wire harness to the other components. This way you could have the large components tucked away inside the battery compartment of the bike and just the display mounted on the bars or more centrally on say the frame ?
Fast because I am reusing the display firmware from TSDZ2 and also I am having help from other developers like CiDi on the telegram channel.

My plan is to make the first version as a replacement of original display, so if user is not happy, can quickly change back to original display, just buy unconnecting one and connect the other, on the display port of the warness cable.
 
Very Good work Casainho ! :thumb:

the walk rpm seems low (without throttle)
You don't have to go through the original CAN for walk mode
You must use a gpio DAC with PID calculation to have 6 km/h max
(the motor speed which adapts according of rear gear)
This is a very important function that is missing for difficult mountain bike
 
I see there is a thread dedicated for these motors so I will post my question here about the UART m620:

Hello all,
I have acquired a UART m620 with my voltbike yukon core, but upon reading its configuration with the bafang usb programming cable and software, I see the current max is 25A at 48v. Most m620s I see have a limit of 30A, so is there any way for me to unlock that 30 amps? Attempting to set the current limit above 25A results in an error. Does this mean I will have to do some shunt resistor shenanigans or is there another way for me to unlock 30A?

I've never posted on this forum before so hopefully this is the proper way to do it, thank you!
 

Attachments

  • controller.png
    controller.png
    59.9 KB · Views: 1,386
Some good news about Bafang M500/M600 motors!!

CiDi is measuring his torque sensor CAN values and the plot seems to indicate the output is linear, at least on the first 20kgs range.



Our plan is to use the CAN pedal torque and cadence values, multiply by the crank length, and we will have the pedal power meter!! Then we will send this value by ANT wireless to the Garmin or other similar GPS cycling computers (using our EasyDIY display). This pedal power meters for cycling usually costs 700€ or more!!
 
Neat! if it helps, I threw together a quick chart and extrapolated some values. I tossed out the initial 0 and 1 Kg values and used 2-20kg. Those values are linear, R^2= 0.9979. (1.0 would be 'perfectly linear'), so these points are "99.79% linear" ...not bad. A 'line of best fit also makes a linear equation:

CAN Value = (52.165 x Force in Kg) + 737.68

From there, extrapolated a quick chart of what the CAN values should be for higher pedal weights. Should be possible to check one or possibly two of those higher points and see if the values roughly agree. if so, then the linearity should hold.weight extrapolation.jpg
 
4πr^2 said:
Neat! if it helps, I threw together a quick chart and extrapolated some values. I tossed out the initial 0 and 1 Kg values and used 2-20kg. Those values are linear, R^2= 0.9979. (1.0 would be 'perfectly linear'), so these points are "99.79% linear" ...not bad. A 'line of best fit also makes a linear equation:

CAN Value = (52.165 x Force in Kg) + 737.68

From there, extrapolated a quick chart of what the CAN values should be for higher pedal weights. Should be possible to check one or possibly two of those higher points and see if the values roughly agree. if so, then the linearity should hold.weight extrapolation.jpg
I plan to build my EBike, my battery pack and my display this weekend, then I will also measure my torque sensor values to compared with the CiDi values.

Here the file wit the values (everyone with the link can edit the file): https://docs.google.com/spreadsheets/d/1bM2nGOxdS6B8OtL-XEBdxDHadLE4m8Odmi4iDWrgSro/edit?usp=sharing

Maybe you can go there and improve by adding the extrapolation line.

On the display, I will add a configuration for the crank size, for correct calculation of pedal power.
I will also add a field to show the torque sensor value, so anyone with the display will be able to check his torque sensor against this values. If we find the values vary between different motors, then we can implement a calibration process, maybe by user adding some measured values, just like I did for TSDZ2 torque sensor calibration.
 
casainho said:
///
Here the file wit the values (everyone with the link can edit the file): https://docs.google.com/spreadsheets/d/1bM2nGOxdS6B8OtL-XEBdxDHadLE4m8Odmi4iDWrgSro/edit?usp=sharing

Maybe you can go there and improve by adding the extrapolation line.
...

Done. I created a second chart with measured values in blue, linear 'best fit' in red. I went ahead and added the extrapolated values list, too. Kept getting a formula error, then I realized on your side of the pond, the 'decimal' is actually what we would consider a 'comma', not the usual 'period' ...so had to enter 52,2 instead of 52.2 - lol. :wink:

I would expect from sensor to sensor, the slope is likely the same (52.2), but the offset (737.7) likely changes. Possibly the offset even changes from start-up to start-up, warm to cold, etc.
 
The build of my display, to install on my EBike, is almost ready. It already works and I am now playing with FreeCAD for the 3D design, for 3D printing - I want to design the enclosure in a way the display will be placed at the same location of the handlebar, as the original display.

Basic 3D printed enclosure, with the correct dimensions for display, compared with original display:




The build of the boards started as this:




Yes, some components has glue because I am reusing them from other displays I built for TSDZ2 Ebike motor:


All the wiring done except the ones for the CAN module. Here I can already see the display working as also see if I can turn ON/OFF:


On last step I add the CAN module:


Finally I connect to the Bafang motor and it should fully work:


Next step of the build will be to put the boards inside the 3D printed enclosure and seal it very well to avoid water inside. Finally the display will be ready to install on the handlebar.
 
Hi,
I am new to this forum, but it helped me a lot to understand how to connect to my e-bike. I have an Econic One bike with a rearhub bafang 250w.

I have an arduino and a MCP2515 chip and I have managed to read the data from the canbus usning the canhacker software. This is what I mostly get on a read:

ID DLC DATA
01F83100 4 EE 02 00 85
02F83200 8 3C 06 00 00 EE 02 CE 0E
02F83201 8 00 00 00 00 A4 0E 4C 3D
02F83202 1 00
02F83203 6 C4 09 C0 01 B6 08
02F83205 2 00 00
02F83206 1 0D
02FF1200 1 00
03103000 4 00 00 02 B6
03106300 4 01 01 00 01
03106303 1 FF

From my understanding the following line represents the speed limit:
02F83203 6 C4 09 C0 01 B6 08
where C4 09 =25KM/H and I would like to replace that with 70 17 but I have no ideea how.

In CanHacker I can transmit messages, but they are temporary,
for example if I change this line: 03106300 4 01 01 00 01 to 03106300 4 01 01 01 01 the headlight flashes for a second.

Is there any way to update the speed limit with my arduino, MCP2515 and canhacker? Or can I write a piece of code on the arduino that updates only that specific message?

I cannot use innomaker as there is no library for it on arduino.

I have added some pictures and some potentially isefull information here:https://drive.google.com/drive/folders/1zExZM7Ve7k3tGI3LBkSZa-HnKf0AM-3u?usp=sharing
 
I did it as you can see on this video about our EasyDIY display. Here you can see all the CAN messages used on our firmware: https://github.com/OpenSourceEBike/EV_Display_Bluetooth_Ant/blob/main/firmware/display/can.c

[youtube]PQ6YQrqAuaA[/youtube]

Yesterday I designed and 3D printed the enclosure final version:


The display works well, here is it installed on my handlebar:
 
Thanks,
Very interesting and complex project!

I won't have a display, so I would like to simply hardcode the new value in.

I am not a great programmer, but I hope I can use some of your functions in order to change my value.

I will try and call
Code:
can_set_max_wheel_speed(60)
function and pass 60km/h as a parameter and see if I can fix all the orther references.
 
casainho said:
I did it as you can see on this video about our EasyDIY display. Here you can see all the CAN messages used on our firmware: https://github.com/OpenSourceEBike/EV_Display_Bluetooth_Ant/blob/main/firmware/display/can.c

[youtube]PQ6YQrqAuaA[/youtube]

Yesterday I designed and 3D printed the enclosure final version:


The display works well, here is it installed on my handlebar:

I cannot figure out how to compile all that code(Way to many libraries for my non existent experience). Could you help me with a plain and simple sample of code for arduino and mcp2515 that will substitute a message with another one and what library should I use for that?
 
ogrezear said:
casainho said:
I did it as you can see on this video about our EasyDIY display. Here you can see all the CAN messages used on our firmware: https://github.com/OpenSourceEBike/EV_Display_Bluetooth_Ant/blob/main/firmware/display/can.c

[youtube]PQ6YQrqAuaA[/youtube]

Yesterday I designed and 3D printed the enclosure final version:


The display works well, here is it installed on my handlebar:

I cannot figure out how to compile all that code(Way to many libraries for my non existent experience). Could you help me with a plain and simple sample of code for arduino and mcp2515 that will substitute a message with another one and what library should I use for that?
Arduino -> Try send like this

canMsg1.can_id = 0x05103203;

canMsg1.can_dlc = 6;

canMsg1.data[0] = 0x70;

canMsg1.data[1] = 0x17;

canMsg1.data[2] = 0xD0;

canMsg1.data[3] = 0x01;

canMsg1.data[4] = 0xE8;

canMsg1.data[5] = 0x08;

library
https://github.com/autowp/arduino-mcp2515
 
Being building my EBike with Dengfu E10 frame and Bafang M500 motor. Today I built the battery, 48V 13S2P 21700 cells and with the popular Xiaoxiang Bluetooth BMS:











 
After I built my ebike, I rode with it and all seems ok (went from using assist level 1 up to max of 5). But when I try walk assist, it runs but if I pull backward the ebike to make resistance, the display shuts off... - any idea what could be happening?
 
casainho said:
After I built my ebike, I rode with it and all seems ok (went from using assist level 1 up to max of 5). But when I try walk assist, it runs but if I pull backward the ebike to make resistance, the display shuts off... - any idea what could be happening?

I am start to think there is nothing wrong with my battery but on the M500 firmware, as I can ride as expected and it only turns the system off on walk assist when doing some resistance to the movement.

Usually if I have shutdowns from the BMS, I can see it on the app, just like the charging events, I see a over current or under voltage event, but I tested a few times and I never get that event:







 
Not sure. I just tested my bike and walk mode seems to run right up to the point the wheel stalls and even then it is still trying to move forward and the display never goes blank, so definitely abnormal behavior. Sounds like some over current / under voltage / other software limit is being hit and shutting off the controller. Does it doe the same thing if you draw high current while riding?

Any readings on current/voltage at the moment the display goes blank? Also, does the display go blank with the bike physically moving backward or are you saying just the added resistance? (for example, does applying the brake slightly cause the same issue?) If the bike is physically moving backward, I would wonder if some sort or reverse current situation?

Is this the bike/battery you mention in the next post above? Admittedly wiring like that worries me a bit. Any time the wires cross each other, or go over a corner or edge, you have a chance vibration will cause the insulation to wear through. It is a small chance, and 'likely' won't be an issue, but lithium battery fires are no fun! Much better to keep everything parallel if possible and provide extra insulation or tape layers if the wires do have to cross. (below)

Also seems like your cells are stacked so you have the overall + at one end and - at the other? ...and you have a long wire run (blue?) to get the power back to the bottom of the battery? Not sure if a long wire like that would create a large voltage drop or not? Another option is to place the nickel strips so the cells are in series in a "U" formation. This keeps the overall + and - at the same end of the battery and eliminates the extra wire run.

IMG_3866.JPG
 
Ah! Looks like more info while I was typing. So seems like if no over current / under volt events are registered, it might be something with the firmware? I would wonder does a different firmware act the same? Or possibly re-load the existing firmware? ...not sure if it could become slightly corrupt?
 
When I move backward the ebike, with system off, there is some resistance as I always ear and feel the motor rotating inside - I do not know if is normal on this motor...

For now, I would say the issue can be because battery is almost fully charged and when I rotate backwards, there is regen that increases the battery voltage and so the controllers shutdown??

While I ride, from 1 up to max of the 5 assist levels, I have no problems at all, all works well as expected.
 
Yes, I hear similar 'whirling' or 'wailing' sound when pushing the bike in reverse - so I suspect that is normal. I have never noticed any power to be generated from it, or any effective 'regen' though. If you are actually seeing a voltage spike, possibly current is still flowing to the motor? Blown mosfet?

I've heard the controller shuts down when going over "58 volts". Though I have my charge cutoff at 58.4V (~4.17V/cell) because my BMS only starts to balance at 4.15V or higher. So far, I have not noticed a cutoff at up to 58.4V.
 
4πr^2 said:
Is this the bike/battery you mention in the next post above? Admittedly wiring like that worries me a bit. Any time the wires cross each other, or go over a corner or edge, you have a chance vibration will cause the insulation to wear through. It is a small chance, and 'likely' won't be an issue, but lithium battery fires are no fun! Much better to keep everything parallel if possible and provide extra insulation or tape layers if the wires do have to cross. (below)

Also seems like your cells are stacked so you have the overall + at one end and - at the other? ...and you have a long wire run (blue?) to get the power back to the bottom of the battery? Not sure if a long wire like that would create a large voltage drop or not? Another option is to place the nickel strips so the cells are in series in a "U" formation. This keeps the overall + and - at the same end of the battery and eliminates the extra wire run.
Thanks for all the feedback. I used a LOT of kapton tape to protect the battery but I plan to redo that small wires to avoid their crossing as also using 3D printing to make a good support of the battery against the metal case.
 
I did a BETA release of the display firmware: https://github.com/OpenSourceEBike/EV_Display_Bluetooth_Ant/releases/tag/v0.20.0

On next weeks, I plan to keep testing all this, including doing my first rides on my new EBike. My plan is to never use the original display and go straight to use our display. And I will be documenting the build process, and try to avoid developing further the firmware, to have a "stable" version including some nice documentation.

In 1 month, I have a trip of 4 intense days from Portugal to Santiago de Compostela in Spain (500 kms). I need to have my EBike ready tested for this special trip.
 
Found the issue with power cut off on walk assist only: my BMS has 2 temperature sensors but I installed it using only 1. Even if I disable the second one on the software configurations, for some reason after sometime it is enabled again and it triggers the protection over temperature on walk assist - I would say motor rotating makes some electronic noise or such to trigger that sensor input.
 
Finally could ride and further test the display -- basically, everything that can be done on BESST can be done on this display while you are riding outside!!

If I keep the ON/OFF button pressed at startup, I can see this information, like the last line that is the display firmware version - in future could be added motor controller firmware version:


One of the three main screens: on my M500, the max current value I could see were 10 amps of battery current, on my 48V battery, that is 480W. Other main screen shows the motor power and yes, it is 480W max:


Now showing part of the configurations: wheel; battery and battery SOC:


Here we can change the max speed limit, and work well as expected!!


And here the configurations for battery SOC Coloumb counting, which is more precise than original battery SOC. We need to see the voltage value at which the reset of SOC happens to 100%. Usually to a near voltage when the battery is fully charged. Then we also need to set the amount of Wh of our battery. And finally we can see the amount of used battery power in Wh:


Some technical information as pedal torque and cadence values, as also the option to start the pedal torque sensor calibration as also the motor rotor position calibration:


Here some options for the display, like using 3, 5 or 9 assist levels, invert or not the buttons UP / DOWN or invert the display: useful if you want to fix the keypad or the display on left or right side of the handle bar. And the options for autonomic power off after some time or the reset of the configurations to the default state:
 
SUPERJC said:
Arduino -> Try send like this

canMsg1.can_id = 0x05103203;

canMsg1.can_dlc = 6;

canMsg1.data[0] = 0x70;

canMsg1.data[1] = 0x17;

canMsg1.data[2] = 0xD0;

canMsg1.data[3] = 0x01;

canMsg1.data[4] = 0xE8;

canMsg1.data[5] = 0x08;

library
https://github.com/autowp/arduino-mcp2515

Thanks for the example.
I have tried this:
Code:
#include <SPI.h>
#include <mcp2515.h>

struct can_frame canMsg1;
MCP2515 mcp2515(10);

void setup() {
  
  canMsg1.can_id = 0x05103203;
  canMsg1.can_dlc = 6;
  canMsg1.data[0] = 0x70;
  canMsg1.data[1] = 0x17;
  canMsg1.data[2] = 0xC0;
  canMsg1.data[3] = 0x01;
  canMsg1.data[4] = 0xB6;
  canMsg1.data[5] = 0x08;
  
  while (!Serial);
  Serial.begin(115200);
  
  mcp2515.reset();
  mcp2515.setBitrate(CAN_250KBPS, MCP_8MHZ);
  mcp2515.setNormalMode();
  
  Serial.println("Example: Write to CAN");
  
  for(int i = 0; i<5; i++)
  {
     mcp2515.sendMessage(&canMsg1);

  Serial.println("Messages sent");
  
  delay(100);
  }
}

void loop() {
   
}

Unfortunately when I try to read the messages after sending them a few times. I still get the same C4 09 values in the message. And the limit doesn't seem to be replaced.

I have seen in casainho git coments that he had o send it 5 times with a small delay, but that doesn't deem to do the trick.

Do you have any other sugestions that I can try?

Thanks again!
 
Back
Top