{"id":19738437,"url":"https://github.com/sensirion/embedded-i2c-scd4x","last_synced_at":"2025-04-30T05:31:28.440Z","repository":{"id":44421426,"uuid":"329872779","full_name":"Sensirion/embedded-i2c-scd4x","owner":"Sensirion","description":"Embedded driver for the SCD4x sensor family.","archived":false,"fork":false,"pushed_at":"2024-05-13T13:03:43.000Z","size":1169,"stargazers_count":24,"open_issues_count":0,"forks_count":18,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-05-13T14:30:02.917Z","etag":null,"topics":["co2","driver","embedded","i2c","scd40","scd41","scd4x","scd4x-sensor","sensirion","sensirion-embedded-drivers","sensirion-i2c","sensirion-sensors","sensor"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sensirion.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2021-01-15T09:55:26.000Z","updated_at":"2024-05-13T14:30:03.752Z","dependencies_parsed_at":"2024-05-13T14:30:03.130Z","dependency_job_id":"45783453-ded4-46ed-8e45-da5eb60af0e4","html_url":"https://github.com/Sensirion/embedded-i2c-scd4x","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sensirion%2Fembedded-i2c-scd4x","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sensirion%2Fembedded-i2c-scd4x/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sensirion%2Fembedded-i2c-scd4x/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sensirion%2Fembedded-i2c-scd4x/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sensirion","download_url":"https://codeload.github.com/Sensirion/embedded-i2c-scd4x/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224197821,"owners_count":17271999,"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","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":["co2","driver","embedded","i2c","scd40","scd41","scd4x","scd4x-sensor","sensirion","sensirion-embedded-drivers","sensirion-i2c","sensirion-sensors","sensor"],"created_at":"2024-11-12T01:14:14.193Z","updated_at":"2025-04-30T05:31:28.430Z","avatar_url":"https://github.com/Sensirion.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sensirion I2C SCD4X embedded Library\n\nThis document explains how to set up a sensor of the SCD4X family to run on an embedded device using the I²C interface.\n\n\u003cimg src=\"images/SCD41.png\" width=\"300px\"\u003e\n\nClick [here](https://sensirion.com/products/catalog/SEK-SCD41) to learn more about the Sensirion SCD4X sensor family.\n\n\nNot all sensors of this driver family support all measurements.\nIn case a measurement is not supported by all sensors, the products that\nsupport it are listed in the API description.\n\n\n\n## Supported sensor types\n\n| Sensor name   | I²C Addresses  |\n| ------------- | -------------- |\n|[SCD40](https://sensirion.com/products/catalog/SCD40)| **0x62**|\n|[SCD41](https://sensirion.com/products/catalog/SCD41)| **0x62**|\n\nThe following instructions and examples use a *SCD41*.\n\n\n\n## Setup Guide\n\n### Connect the Sensor\n\nYour sensor has 4 pins that need to be connected to your board: SCL, GND, VDD, SDA.\nUse the following description to connect your SCD4X:\n\n\u003cimg src=\"images/SCD41_pinout.png\" width=\"300px\"\u003e\n\n| *Pin* | *Cable Color* | *Name* | *Description*  | *Comments* |\n|-------|---------------|:------:|----------------|------------|\n| 1 | yellow | SCL | I2C: Serial clock input |\n| 2 | black | GND | Ground |\n| 3 | red | VDD | Supply Voltage | 2.4V to 5.5V\n| 4 | green | SDA | I2C: Serial data input / output |\n\n\n\nThe recommended voltage is 3.3V.\n\n### Configure the code\n\nIn order to use the provided code we need to adjust two files according to your platform.\n\n### Edit `sensirion_i2c_hal.c`\n\nThis file contains the implementation of the sensor communication, which\ndepends on your hardware platform. We provide function stubs for your\nhardware's own implementation.\nSample implementations are available for some platforms:\n[`sample-implementations`](sample-implementations). For Linux based platforms\nlike Raspberry Pi you can just replace the unimplemented HAL template with the\nimplementation in `sample-implementations/linux_user_space/`:\n\n```\ncp sample-implementations/linux_user_space/sensirion_i2c_hal.c ./\n```\n\n### Edit `sensirion_config.h`\n\nSkip this part for Linux based platforms since everything is already setup for\nthis case.\n\nOtherwise you need to check if the libraries `\u003cstdint.h\u003e` and `\u003cstdlib.h\u003e` are\nprovided by your toolchain, compiler or system. If you have no idea on how to\ndo that you can skip this step for now and come back when you get errors\nrelated to these names when compiling the driver.\nThe features we use from those libraries are type definitions for integer sizes\nfrom `\u003cstdint.h\u003e` and `NULL` from `\u003cstdlib.h\u003e`. If they are not available you\nneed to specify the following integer types yourself:\n\n* `int64_t` = signed 64bit integer\n* `uint64_t` = unsigned 64bit integer\n* `int32_t` = signed 32bit integer\n* `uint32_t` = unsigned 32bit integer\n* `int16_t` = signed 16bit integer\n* `uint16_t` = unsigned 16bit integer\n* `int8_t` = signed 8bit integer\n* `uint8_t` = unsigned 8bit integer\n\nIn addition to that you will need to specify `NULL`. For both we have a\ndetailed template where you just need to fill in your system specific values.\n\n## Choose the i2c address to use with your product\n\nThe provided example is working with a SCD41, I²C address 0x62.\nIn order to use the code with another product or I²C address you need to change it in the call scd4x_init(ADDRESS) in\n`scd4x_i2c_example_usage.c`. The list of supported I²C-addresses is found in the header\n`scd4x_i2c.h`.\n\n\nNow we are ready to compile and run the example usage for your sensor.\n\n## Compile and Run\n\nPass the source `.c` and header `.h` files in this folder into your C compiler\nand run the resulting binary. This step may vary, depending on your platform.\nHere we demonstrate the procedure for Linux based platforms:\n\n1. Open up a terminal.\n2. Navigate to the directory where this README is located.\n3. Navigate to the subdirectory example-usage.\n4. Run `make` (this compiles the example code into one executable binary).\n5. Run the compiled executable with `./scd4x_i2c_example_usage`\n6. Now you should see the first measurement values appear in your terminal. As\n   a next step you can adjust the example usage file or write your own main\n   function to use the sensor.\n\n## Compile and Run Tests\n\nThe testframekwork used is CppUTest. Pass the source `.cpp`, `.c`  and header `.h`\nfiles from the tests and top level folder into your CPP compiler and run the\nresulting binary. This step may vary, depending on your platform.\nHere we demonstrate the procedure for Linux based platforms:\n\n1. Open up a terminal.\n2. Install CppUTest framework `apt install cpputest`.\n3. Navigate to the directory `tests`.\n4. Run `make` (this compiles the test code into one executable binary).\n5. Run the compiled executable with `./scd4x_test_hw_i2c`.\n6. Now you should see the test output on your console.\n\n# Background\n\n## Files\n\n### sensirion\\_i2c.[ch]\n\nIn these files you can find the implementation of the I2C protocol used by\nSensirion sensors. The functions in these files are used by the embedded driver\nto build the correct frame out of data to be sent to the sensor or receive a\nframe of data from the sensor and convert it back to data readable by your\nmachine. The functions in here calculate and check CRCs, reorder bytes for\ndifferent byte orders and build the correct formatted frame for your sensor.\n\n### sensirion\\_i2c\\_hal.[ch]\n\nThese files contain the implementation of the hardware abstraction layer used\nby Sensirion's I2C embedded drivers. This part of the code is specific to the\nunderlying hardware platform. This is an unimplemented template for the user to\nimplement. In the `sample-implementations/` folder we provide implementations\nfor the most common platforms.\n\n### sensirion\\_config.h\n\nIn this file we keep all the included libraries for our drivers and global\ndefines. Next to `sensirion_i2c_hal.c` *it's the only file you should need to\nedit to get your driver working.*\n\n### sensirion\\_common.[ch]\n\nIn these files you can find some helper functions used by Sensirion's embedded\ndrivers. It mostly contains byte order conversions for different variable\ntypes. These functions are also used by the UART embedded drivers therefore\nthey are kept in their own file.\n\n## Contributing\n\n**Contributions are welcome!**\n\nThis Sensirion library uses\n[`clang-format`](https://releases.llvm.org/download.html) to standardize the\nformatting of all our `.c` and `.h` files. Make sure your contributions are\nformatted accordingly:\n\nThe `-i` flag will apply the format changes to the files listed.\n\n```bash\nclang-format -i *.c *.h\n```\n\nNote that differences from this formatting will result in a failed build until\nthey are fixed.\n\n\n# License\n\nSee [LICENSE](LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsensirion%2Fembedded-i2c-scd4x","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsensirion%2Fembedded-i2c-scd4x","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsensirion%2Fembedded-i2c-scd4x/lists"}