{"id":19715886,"url":"https://github.com/wrclark/lis3dh","last_synced_at":"2025-11-23T07:02:08.591Z","repository":{"id":216880345,"uuid":"740656584","full_name":"wrclark/lis3dh","owner":"wrclark","description":"C library for interfacing with the LIS3DH accelerometer","archived":false,"fork":false,"pushed_at":"2025-05-11T14:40:48.000Z","size":12750,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-11T15:33:17.619Z","etag":null,"topics":["accelerometer","c","i2c","lis3dh","raspberrypi","spi","stm32"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wrclark.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":"2024-01-08T19:46:10.000Z","updated_at":"2025-05-11T14:40:51.000Z","dependencies_parsed_at":"2024-01-13T12:03:01.138Z","dependency_job_id":"8b994ecb-e279-48ac-8920-5dd4e780bffb","html_url":"https://github.com/wrclark/lis3dh","commit_stats":null,"previous_names":["wrclark/lis3dh"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/wrclark/lis3dh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrclark%2Flis3dh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrclark%2Flis3dh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrclark%2Flis3dh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrclark%2Flis3dh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wrclark","download_url":"https://codeload.github.com/wrclark/lis3dh/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wrclark%2Flis3dh/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285914727,"owners_count":27252968,"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-11-23T02:00:06.149Z","response_time":135,"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":["accelerometer","c","i2c","lis3dh","raspberrypi","spi","stm32"],"created_at":"2024-11-11T22:39:40.499Z","updated_at":"2025-11-23T07:02:08.585Z","avatar_url":"https://github.com/wrclark.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LIS3DH\n\nA C linux driver for the 3-axis accelerometer LIS3DH. Supports both I2C and SPI. \n\n### Features\n\u003e - FIFO \n\u003e - HP filter\n\u003e - 2G, 4G, 8G and 16G\n\u003e - Low-power mode, normal mode and high-resolution mode\n\u003e - ADC and temperature sensing\n\u003e - Interrupt generation\n\u003e - Free-fall detection\n\u003e - Single-click detection\n\u003e - Double-click detection\n\u003e - 4D/6D orientation detection\n\u003e - Sleep-to-Wake/Return-to-Sleep\n\u003e - Self test\n\n\n## Examples\nSee the `example/` dir for complete code examples and explanations of LIS3DH terminology\n\n## Implementation\nThis driver requires the user to implement the following interface functions:\n\nThis project has example interface code for I2C and SPI used on Raspberry Pi 4 and STM32\n```c\n/* initialise the \"interface\" */\nint init(void);\n/* read from register `reg', `size' amount of bytes, and write them to `dst' */\nint read(uint8_t reg, uint8_t *dst, uint32_t size);\n/* write `value' to register `reg' */\nint write(uint8_t reg, uint8_t value);\n/* sleep for `dur_us' microseconds */\nint sleep(uint32_t dur_us);\n/* deinitalise the \"interface\" */\nint deinit(void);\n```\nAll above functions return `0` on success, and any non-zero value on error.\n\nIf `init` and/or `deinit` are set to `NULL`, they will be ignored. Useful on microcontrollers.\n\n---\n## Functions\n\n```c\nint lis3dh_init(lis3dh_t *lis3dh);\nint lis3dh_deinit(lis3dh_t *lis3dh);\nint lis3dh_configure(lis3dh_t *lis3dh);\nint lis3dh_read(lis3dh_t *lis3dh);\nint lis3dh_read_fifo(lis3dh_t *lis3dh, struct lis3dh_fifo_data *fifo);\nint lis3dh_read_int1(lis3dh_t *lis3dh);\nint lis3dh_read_int2(lis3dh_t *lis3dh);\nint lis3dh_read_click(lis3dh_t *lis3dh);\nint lis3dh_reference(lis3dh_t *lis3dh);\nint lis3dh_reset(lis3dh_t *lis3dh);\nint lis3dh_read_adc(lis3dh_t *lis3dh);\nint lis3dh_read_temp(lis3dh_t *lis3dh);\nint lis3dh_fifo_reset(lis3dh_t *lis3dh);\n```\nAll functions return `0` on success, and any non-zero value on error.\n\n## Raspberry Pi\nFirst run `$ sudo raspi-config` and enable SPI and/or I2C.\n\nEdit `main.c` to use I2C or SPI.\n\nSee `i2c.c` and `spi.c` for which pins/device to use.\n```sh\n$ git clone https://github.com/wrclark/lis3dh.git\n$ cd lis3dh\n$ make\n$ ./lis3dh\n```\n\n## STM32\n### I2C\n```c\n#define LIS3DH_I2C_ADDR 0x18 /* can also be 0x19 */\n\nint i2c_write(uint8_t reg, uint8_t value) {\n    uint8_t buf[2] = { reg, value };\n    HAL_I2C_Master_Transmit(\u0026hi2c2, LIS3DH_I2C_ADDR \u003c\u003c 1, buf, 2, HAL_MAX_DELAY);\n    return 0;\n}\n\nint i2c_read(uint8_t reg, uint8_t *dst, uint32_t size) {\n    if (size \u003e 1) {\n        reg |= 0x80; /* auto-increment bit */\n    }\n    uint8_t send[2] = { reg, 0x00 };\n    HAL_I2C_Master_Transmit(\u0026hi2c2, LIS3DH_I2C_ADDR \u003c\u003c 1, send, 2, HAL_MAX_DELAY);\n    HAL_I2C_Master_Receive(\u0026hi2c2, LIS3DH_I2C_ADDR \u003c\u003c 1, dst, size, HAL_MAX_DELAY);\n    return 0;\n}\n```\n\n### SPI\nCPHA=0 CPOL=0 8 bits motorola\n```c\n/* Every sleep call duration is a multiple of 1000 us (1 ms) */\n/* So dividing this value by 1000 is perfectly fine. */\nint sleep_us(uint32_t dur_us) {``\n    HAL_Delay(dur_us / 1000);\n    return 0;\n}\n\nint spi_write(uint8_t reg, uint8_t value) {\n    uint8_t send[2];\n\n    reg \u0026= 0x3F; /* clear 2 msbit */\n    send[0] = reg;\n    send[1] = value;\n\n    /* CS LOW */\n    HAL_GPIO_WritePin(SPI1_GPIO_CS_GPIO_Port, SPI1_GPIO_CS_Pin, GPIO_PIN_RESET);\n    HAL_SPI_Transmit(\u0026hspi1, send, 2, HAL_MAX_DELAY);\n    /* CS HIGH */\n    HAL_GPIO_WritePin(SPI1_GPIO_CS_GPIO_Port, SPI1_GPIO_CS_Pin, GPIO_PIN_SET);\n\n    return 0;\n}\n\nint spi_read(uint8_t reg, uint8_t *dst, uint32_t size) {\n    uint8_t send[2];\n    reg |= 0x80; /* read bit = 1 */\n\n    if (size \u003e 1) {\n        reg |= 0x40; /* auto increment for rx \u003e 1 */\n    }\n\n    send[0] = reg;\n    send[1] = 0x00;\n\n    /* CS LOW */\n    HAL_GPIO_WritePin(SPI1_GPIO_CS_GPIO_Port, SPI1_GPIO_CS_Pin, GPIO_PIN_RESET);\n    HAL_SPI_Transmit(\u0026hspi1, send, 2, 1000);\n    HAL_SPI_Receive(\u0026hspi1, dst, size, 1000);\n    /* CS HIGH */\n    HAL_GPIO_WritePin(SPI1_GPIO_CS_GPIO_Port, SPI1_GPIO_CS_Pin, GPIO_PIN_SET);\n\n    return 0;\n}\n```\n\nThis project is licensed under the terms of the GNU General Public License v2.0.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwrclark%2Flis3dh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwrclark%2Flis3dh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwrclark%2Flis3dh/lists"}