{"id":21070693,"url":"https://github.com/microbit-foundation/microbit-v2-battery-voltage","last_synced_at":"2026-01-28T23:02:32.904Z","repository":{"id":236274058,"uuid":"792277533","full_name":"microbit-foundation/microbit-v2-battery-voltage","owner":"microbit-foundation","description":"A C++ example project showing how to measure the battery voltage with a BBC micro:bit V2","archived":false,"fork":false,"pushed_at":"2024-11-15T20:01:09.000Z","size":31,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-29T19:58:53.179Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microbit-foundation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-26T10:38:15.000Z","updated_at":"2024-11-18T11:23:23.000Z","dependencies_parsed_at":"2024-04-26T11:41:47.928Z","dependency_job_id":"3d91bda1-e12b-4b9f-a25d-d35131307c79","html_url":"https://github.com/microbit-foundation/microbit-v2-battery-voltage","commit_stats":null,"previous_names":["microbit-foundation/microbit-v2-battery-voltage"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/microbit-foundation/microbit-v2-battery-voltage","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microbit-foundation%2Fmicrobit-v2-battery-voltage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microbit-foundation%2Fmicrobit-v2-battery-voltage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microbit-foundation%2Fmicrobit-v2-battery-voltage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microbit-foundation%2Fmicrobit-v2-battery-voltage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microbit-foundation","download_url":"https://codeload.github.com/microbit-foundation/microbit-v2-battery-voltage/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microbit-foundation%2Fmicrobit-v2-battery-voltage/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28854443,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T22:56:21.783Z","status":"ssl_error","status_checked_at":"2026-01-28T22:56:00.861Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T18:47:51.516Z","updated_at":"2026-01-28T23:02:32.884Z","avatar_url":"https://github.com/microbit-foundation.png","language":"CMake","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BBC micro:bit V2 Battery Voltage Measurement\n\nA micro:bit C++ project showing how to measure the BBC micro:bit V2 battery\nvoltage.\n\nThis project measures the input voltage, in millivolts, of the nRF52833\nmicrocontroller. It shows the value on the micro:bit display and also sends\nit via serial.\n\nIt's important to note that the battery voltage is not exactly the same\nas the microcontroller input voltage, as there is some\n[safety circuitry](https://github.com/microbit-foundation/microbit-v2-hardware)\nbetween the battery and the microcontroller that will produce a small voltage\ndrop.\n\nA prebuilt hex file can be downloaded from the\n[GitHub Releases page](https://github.com/microbit-foundation/microbit-v2-battery-voltage/releases).\n\nA similar example for micro:bit V1 can be found in:\nhttps://os.mbed.com/teams/microbit/code/microbit-battery-test/\n\n## Logging the voltage\n\nIf the button A is pressed (keep it pressed until the text stops scrolling and\nall display LEDs are on), the battery voltage will be logged into the\n[data log](https://microbit.org/get-started/user-guide/data-logging/).\n\nThe voltage is logged once per minute, and when the log is full\n(it should take over 5 days) a cross will be displayed and the programme will\nstop running.\n\nThe data-log can then be accessed by connecting the micro:bit to a computer\nand opening the `MY_DATA.HTM` file inside the `MICROBIT` USB drive.\n\n## How is the battery voltage measured\n\nTo measure the micro:bit battery voltage, the nRF52833 (the target MCU)\nmicrocontroller ADC is used to measure its Vdd input voltage.\n\nAll the ADC channels are currently used for the Analogue pins and the on-board\nmicrophone, so for this example we hijack the ADC channel used for P0 and\nre-route it to the internal Vdd (voltage from the microcontroller power input).\n\nIt's important to note that there are two protection diodes and a voltage\nregulator between the battery connector and the microcontroller Vdd pin,\nas can be seen in the\n[micro:bit open source schematics](https://github.com/microbit-foundation/microbit-v2-hardware).\n\nSo, there is a voltage drop on these components that will vary on different\nfactors, like the current load and component temperature.\nThrough some of the micro:bit testing we measured this voltage\ndrop ranging from 210 to 300 mV (measured without any additional\nload on the micro:bit power supply).\nHowever, these values should not be considered definitive,\nas they may further fluctuate under different conditions.\n\n## Building the project\n\n### Dependencies\n\n- [GNU Arm Embedded Toolchain](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)\n- [Git](https://git-scm.com)\n- [CMake](https://cmake.org/download/)\n- [Python 3](https://www.python.org/downloads/)\n- [Ninja Build](https://ninja-build.org/) (only needed on Windows)\n\nFor example, to install these dependencies on Ubuntu:\n\n```\nsudo apt install gcc\nsudo apt install git\nsudo apt install cmake\nsudo apt install gcc-arm-none-eabi binutils-arm-none-eabi\n```\n\n### Building\n\n- Install the dependencies\n- Clone this repository\n  ```\n  git clone https://github.com/microbit-foundation/microbit-v2-battery-voltage.git\n  ```\n- In the root of this repository run the `build.py` script\n  ```\n  cd microbit-v2-battery-voltage\n  python build.py\n  ```\n- The `MICROBIT.hex` hex file will be built and placed in the root folder.\n- Copy the `MICROBIT.hex` file into the `MICORBIT` USB drive to flash the\n  micro:bit\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrobit-foundation%2Fmicrobit-v2-battery-voltage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrobit-foundation%2Fmicrobit-v2-battery-voltage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrobit-foundation%2Fmicrobit-v2-battery-voltage/lists"}