README and removed weActTest.zip; it will be its own repo

This commit is contained in:
William Clark 2023-12-25 00:06:59 +00:00
parent 950852c151
commit b27722f466
2 changed files with 73 additions and 57 deletions

130
README.md
View File

@ -1,65 +1,81 @@
# LIS3DH
3-axis accelerometer
A C89 driver for the 3-axis accelerometer LIS3DH by ST. Supports both i2c and SPI.
> ### Features
> - FIFO of varying watermark level, up to 32
> - HP filter
> - 2G, 4G, 8G and 16G
> - All power modes
> - Interrupt generation (soon)
> - Free-fall detection (soon)
> - Single and double click detection (soon)
> - 4D/6D orientation detection (soon)
FIFO output example
```
$ ./lis3dh
x: 0.5520 g, y: -0.8800 g, z: 0.0760 g, mag: 1.0416
x: 0.5560 g, y: -0.9000 g, z: -0.0040 g, mag: 1.0579
x: 0.5840 g, y: -0.8680 g, z: 0.0360 g, mag: 1.0468
x: 0.5440 g, y: -0.8680 g, z: 0.0920 g, mag: 1.0285
x: 0.5240 g, y: -0.9000 g, z: -0.0600 g, mag: 1.0432
x: 0.6040 g, y: -0.8960 g, z: 0.1000 g, mag: 1.0852
x: 0.5440 g, y: -0.8680 g, z: 0.0000 g, mag: 1.0244
x: 0.5720 g, y: -0.9040 g, z: -0.0160 g, mag: 1.0699
x: 0.5480 g, y: -0.8680 g, z: 0.0200 g, mag: 1.0267
x: 0.5360 g, y: -0.9120 g, z: 0.0240 g, mag: 1.0581
x: 0.5600 g, y: -0.9040 g, z: 0.0000 g, mag: 1.0634
x: 0.5960 g, y: -0.8760 g, z: 0.0640 g, mag: 1.0615
x: 0.5360 g, y: -0.8960 g, z: -0.0040 g, mag: 1.0441
x: 0.5320 g, y: -0.8800 g, z: -0.0080 g, mag: 1.0283
x: 0.5520 g, y: -0.9000 g, z: -0.0440 g, mag: 1.0567
x: 0.5760 g, y: -0.8800 g, z: 0.0320 g, mag: 1.0522
x: 0.5560 g, y: -0.8840 g, z: -0.0240 g, mag: 1.0446
x: 0.5120 g, y: -0.9040 g, z: -0.0360 g, mag: 1.0395
x: 0.6000 g, y: -0.8720 g, z: 0.0320 g, mag: 1.0590
x: 0.5320, y: -0.8800, z: -0.0600 mag: 1.0301
x: 0.5440, y: -0.8680, z: -0.0760 mag: 1.0272
x: 0.5440, y: -0.8720, z: -0.0760 mag: 1.0306
x: 0.5440, y: -0.8720, z: -0.0760 mag: 1.0306
x: 0.5440, y: -0.8720, z: -0.0760 mag: 1.0306
x: 0.5440, y: -0.8720, z: -0.0760 mag: 1.0306
x: 0.5440, y: -0.8720, z: -0.0760 mag: 1.0306
x: 0.5440, y: -0.8720, z: -0.0760 mag: 1.0306
x: 0.5440, y: -0.8720, z: -0.0760 mag: 1.0306
x: 0.5440, y: -0.8720, z: -0.0760 mag: 1.0306
x: 0.5440, y: -0.8720, z: -0.0760 mag: 1.0306
x: 0.5440, y: -0.8720, z: -0.0720 mag: 1.0303
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0720 mag: 1.0392
x: 0.5480, y: -0.8800, z: -0.0800 mag: 1.0398
x: 0.5480, y: -0.8960, z: -0.0960 mag: 1.0547
```
### Noise at 2G
![DC noise at 2G](.gitea/graph-2g.png)
FIFO demo:
```
$ ./lis3dh
FIFO =>
x: 0.5280, y: -0.8760, z: -0.0080
x: 0.5320, y: -0.8920, z: -0.0120
x: 0.5280, y: -0.8680, z: -0.0040
x: 0.5280, y: -0.8800, z: 0.0080
x: 0.5400, y: -0.8920, z: 0.0120
x: 0.5400, y: -0.8960, z: 0.0120
x: 0.5400, y: -0.8960, z: 0.0000
x: 0.5560, y: -0.8840, z: -0.0040
x: 0.5360, y: -0.8840, z: -0.0160
x: 0.5560, y: -0.8840, z: -0.0040
x: 0.5320, y: -0.8960, z: 0.0080
x: 0.5400, y: -0.8880, z: -0.0040
x: 0.5320, y: -0.8800, z: 0.0000
x: 0.5560, y: -0.8920, z: 0.0120
x: 0.5280, y: -0.8680, z: -0.0120
x: 0.5440, y: -0.8760, z: 0.0000
x: 0.5520, y: -0.8880, z: -0.0040
x: 0.5400, y: -0.8840, z: -0.0160
x: 0.5560, y: -0.8840, z: -0.0040
x: 0.5360, y: -0.8840, z: -0.0040
x: 0.5360, y: -0.8880, z: -0.0160
x: 0.5560, y: -0.8920, z: 0.0080
x: 0.5400, y: -0.8880, z: -0.0120
x: 0.5560, y: -0.8840, z: -0.0160
x: 0.5480, y: -0.8800, z: 0.0040
x: 0.5520, y: -0.8880, z: -0.0040
x: 0.5280, y: -0.8680, z: -0.0160
x: 0.5560, y: -0.8920, z: -0.0040
x: 0.5400, y: -0.8840, z: -0.0040
x: 0.5360, y: -0.8880, z: -0.0080
x: 0.5280, y: -0.8680, z: -0.0120
x: 0.5480, y: -0.8880, z: -0.0120
<= FIFO
### Noise at 4G
![DC noise at 4G](.gitea/graph-4g.png)
### Noise at 8G
![DC noise at 8G](.gitea/graph-8g.png)
### Noise at 16G
![DC noise at 16G](.gitea/graph-16g.png)
## Using i2c on STM32
Simple example code
```c
#define LIS3DH_I2C_ADDR 0x18
int i2c_write(uint8_t reg, uint8_t value) {
uint8_t buf[2] = { reg, value };
HAL_I2C_Master_Transmit(&hi2c2, LIS3DH_I2C_ADDR << 1, buf, 2, HAL_MAX_DELAY);
return 0;
}
int i2c_read(uint8_t reg, uint8_t *dst, uint32_t size) {
uint8_t send[2] = { reg, 0x00 };
HAL_I2C_Master_Transmit(&hi2c2, LIS3DH_I2C_ADDR << 1, send, 2, HAL_MAX_DELAY);
HAL_I2C_Master_Receive(&hi2c2, LIS3DH_I2C_ADDR << 1, dst, size, HAL_MAX_DELAY);
return 0;
}
```

Binary file not shown.