Jump to content
ghatikar

WHICH BMS for my LiFepo4

Recommended Posts

11 hours ago, plonkster said:

so RS485-styles won't work unless someone makes a driver for them. Which is not impossible, it's open enough that anyone with a bit of Linux+python experience

I have been looking at doing something like this. My Python experience is a little lacking currently. 
My BMS use RS232 which is similar to RS485.

I have found this thread which has been useful to start the research and I think this script from you is probably the best to base this of. What I have not found yet is if there is a guide to set up a development environment for the VenusOS\rPiVenus. I don't want to play work on my live system.

@Luminous what I can tell you is that the system works very well without any comms to the MPs. You just need to match the settings between the battery BMS and the MultiPlus. If you have comms the BMS tells this to the MP. If you don't you set the settings and the MP will calculate the battery SOC using the voltages from the battery.

Share this post


Link to post
Share on other sites
Posted (edited)
1 hour ago, Louisvdw said:

I have found this thread which has been useful to start the research and I think this script from you is probably the best to base this of. What I have not found yet is if there is a guide to set up a development environment for the VenusOS\rPiVenus. I don't want to play work on my live system.

That batterydata "script" has nothing to do with BMSes. It's for MFD integration, to make batteries show up on the multifunction display in boats and yachts 🙂

There are some "fake" scripts you can use to fake a battery. Eg the dummycanbms script. These are still accidentally included in the build, so you can do this:

cd /opt/victronenergy/dbus-systemcalc-py
python scripts/dummycanbms.py

That starts up a fake dummy BMS. You can then run "dbus-spy" in another terminal, and you will see a ACME BMS which you can actually edit. You will see there are /Info paths that has the maximum charge voltage and current, as well as the usual /Dc/0/Voltage, Current, Power paths, and /Soc.

You can also look at the proxybattery script. This runs in a similar way, except you pass as a parameter another device that provides the Dc and Soc values. You can use a BMV or the Multi for that, eg:

python scripts/proxybattery.py com.victronenergy.battery.ttyUSB0

# or...

python scripts/proxybattery.py com.victronenergy.vebus.ttyO1

Now this script is used to turn a non-BMS battery monitor (such as a BMV) into a fake one that has the extra /Info paths, and then again you can edit those using dbus-spy.

Now... your job is to make something that works like that script, that publishes that info onto dbus... but it must read it from a serial port.

The easiest might be to read the serial port in a separate thread. To see how to do that, look at the example in dbus-digitalinputs (which reads gpios... but the idea is the same).

Once you've got something running that can interpret the serial BMS data and put them on dbus... then you have a "driver" for your BMS.

Also look here to stick to the dbus spec. Some paths are required, such as the stuff in /Mgmt, the ProductId (you can use 0xFFFF, 65535 to leave it unset), the ProductName, and so forth. Those have to be there for it to work at all.

https://github.com/victronenergy/venus/wiki/dbus-api

https://github.com/victronenergy/venus/wiki/dbus

Edit: Yes, ACME is a pun on the Loonytunes, and for those who don't know, ACME == A Company that Makes Everything.

Edited by plonkster

Share this post


Link to post
Share on other sites
5 minutes ago, plonkster said:

ACME is a pun on the Loonytunes, and for those who don't know, ACME == A Company that Makes Everything.

Yes I saw there are a few ACME companies in some of the scripts :) 

Thanks plonkster for directing me to the correct starting point. I'll give it a try.

Share this post


Link to post
Share on other sites
4 minutes ago, Louisvdw said:

Yes I saw there are a few ACME companies in some of the scripts :) 

There are also a few hex strings that spell things like 0xBADBEEF15BAD or 0xB00B135. Developers have to entertain themselves.

Share this post


Link to post
Share on other sites
Just now, plonkster said:

Developers have to entertain themselves

We added a ASCII image of a scorpion in one of our scripts as a reference to a client that was bugging us for support. They always phoned at 4pm on a Friday with an issue!

Share this post


Link to post
Share on other sites
18 hours ago, plonkster said:

Edit: Yes, ACME is a pun on the Loonytunes, and for those who don't know, ACME == A Company that Makes Everything.

Wow Today I learned!

Never too old to learn something new hey.

Very interesting thread...

Also as an aside. @plonkster I have manged to decode the Arduino sketch, you provided me in the other thread. 

023a 570 Charge Voltage:       57V
0064 100 Max Charging Current: 10A
0064 100 Max Charging Current: 10A
01a4 420 Discharge Voltage:    42V

