Skip to content

CrashOverride2/NIU_CAN_BatteryChecker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NIU_CAN_BatteryChecker

Check your NIU CAN-based Battery. Show voltages, temperatures, cycles and more. This firmware is running out of the box on a LilyGo T-CAN485. You will get live values of both batteries connected to your scooter, you can also request battery data from a sleeping BMS like a single connected directly to the T-CAN.

It is possible to charge and discharge the batteries inside and outside your scooter, for example to use a third party (fast) charger or using it in a solar battery application.

The data can be viewed via serial console (USB-C), a web gui and can be pushed to a mqtt server.

NOTE: Ideal to check your batteries withing storage regularly, especially if you store it at a lower SOC than recommended

Wifi connection

If you flashed the firmware and start up the T-CAN, the eeprom (nvs partition) will be initialized with default values. The T-CAN will open up a wifi access point, you can connect with your notebook or smartphone to it. You see a webpage (which takes a moment to load) with all battery data and a settings page.

IMPORTANT: The wifi AP from the T-CAN has now a default password set! "NIUDrivingRulez"

Settings page

You can set your home wifi credentials and a mqtt server to push the data to.

If the T-CAN see your access point on boot up, it will connect to it and if enabled it will connect to your mqtt server as well. If the access point is lost, for example you connected the T-CAN to your scooter in home wifi range and drive away, the access point mode will be triggered immediately, so you can connect with your smart phone directly to it. It will check every minute, if it can connect back to your home wifi access point, but leaves its own access point open.

Autostart charging - if enabled charging will be enabled if T-CAN boots up Voltage charging - if enabled charging will automatically started if cell voltage drops below setpoint and stops if setpoint is reached. If you manually start charging, after it was stopped, it will ignore the upper charge voltage limit for this session. Cell charge start voltage - Setpoint for automatic charging start Cell charge stop voltage - Setpoint for automatic charging stop

IMPORTANT: The batteries will not be woken up for cell voltage checking, a manual request or a push on a battery button will be neccessary to get actual voltages

Battery control

The fimware gathers all battery related CAN frames and gets data out of it. If connected to your scooter, the messages are already coming in and will be parsed. If you connect it to a single battery, you can push the "Battery request" button, it will send some CAN messages to get all information about it. This is possible connected to the scooter too, but will only retrieve all details of battery A.

NO DATA on Hardware, Softwareversion and cycles

The batteries will sent these informations no very often, only on request (with the Battery request button) or connect to the scooter. If you charge or discharge the battery so the cycles will flip, these information will shortly be sent.

You can only gather all data at once, if the BMS is asleep for at least 10 seconds and push the Battery request button. If connected to the scooter only battery A will report all informations, battery B will be wake up too, but doesnt sent hardware, software and cycles.

EEPROM or flash based non-volatile memory

I use the eeprom function (the ESP32 has no eeprom, it uses the nvs partition in its flash) to not only store your settings, it will store the hard, firmware and cycles from a connected battery too. So if your disconnect the T-CAN regularly, you see the last information the batteries sent immediately.

FAQ

The nice RGB LED on the T-CAN is not working

This is normal, I dont control the LED. The soldered LED is a WS2812 type, sometimes called "Neopixel" which needs a timing sensitive control to display color. There are many libraries out for easy control of these. But they all interfere with my exact timings needs. I thought of implementing a easy bit banging method to represent the states with nice colors, but I already invest (too?) much time in this firmware, so I will skip this step (for now).

Getting started

Flash firmware

  • Buy a LILYGO T-CAN485
  • Connect T-CAN via USB-C to your computer
  • Use a chromium based browser and browse to https://espressif.github.io/esptool-js/
  • Click connect and choose serial port to the T-CAN, choose baudrate 460800
  • Download firmware_xyz.bin from releases page of this repo
  • Flash firmware.bin with Web ESP Tool, change flash address to 0x0
  • After it completes with "Leaving...", close web page

Connect and read battery

  • Connect your smartphone to the new accesspoint "NIU CAN Battery Checker vX.X" a new site should pop up automatically, alternatively point your browser to 192.168.4.1 or
  • Connect with a terminal program like PuTTY, TeraTerm or https://webserial.io/ with 115200 Baudrate
  • Now it is time to connect the T-CAN to your battery. Use a dupont cable and connect CAN_L to the second pin from left and CAN_H to the third pin. If you look at the connector the big positive and negative terminals are above.
  • Now click the "Battery request" button in the web gui or enter "request" in your terminal program, your battery LEDs will light up for a moment, press ENTER to show battery values

WARNING: If the battery will be polled, the battery positive and negative terminals gets powered shortly, ensure no cable or tool is shorting these pins. If you feel unsure use isolation tape to cover them. It is only a sense voltage about 62V no the full power, but it can makes nice sparks too.

Charge batteries with a 3rd party charger - inside scooter

  • Connect the T-CAN to your scooter
  • Flip the switcher "Enable Charging/Discharging" in the web gui or enter "charge" into terminal
  • Now the scooter will accept a 3rd party charger

