Skip to content

About

Hacking NIU Electric Scooters (KQI series)

Resources

Stars

8 stars

Watchers

0 watching

Forks

Latest commit

 

History

29 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hacking NIU Electric Scooters (KQI series) - ESP32-driven BMS emulator

This repository is supposed to serve as a summary of findings when trying to customize the experience of NIU scooters for me in a private manner. I created an ESP32-driven workaround for broken batteries. I hope it is useful for others.

Background Story

I bought a NIU KQI3 Pro scooter at the end of 2024 and it has taken me already almost 4500km since then. Those are very nice scooters and they are really well made. Read more...

Battery Emulator (v1)

Read more about v1 here.

Improved Battery Emulator (v2)

Like in v1, I created an ESP32-based workaround for the missing serial interface on the BMS. It's a workaround, and it pretends to be a battery while not being linked to it at all except for measuring the battery voltage to assess SOC status. I chose an ESP32 Relay board, because it allows for connecting up to 60V power supply with an integrated power circuit to bring this down to 5V the ESP32 needs. Again, it also has Berry support.

IMG_0795

In this case the connector to the controller is linked to two GPIOs 14 and 13 as RX/TX. The (very simple) voltage divider brings the 39.0V-54.6V range from the battery down to some 2-3 volts, which can be read by the ESP32 on analog input GPIO 34. The capacitor is used for smoothing and can be omitted if not available. Now, in order to get the battery voltage, you can use a Y-cable.

Note: You can change the GPIOs to what you like, but note that e.g. GPIO 12 is internally linked to the flash voltage. Because the ESP32 needs to have this one floating on boot and the controller will pull it down, the ESP32 does not boot if it is connected to GPIO 12. The same likely applies to GPIO 0 or 2.

TAKE CARE TO NOT FRY THE BOARD OR YOURSELF.

Tasmota Setup

The ESP32 is flashed with Tasmota. Get information how to do that from there. There are two important things to consider here:

  • Tasmota is not supposed to run in standalone mode. In other words, it will reset after 3 minutes if not connected to a network. This is bad, but luckily there is a patch for that.
  • The ESP32 will be always on, which is bad, unnecessary and drains battery over time. Luckily there is a feature called ULP (Ultra-Low-Power) which we can use.

So we patch the sources and include ULP support. ULP is the mode allowing the ESP32 to turn completely off and to come back to life based on e.g. an interrupt or counting edges on GPIOs. The precompiled binaries in the prebuilts folder include ULP support and the patch.

After flashing, if you connect the ESP32 to power, it will spawn a WIFI hotspot and will be available under a weird name like tasmota_XXXXXX. The IP is 192.168.4.1.

  • You can change the hostname. The WIFI hotspot will from then on have the same name.
  • Set GPIO 34 to an Analog Range input.
  • On the Console you need to map the parameters for the input to a plausible SOC value. I have not really calibrated it yet, but these values seem to work to scale the SOC to give something between 0 and 100%
      AdcParam1 34,2900,3700,0,100
    

Then you can move on with uploading the scripts.

Berry Scripts

Finally, you need to put the autoexec.be and the runulp.be Berry scripts into the file system of the ESP32 and restart. Done!

The biggest issue previously was to get the supply voltage to the ESP. The Relay board solves that elegantly now. And here's the catch:

We can now use the ULP mode listening on the RX line of the ESP32 to power it up and down once the scooter is powered on/off.

In a nutshell, over the RX/TX line the controller requests data from the battery, respectively the emulator. But it stops requesting data once it is powered off and the RX/TX lines stay silent. If there is no communication, the ESP32 recognizes this and goes into ultra deep sleep mode, as there's a timer in the script which checks if there has been any communication with the controller recently. On timer expiration, it calls the sleep script.

The Berry script currently waits for 30 seconds before sending the ESP to sleep. In ULP mode, it listens on GPIO 14 and if there is an edge detected, it turns on automatically.

Updating Scooter Firmware

Below there are a few links to upgrade the firmware of the scooter with a modified Android app. During any update, the controller does not send the usual packages. Therefore, the ESP will go to sleep, which leads to upgrade failure.

If you are trying to update the firmware of the scooter, make sure that you disable the runULP.be script before doing so. It is fine to add a return statement as the first line in the script, which can be easily removed after the upgrade has succeeded.

Parts list

Known Issues (v2)

The rest of the issues are minor actually.

  • Despite using ULP, the ESP32 will wake up periodically and will not be in deep-sleep all the time. I think it is somewhat around 15 minutes. I weren't able yet to increase this timeout; however, it will go back to sleep again as there is no communication happening;
  • The WIFI is the most power-hungry part still; one can add a "Wifi Off" as a rule to tasmota on boot-up, but that makes the ESP32 unavailable once mounted. It's a tradeoff, I rather live with it.
  • I did not find an ESP module accepting the 48V without relays. They are superficial and make the board bulky. Will continue searching...

More links to modify the NIU scooters

Here are a few links for modifying the NIU scooters:

Disclaimer

⚠️ DANGER OF ELECTROCUTION ⚠️

You very likely loose any guarantee or warranty when modifying your scooter. I don't take any responsibility for any lost warranty or guarantee, any personal harm to anyone, or if anything else going wrong neither during assembly or use. Nor do I take any responsibility if you violate any local regulations concerning driving safety or local guidelines (e.g. max speed in Austria is 25km/h, in Germany it is 20km/h, and so on). Also I have to repeat at this point what is mentioned also in the Tasmota repository in a modified form, particular because working with DC is even more dangerous than working with AC probably:

If your device connects to mains electricity (AC power) there is danger of electrocution if not installed properly - this applies mainly to the part where you connect the charger to the controller/battery/scooter. If you don't know how to install it (or what you are doing overall), either leave it or please call an expert in electronics or talk to a repair shop guy for scooters. Remember: SAFETY FIRST. It is not worth the risk to yourself, your family and your home if you don't know exactly what you are doing. I don't take any responsibility nor liability for for any software part on this page nor for the installation or any tips, advice, videos, etc. given by anyone else in the issues section or elsewhere.

About

Hacking NIU Electric Scooters (KQI series)

Resources

Stars

8 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages