{"id":21477705,"url":"https://github.com/edward62740/scd4x-lpc","last_synced_at":"2025-08-01T11:15:03.609Z","repository":{"id":165838266,"uuid":"641235318","full_name":"edward62740/SCD4x-LPC","owner":"edward62740","description":"Low-power C++ calibration algorithm for SCD4x sensors","archived":false,"fork":false,"pushed_at":"2023-05-27T06:48:03.000Z","size":332,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T08:22:18.845Z","etag":null,"topics":["algorithm","low-power","scd41","scd4x","sensirion"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edward62740.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-05-16T04:02:50.000Z","updated_at":"2025-01-10T21:22:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b6c8c9a-5b44-4e6c-9cf5-a11526a2d9e9","html_url":"https://github.com/edward62740/SCD4x-LPC","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/edward62740/SCD4x-LPC","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edward62740%2FSCD4x-LPC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edward62740%2FSCD4x-LPC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edward62740%2FSCD4x-LPC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edward62740%2FSCD4x-LPC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edward62740","download_url":"https://codeload.github.com/edward62740/SCD4x-LPC/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edward62740%2FSCD4x-LPC/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268214425,"owners_count":24214352,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["algorithm","low-power","scd41","scd4x","sensirion"],"created_at":"2024-11-23T11:14:49.731Z","updated_at":"2025-08-01T11:15:03.595Z","avatar_url":"https://github.com/edward62740.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SCD4x Low-Power Calibration (LPC) Algorithm\nThe SCD4x sensor has a built-in Automatic Self-Calibration (ASC) that is not available for ultra-low power applications that require power-down of the sensor between measurements.\n\nThis C++ algorithm attempts to emulate the behaviors of the ASC in single-shot mode, based on the ASC Application Note (p. 2-5,11-13). The key assumption is that the lowest measured co2 is no less than SCD4X_LPC_BASELINE_CO2_PPM.\u003cbr\u003e \nDo **not** use this (or the ASC) if the assumption does not hold for the application requirements.\u003cbr\u003e\n\n![Graph](https://github.com/edward62740/SCD4x-LPC/blob/master/graph.png)\n\u003cbr\u003e*ASC Application Note (p. 5)*\n\u003cbr\u003e\n\nIt also is designed to run asynchonously (from the sensor) and delays in between function calls are up to the user to enforce. This algorithm provides some safety by taking in a platform defined millisecond timer in the constructor and blocking function calls for the given sensor execution durations (specified in SCD4x datasheet p.8). The HAL function sensirion_i2c_hal_sleep_usec must be implemented as such:\n```\nvoid sensirion_i2c_hal_sleep_usec(uint32_t useconds) {\n\tif(useconds \u003e 1000) return;\n    platform_delay_us(useconds); // platform specific delay or RTC sleep\n}\n```\nThe only function calls that are not handled by this method are the FRC (400ms) and self-test(10000ms, never called by this lib). These need to be manually modified by the user if maximum power savings are needed.\n\nIn general, this algorithm has a FSM that goes through 3 states:\n- First: First reading calibration\n- Initial: Initial period of 576 measurements\n- Standard: Standard period of 2016 measurements (recurring)\n\n\u003cbr\u003e Wherein the FRC is allowed to run once per period, when the reading is below baseline OR at the end of the period, whichever is earlier.\nThe calibration is defined by a signed offset value for each period, where a measurement point $t \\in [0, \\text{NUM MEAS}] \\cap \\mathbb{Z}$, with $f(t)$ representing the co2 reading at point $t$:\n\n```math\n\\text{{offset}} = \\begin{cases}\n    \\text{{BASELINE}} - f(t), \u0026 \\text{{if }} f(t) \u003c \\text{{BASELINE}} \\\n    \\text{{BASELINE}} - \\min(f(t)), \u0026 \\text{{otherwise}}\n\\end{cases}\n\n```\nNote that in the case where $f(t) \u003c \\text{{BASELINE}}$, accuracy may only be restored over a few periods, as the calibration point may represent only a local minimum.\n\nAll the thresholds/configs are user-definable in the header file.\n\nInitialization requires the necessary SCD4x driver function pointers to be passed to the constructor. This allows for the generic C driver to be used, or C++ class instance methods.\n```\nLPC::SCD4X sensor(scd4x_wake_up, scd4x_power_down, scd4x_measure_single_shot,\n\t\t scd4x_get_data_ready_flag, scd4x_read_measurement, scd4x_perform_forced_recalibration,\n\t\t scd4x_persist_settings, sl_sleeptimer_get_tick_count);\n```\n\nIt is recommended to disable ASC and set persistent settings prior to using this algorithm.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedward62740%2Fscd4x-lpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedward62740%2Fscd4x-lpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedward62740%2Fscd4x-lpc/lists"}