{"id":48188704,"url":"https://github.com/libmcu/hlw811x","last_synced_at":"2026-04-04T17:52:57.545Z","repository":{"id":251588699,"uuid":"837848921","full_name":"libmcu/hlw811x","owner":"libmcu","description":"HLW8112/HLW8110 power metering ICs driver","archived":false,"fork":false,"pushed_at":"2025-07-18T01:39:41.000Z","size":60,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-18T06:09:38.851Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","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/libmcu.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,"zenodo":null}},"created_at":"2024-08-04T08:11:22.000Z","updated_at":"2025-07-18T01:39:44.000Z","dependencies_parsed_at":"2025-06-11T04:10:08.483Z","dependency_job_id":null,"html_url":"https://github.com/libmcu/hlw811x","commit_stats":null,"previous_names":["libmcu/hlw811x"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/libmcu/hlw811x","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libmcu%2Fhlw811x","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libmcu%2Fhlw811x/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libmcu%2Fhlw811x/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libmcu%2Fhlw811x/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libmcu","download_url":"https://codeload.github.com/libmcu/hlw811x/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libmcu%2Fhlw811x/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31407655,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T10:20:44.708Z","status":"ssl_error","status_checked_at":"2026-04-04T10:20:06.846Z","response_time":60,"last_error":"SSL_read: 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":"2026-04-04T17:52:56.708Z","updated_at":"2026-04-04T17:52:57.519Z","avatar_url":"https://github.com/libmcu.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HLW811x driver\n\nMinimal C driver for HLW811x energy metering ICs – no external dependencies, no RTOS required.\n\nProvides direct access to voltage, current, power, energy, frequency, and phase angle through low-level register interaction.\n\n## Highlights\n\n- No external dependencies (pure C99)\n- Suitable for STM32, ESP32, or bare-metal systems\n- Minimal heap usage — dynamic memory used only once at initialization\n\n## Limitations\n\nThis driver currently supports only a single HLW811x instance.\nSupport for multiple devices (via dependency injection of I/O functions) is under consideration.\nLet us know if this is important for your use case.\n\n## Used in Production\nThis driver is used in the [Pazzk open-source EV charger project](https://github.com/pazzk-labs/evse) to monitor real-time AC input parameters such as voltage, current, and power.\nSee [`hlw811x_meter.c`](https://github.com/pazzk-labs/evse/blob/main/src/metering/adapter/hlw8112.c) for a working integration on ESP32.\n\n## Quick Start\n\n```c\nstruct hlw811x_coeff coeff;\n\nhlw811x_init(HLW811X_UART);\nhlw811x_reset();\nsleep_ms(60);\n\nhlw811x_read_coeff(\u0026coeff);\n\nhlw811x_set_resistor_ratio(\u0026(const struct hlw811x_resistor_ratio) {\n    .K1_A = 1,\n    .K1_B = 1,\n    .K2 = 1,\n});\nhlw811x_set_pga(\u0026(const struct hlw811x_pga) {\n    .A = HLW811X_PGA_GAIN_16,\n    .B = HLW811X_PGA_GAIN_2,\n    .U = HLW811X_PGA_GAIN_1,\n});\nhlw811x_set_channel_b_mode(HLW811X_B_MODE_NORMAL);\nhlw811x_set_active_power_calc_mode(HLW811X_ACTIVE_POWER_MODE_POS_NEG_ALGEBRAIC);\nhlw811x_set_rms_calc_mode(HLW811X_RMS_MODE_AC);\nhlw811x_set_data_update_frequency(HLW811X_DATA_UPDATE_FREQ_HZ_3_4);\nhlw811x_set_zerocrossing_mode(HLW811X_ZEROCROSSING_MODE_POSITIVE);\nhlw811x_set_interrupt_mode(HLW811X_INTR_PULSE_OUT_A, HLW811X_INTR_B_LEAKAGE);\nhlw811x_enable_waveform();\nhlw811x_enable_zerocrossing();\nhlw811x_enable_powerfactor();\nhlw811x_enable_b_channel_comparator();\nhlw811x_enable_interrupt(HLW811X_INTR_PULSE_OUT_A | HLW811X_INTR_B_LEAKAGE);\nhlw811x_enable_channel(HLW811X_CHANNEL_ALL);\nhlw811x_enable_pulse(HLW811X_CHANNEL_ALL);\n\nhlw811x_select_channel(HLW811X_CHANNEL_A);\n\nint32_t mV, mA, mW, watt, centiHz, pf_centi, centidegree;\n\nhlw811x_get_rms(HLW811X_CHANNEL_U, \u0026mV);\nhlw811x_get_rms(HLW811X_CHANNEL_A, \u0026mA);\nhlw811x_get_power(\u0026mW);\nhlw811x_get_energy(HLW811X_CHANNEL_A, \u0026watt);\nhlw811x_get_frequency(\u0026centiHz);\nhlw811x_get_power_factor(\u0026pf_centi);\nhlw811x_get_phase_angle(\u0026centidegree, HLW811X_LINE_FREQ_60HZ);\n```\n\n## Contributing\nContributions are welcome.\n\nFeel free to open issues or PRs\tto improve the driver, fix bugs, or add features.\n\n## License\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibmcu%2Fhlw811x","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibmcu%2Fhlw811x","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibmcu%2Fhlw811x/lists"}