0032  50 SOC  50%
0064 100 SOH 100%
0000   0 SOC high definition 0 * 0.01%

14b4 Battery Voltage: 5300 * 0.01V = 53V
0064 Battery Current: 100  * 0.01A = 10A
00f0 Battery Temp:    240  * 0.1c = 24c

These values look familiar/correct?

So in essence my idea is to make a "smart" module for any "dumb" BMS like the Daly. The current version will not have individual cell reporting, however it will have Bluetooth and Wifi, probably MQTT and CAN-Bus support.

Anyway sorry to derail the thread. 

/me drops ninja dust... 

Share this post


Link to post
Share on other sites
2 hours ago, JohanB said:

decode the Arduino sketch

Heh, if you do this stuff enough you can eye-ball it and go... hang on, that's not right...

When working with a BYD's alarms, for example, I expect to see frame 0x35A with content 0xAA 0xAA... 0x02, and then repeat the same for the warnings. I can instantly see from a CAN-dump when it goes wrong 🙂

What is initially difficult about decoding the can frames, for people from other walks of life or simpler development jobs, is that most of the tools operate in hex and it needs to be translated, and secondly that 16-bit values are byte-swapped (it's little-endian in other words, the small side comes first). You are quite correct that frame 0x351's first two bytes 0x3a, 0x02, does indeed represent 0x023a which is 570, or 57.0V, and the next two is 0x64, or 100, 10.0A, and so forth.

That can-bms sketch literally just throws static values at the CAN-bus. If you put that on an arduino with a can-bus shield, and connect it to a Victron GX device, it will show up as a battery.

Share this post


Link to post
Share on other sites
12 minutes ago, plonkster said:

What is initially difficult about decoding the can frames, for people from other walks of life or simpler development jobs, is that most of the tools operate in hex and it needs to be translated

Yes, this was indeed a huge help, understanding number systems, and endian-ness. I remember the days before Arduino's when I first started to mess around with micro controllers, PIC16's  having to print out a datasheet with the instruction set, and code the thing in Assembly.

Not that I would go back to that using the Modern IDE's and high level languages  makes things allot easier.  🙂

17 minutes ago, plonkster said:

That can-bms sketch literally just throws static values at the CAN-bus. If you put that on an arduino with a can-bus shield, and connect it to a Victron GX device, it will show up as a battery.

Amazing, exactly what I was looking for a great start, now I just need to populate the values with "real" values. 

Share this post


Link to post
Share on other sites
Posted (edited)
37 minutes ago, JohanB said:

Amazing, exactly what I was looking for a great start, now I just need to populate the values with "real" values. 

In my minds eye, I see an interrupt handler that services your serial port (going to the BMS), and that simply stuffs the decoded values into memory locations.

The main loop then simply writes those memory locations to the relevant CAN frames, probably with some bit shuffling (ie, a lot of bitwise and-ing to get the half you want and shifting it left or right). You'll probably keep some kind of a wrapping counter variable and write some of the less important frames only when the counter variable reaches multiples of some time value.

Finally, remember to set the mask and filter registers of the can controller (it has two) to zeroes (and something) so it ignores anything incoming from the can bus. I find that if you don't properly handle incoming messages from the CAN-bus, the sketch tends to hang up after some seconds. I have not looked into this in more depth, I assumed it happens because the MCP2515 has only two buffers for received messages and you don't want to overflow those.

I would also play with the watchdog on the chip to make sure it restarts if it hangs up, you know, cause this is a BMS and all 🙂

I also discovered that at 500kbaud, you should try to keep any interrupt handling as short as possible so you don't miss interrupts from the CAN controller. I'm not fully clued up on the ATMEGA328, but if it is anything like most platforms, it masks interrupts while handling one.

Just some ideas off the top of my head.

Edited by plonkster

Share this post


Link to post
Share on other sites
1 hour ago, JohanB said:

PIC16's  having to print out a datasheet with the instruction set, and code the thing in Assembly

I remember being at varsity in the last few months of my studies and just then Microchip released a C compiler/editor for the PIC. That was super exciting! Now I can't remember assembly code much. 

Share this post


Link to post
Share on other sites
45 minutes ago, Louisvdw said:

I remember being at varsity in the last few months of my studies and just then Microchip released a C compiler/editor for the PIC. That was super exciting! Now I can't remember assembly code much. 

 

Yep even me! It does still come in handy to have the background knowledge of things like hex. Think today it might be a lost art. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


Topics

Contact Us - Power Forum South Africa

×
×
  • Create New...