Software for diyBMS v4
Version 4 of the diyBMS. Do-it-yourself battery management system for Lithium ion battery packs and cells
If you are looking for version 3 of this project take a look here https://github.com/stuartpittaway/diyBMS
THIS REPOSITORY IS FOR THE ESP8266 BASED CONTROLLER BOARD (ORIGINAL/LEGACY)
The newest ESP32 based code can be found here https://github.com/stuartpittaway/diyBMSv4ESP32
If you find the BMS useful, please consider buying me a beer, check out Patreon for more information.
You can also send beer tokens via Paypal - paypal.me/stuart2222
Any donations go towards the on going development and prototype costs of the project.
https://www.youtube.com/stuartpittaway
If you need help, ask over at the forum
If you discover a bug or want to make a feature suggestion, open a Github issue
This release removes the need to manually compile the code yourself, instead GITHUB Actions are now used to build the code for you automatically.
The files you will need are held as a ZIP file in Releases
Download the ZIP file named "Compiled_Firmware_YYYY-MM-DD-HH-MM.zip" and extract its contents and inside the folder you should find:
Files for the controller (ESP8266)
Files for the modules (ATTINY841)
You can ignore the "filesystemimage" for the esp8266, this is no longer required.
You will need to determine which module HEX file to use (see "Identify which module/board you have" below for help). Most people will have a V4.00 or V4.21 board.
Both Wemos D1 Mini and Wemos D1 Mini & Pro are supported - minimum of 4MB flash memory.
You should see output similar to below, this is a WeMos D1 Mini Pro (16MB Flash)
Using 'COM3' as serial port.
Connecting....
Detecting chip type... ESP8266
Connecting....
Chip Info:
- Chip Family: ESP8266
- Chip Model: ESP8266EX
- Chip ID: 00123456
- MAC Address: AA:BB:CC:DD:EE:FF
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
- Flash Size: 16MB
- Flash Mode: dout
- Flash Frequency: 40MHz
Erasing flash (this may take a while)...
Writing at 0x000b0000... (100 %)
Wrote 872784 bytes (728955 compressed) at 0x00000000 in 17.2 seconds...
Hash of data verified.
Leaving...
Hard Resetting...
Done! Flashing is complete!
Module code runs on the ATTINY841 micro controller, it is important to program the chip with the correct version of code depending on your PCB version.
You will need a programming device capable of programming ATMEL AVR chips - like the USBASP programmer
cd C:\temp\avrdude-6.3-mingw32
avrdude -C avrdude.conf -P usb -c usbasp -p t841
avrdude: set SCK frequency to 187500 Hz
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e9315 (probably t841)
avrdude: safemode: Fuses OK (E:F4, H:D6, L:E2)
avrdude done. Thank you.
Programming the module takes around 12 seconds.
avrdude -C avrdude.conf -P usb -c usbasp -p t841 -e -B 8 -U efuse:w:0xF4:m -U hfuse:w:0xD6:m -U lfuse:w:0x62:m -U flash:w:diybms_module_firmware_400.hex:i
it should output
avrdude: set SCK frequency to 187500 Hz
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x1e9315 (probably t841)
avrdude: erasing chip
avrdude: set SCK frequency to 187500 Hz
avrdude: reading input file "0xF4"
avrdude: writing efuse (1 bytes):
Writing | ################################################## | 100% 0.00s
avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xF4:
avrdude: load data efuse data from input file 0xF4:
avrdude: input file 0xF4 contains 1 bytes
avrdude: reading on-chip efuse data:
Reading | ################################################## | 100% 0.00s
avrdude: verifying ...
avrdude: writing hfuse (1 bytes):
Writing | ################################################## | 100% 0.00s
avrdude: 1 bytes of hfuse written
avrdude: reading on-chip hfuse data:
Reading | ################################################## | 100% 0.00s
avrdude: verifying ...
avrdude: writing lfuse (1 bytes):
Writing | ################################################## | 100% 0.00s
avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xE2:
avrdude: reading on-chip lfuse data:
Reading | ################################################## | 100% 0.00s
avrdude: verifying ...
avrdude: writing flash (7718 bytes):
Writing | ################################################## | 100% 6.74s
avrdude: 7718 bytes of flash written
avrdude: verifying flash memory against diybms_module_firmware_XXX.hex:
Reading | ################################################## | 100% 3.43s
avrdude: verifying ...
avrdude: 7718 bytes of flash verified
avrdude: safemode: Fuses OK (E:F4, H:D6, L:E2)
avrdude done. Thank you.
Hardware for this code is in a seperate repository, and consists of a controller (you need 1 of these) and modules (one per series cell in your battery)
https://github.com/stuartpittaway/diyBMSv4
V400 = Original board (marked DIYBMS v4 on silkscreen) - has 8 large resistors (marked 2R20) and likely handsoldered using 0805 sized parts [4.0 boards do have TP2 near the ATTINY841 chip]
V410 = JLCPCB built board (marked DIYBMS v4 on silkscreen) - has 8 large resistors (marked 2R00) and machine soldered using 0603 sized parts [4.1 boards do not have TP2 near the ATTINY841 chip]
V420 = JLCPCB built board (marked DIYBMS v4.2 on silkscreen) - has 20 small resistors (marked 6R20) and machine soldered using 0603 sized parts (R20 is in middle of resistor array)
V420_SWAPR19R20 = JLCPCB built board (marked DIYBMS v4.2 on silkscreen) - has 20 small resistors (marked 6R20) and machine soldered using 0603 sized parts [you have manually resoldered R19 and R20 to swap the positions on PCB to move the thermistor inside the resistor array]
V421 = JLCPCB built board (marked DIYBMS v4.21 on silkscreen) - has 20 small resistors (marked 6R20) and machine soldered using 0603 sized parts (R19 is in middle of resistor array)
V440 = Marked DIYBMS v4.4 on silkscreen, released Feb 2021 - DO NOT USE THIS CODE WITH OLDER VERSION BOARDS
Open the module code, navigate to platformio environment "env:attiny841_VXXX", (where XXX is the version from above). Connect your USBASP programmer to the module and select "Upload"
This is a DIY product/solution so don’t use this for safety critical systems or in any situation where there could be a risk to life.
There is no warranty, it may not work as expected or at all.
The use of this project is done so entirely at your own risk. It may involve electrical voltages which could kill - if in doubt, seek help.
The use of this project may not be compliant with local laws or regulations - if in doubt, seek help.
The code uses PlatformIO to build the code. There isn't any need to compile the code if you simply want to use it, see "How to use the code" above.
If you want to make changes, fix bugs or poke around, use platformio editor to open the workspace named "diybms_workspace.code-workspace"
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales License.
https://creativecommons.org/licenses/by-nc-sa/2.0/uk/
You are free to:
Under the following terms:
Notices: You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation.
No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.