Recommended solution is to use a secondary charge socket like a XT60 one and connect a wire directly to the FOC controller battery input. You can charge then with 20 Amps without leaving specs of the 72V 26Ah batteries. The batteries will accept more current, but they will warm up quickly.

WARNING: If you use the original socket in your scooter, do not exceed 10 Amps of charge current, because internal cabling is not capable to carry more. If you do, you damage an internal connector.

Charge batteries with a 3rd party charger - outside scooter

Schematic of charging with T-CAN

  • Connect the T-CAN to your battery or both batteries
  • Apply 12V to the batteries on the apropiate PINs (pinout below)
  • Apply 2,5V to the battery which should be detectet as battery B on the CAN bus (pinout below)
  • Flip the switcher "Enable Charging/Discharging" in the web gui or enter "charge" into terminal
  • Now batteries are awake and send regular updates of its values and accept charge and discharge current

WARNING: If you disable the Charging/Discharging within web gui (or serial or mqtt) the BMS will stay alive till the 12V supply will be removed too. If you want the batteries fully sleeping remove the 12V supply. If you want only check your batteries for example to overwinter omit the 12V connection. With the battery request button both batteries can be wake up and give all cell related values.

NOTE: If you want to use your batteries in a solar application you need to interface the power pins too. At the time of writing there are no connectors which fit like the original buyable. If you find a solution to safely connect the main power pins, leave me a message.

MQTT remote connection

If you enter your server credentials in the settings page, it will publish all battery (A & B if connected to the scooter) values within topic "niu/batteryChecker". You can request battery data if connected directly to a battery if you send "true" to "niu/batteryChecker/BatteryRequest". You dont need to request battery data if connected to your scooter, because batteries will send data, even if the scooter is off, regularly.

If you use a 3rd party battery charger and would enable it remotely, you can send "true" to enable and "false" to disable charging mode with topic "niu/batteryChecker/EnableCharger".

Home Assistant integration

If you want to integrate all battery data in your Home Assistant setup, you can use the template in the doc folder. Of course a working mqtt (mosquitto add on for example) server and configuration on the T-CAN should be properly set up. You need to include this custom mqtt integration in your configuration.yaml like this:

mqtt: !include homeassistant-niu-mqtt.yaml

HA

Example terminal output

------------------------------------------------------------------------------
|                     NIU CAN Battery Checker v2.1                           |
------------------------------------------------------------------------------
| Battery A                                                                  |
------------------------------------------------------------------------------
| V:    77.82V | I:    -2.28A | P:   -177W | SoC:  76% | Cycles: 123         |
| Cell V (Min/Max): 3.847V / 3.865V                                          |
------------------------------------------------------------------------------
| Cell Voltages (V)                                                          |
| 3.868 | 3.863 | 3.862 | 3.867 | 3.896 | 3.896 | 3.896 | 3.900              |
| 3.901 | 3.897 | 3.901 | 3.902 | 3.854 | 3.859 | 3.858 | 3.856              |
| 3.858 | 3.857 | 3.863 | 3.866 |       |       |       |                    |
| Cell Temperatures (C)                                                      |
| 32    C| 32    C| 32    C| 32    C| 33    C| 36    C| 35    C| 36    C     |
------------------------------------------------------------------------------
| Battery B                                                                  |
------------------------------------------------------------------------------
| V:    77.43V | I:    -4.23A | P:   -328W | SoC:  75% | Cycles: 122         |
| Cell V (Min/Max): 3.894V / 3.908V                                          |
------------------------------------------------------------------------------
| Cell Voltages (V)                                                          |
| 3.874 | 3.874 | 3.871 | 3.874 | 3.903 | 3.908 | 3.905 | 3.905              |
| 3.909 | 3.903 | 3.895 | 3.905 | 3.870 | 3.872 | 3.872 | 3.870              |
| 3.903 | 3.903 | 3.903 | 3.903 |       |       |       |                    |
| Cell Temperatures (C)                                                      |
| 32    C| 32    C| 32    C| 32    C| 32    C| 36    C| 35    C| 35    C     |
------------------------------------------------------------------------------
| Scooter & System                                                           |
------------------------------------------------------------------------------
| Odometer:   1941.56 km | Speed:  59 km/h  | Mode: Sport                    |
| DCDC:  14.1V,   1.3A,  37C | FOC:   58C   | Motor:   45C                   |
| Ready: Yes | Stand: Down     | Seat: Open   | Beam: On                     |
------------------------------------------------------------------------------
| Charging Status                                                            |
------------------------------------------------------------------------------
| Command: OFF | Auto-Logic: OFF | Auto-Stop: NO  | Manual-Ovr: NO           |
------------------------------------------------------------------------------

Pictures

Preview of web gui

GUI

Update rate of mqtt variables

MQTT

72V Battery connector

T-CAN485

DBC File

I started generating a DBC file of found metrics on CAN bus, if you want to tinker with your scooter feel free to use it.

Support

If you want to buy me a coffee you can donate via PayPal via c at pfalz-mail.de

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published