https://github.com/forderud/hidbattery
Arduino battery emulator
https://github.com/forderud/hidbattery
arduino battery hid
Last synced: about 1 year ago
JSON representation
Arduino battery emulator
- Host: GitHub
- URL: https://github.com/forderud/hidbattery
- Owner: forderud
- License: mit
- Created: 2025-01-20T08:54:45.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-22T11:05:00.000Z (about 1 year ago)
- Last Synced: 2025-04-22T12:12:10.585Z (about 1 year ago)
- Topics: arduino, battery, hid
- Language: C++
- Homepage:
- Size: 539 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Arduino battery emulator
Make an Arduino board with USB capabilities act as a [HID Power Device](https://www.usb.org/sites/default/files/pdcv11.pdf) to emulate one or more battery packs. This can be useful for simulating various power scenarios that are otherwise hard to test with an actual battery.
The project is based on Alexander Bratchik's [HIDPowerDevice](https://github.com/abratchik/HIDPowerDevice) project, but with changes to make the emulated battery more like a "battery" instead of a "UPS". The project is also extended to emulate multiple batteries.
## Supported Arduinos
* (Pro)[Micro](https://docs.arduino.cc/hardware/micro/)
* Leonardo
## Setup & Usage
Clone this repository to your Arduino libraries folder (`C:\Users\\Documents\Arduino\libraries` on Windows). Then, open the `battery/battery.ino` sketch in Arduino IDE and press "Upload". The Operating System will afterwards detect one or more new batteries.
The [`BatteryQuery.exe`](https://github.com/forderud/BatterySimulator) tool can be used for querying battery parameters from the command line.
### Additional setup on Linux
Copy `linux/98-upower-hid.rules` file to the `/etc/udev/rules.d/` folder and reboot. This is required for Linux device manager (udev) to recognize the Arduino board as a battery.
## Tested on the following Operating Systems
* Mac OS 14 Sonoma
* Ubuntu 24 LTS
* Windows 2000 - 11
### Screenshots
#### Windows 11

Obtained with `CDC_DISABLED` defined[^1] to emulate 6 batteries.
#### Windows 10

Obtained with `CDC_DISABLED` defined[^1] to emulate 6 batteries.
#### Windows 2000

Obtained with `CDC_DISABLED` defined[^1] to emulate 6 batteries.
[^1]: `CDC_DISABLED` can be defined by uncommenting a line in `%LOCALAPPDATA%\Arduino15\packages\arduino\hardware\avr\\cores\arduino\USBDesc.h`. This will disable serial console over USB, which will free up 3 USB endpoints for alternative usage.
### MacOS

Limitation: MacOS displays the battery as a UPS. The UI furthermore only display aggregated information, and not per-battery.
### Linux

Limtation: Linux seem to assume charge values in `%`, regardless of the actual unit ([upower issue #300](https://gitlab.freedesktop.org/upower/upower/-/issues/300)).
# Windows HidBatt extension driver
This repo also contains a [`HidBattExt`](HidBattExt/) filter driver that extends the in-built `HidBatt` driver in Windows to also parse and report `CycleCount` and `Temperature` battery parameters.