# Adafruit Unified Sensor Driver #
Many small embedded systems exist to collect data from sensors, analyse the data, and either take an appropriate action or send that sensor data to another system for processing.
One of the many challenges of embedded systems design is the fact that parts you used today may be out of production tomorrow, or system requirements may change and you may need to choose a different sensor down the road.
Creating new drivers is a relatively easy task, but integrating them into existing systems is both error prone and time consuming since sensors rarely use the exact same units of measurement.
By reducing all data to a single **sensors\_event\_t** 'type' and settling on specific, **standardised SI units** for each sensor family the same sensor types return values that are comparable with any other similar sensor. This enables you to switch sensor models with very little impact on the rest of the system, which can help mitigate some of the risks and problems of sensor availability and code reuse.
The unified sensor abstraction layer is also useful for data-logging and data-transmission since you only have one well-known type to log or transmit over the air or wire.
## Unified Sensor Drivers ##
The following drivers are based on the Adafruit Unified Sensor Driver:
**Accelerometers**
- [Adafruit\_ADXL345](https://github.com/adafruit/Adafruit_ADXL345)
- [Adafruit\_LSM303DLHC](https://github.com/adafruit/Adafruit_LSM303DLHC)
- [Adafruit\_MMA8451\_Library](https://github.com/adafruit/Adafruit_MMA8451_Library)
**Gyroscope**
- [Adafruit\_L3GD20\_U](https://github.com/adafruit/Adafruit_L3GD20_U)
**Light**
- [Adafruit\_TSL2561](https://github.com/adafruit/Adafruit_TSL2561)
- [Adafruit\_TSL2591\_Library](https://github.com/adafruit/Adafruit_TSL2591_Library)
**Magnetometers**
- [Adafruit\_LSM303DLHC](https://github.com/adafruit/Adafruit_LSM303DLHC)
- [Adafruit\_HMC5883\_Unified](https://github.com/adafruit/Adafruit_HMC5883_Unified)
**Barometric Pressure**
- [Adafruit\_BMP085\_Unified](https://github.com/adafruit/Adafruit_BMP085_Unified)
- [Adafruit\_BMP183\_Unified\_Library](https://github.com/adafruit/Adafruit_BMP183_Unified_Library)
**Humidity & Temperature**
- [DHT-sensor-library](https://github.com/adafruit/DHT-sensor-library)
**Humidity, Temperature, & Barometric Pressure**
- [Adafruit_BME280_Library](https://github.com/adafruit/Adafruit_BME280_Library/)
**Orientation**
- [Adafruit_BNO055](https://github.com/adafruit/Adafruit_BNO055)
**All in one device**
- [Adafruit_LSM9DS0](https://github.com/adafruit/Adafruit_LSM9DS0_Library) (accelerometer, gyroscope, magnetometer)
- [Adafruit_LSM9DS1](https://github.com/adafruit/Adafruit_LSM9DS1/) (accelerometer, gyroscope, magnetometer)
## How Does it Work? ##
Any driver that supports the Adafruit unified sensor abstraction layer will implement the Adafruit\_Sensor base class. There are two main typedefs and one enum defined in Adafruit_Sensor.h that are used to 'abstract' away the sensor details and values:
## Sensor Types (`sensors_type_t`)
These pre-defined sensor types are used to properly handle the two related typedefs below, and allows us determine what types of units the sensor uses, etc.
```c++
/** Sensor types */
typedef enum
{
SENSOR_TYPE_ACCELEROMETER = (1),
SENSOR_TYPE_MAGNETIC_FIELD = (2),
SENSOR_TYPE_ORIENTATION = (3),
SENSOR_TYPE_GYROSCOPE = (4),
SENSOR_TYPE_LIGHT = (5),
SENSOR_TYPE_PRESSURE = (6),
SENSOR_TYPE_PROXIMITY = (8),
SENSOR_TYPE_GRAVITY = (9),
SENSOR_TYPE_LINEAR_ACCELERATION = (10),
SENSOR_TYPE_ROTATION_VECTOR = (11),
SENSOR_TYPE_RELATIVE_HUMIDITY = (12),
SENSOR_TYPE_AMBIENT_TEMPERATURE = (13),
SENSOR_TYPE_VOLTAGE = (15),
SENSOR_TYPE_CURRENT = (16),
SENSOR_TYPE_COLOR = (17)
} sensors_type_t;
```
## Sensor Details (`sensor_t`)
This typedef describes the specific capabilities of this sensor, and allows us to know what sensor we are using beneath the abstraction layer.
```c++
/* Sensor details (40 bytes) */
/** struct sensor_s is used to describe basic information about a specific sensor. */
typedef struct
{
char name[12];
int32_t version;
int32_t sensor_id;
int32_t type;
float max_value;
float min_value;
float resolution;
int32_t min_delay;
} sensor_t;
```
The individual fields are intended to be used as follows:
- **name**: The sensor name or ID, up to a maximum of twelve characters (ex. "MPL115A2")
- **version**: The version of the sensor HW and the driver to allow us to differentiate versions of the board or driver
- **sensor\_id**: A unique sensor identifier that is used to differentiate this specific sensor instance from any others that are present on the system or in the sensor network
- **type**: The sensor type, based on **sensors\_type\_t** in sensors.h
- **max\_value**: The maximum value that this sensor can return (in the appropriate SI unit)
- **min\_value**: The minimum value that this sensor can return (in the appropriate SI unit)
- **resolution**: The smallest difference between two values that this sensor can report (in the appropriate SI unit)
- **min\_delay**: The minimum delay in microseconds between two sensor events, or '0' if there is no constant sensor rate
## Sensor Data/Events (`sensors_event_t`)
This typedef is used to return sensor data from any sensor supported by the abstraction layer, using standard SI units and scales.
```c++
/* Sensor event (36 bytes) */
/** struct sensor_event_s is used to provide a single sensor event in a common format. */
typedef struct
{
int32_t version;
int32_t sensor_id;
int32_t type;
int32_t reserved0;
int32_t timestamp;
union
{
float data[4];
sensors_vec_t acceleration;
sensors_vec_t magnetic;
sensors_vec_t orientation;
sensors_vec_t gyro;
float temperature;
float distance;
float light;
float pressure;
float relative_humidity;
float current;
float voltage;
sensors_color_t color;
};
} sensors_event_t;
```
It includes the following fields:
- **version**: Contain 'sizeof(sensors\_event\_t)' to identify which version of the API we're using in case this changes in the future
- **sensor\_id**: A unique sensor identifier that is used to differentiate this specific sensor instance from any others that are present on the system or in the sensor network (must match the sensor\_id value in the corresponding sensor\_t enum above!)
- **type**: the sensor type, based on **sensors\_type\_t** in sensors.h
- **timestamp**: time in milliseconds when the sensor value was read
- **data[4]**: An array of four 32-bit values that allows us to encapsulate any type of sensor data via a simple union (further described below)
## Required Functions
In addition to the two standard types and the sensor type enum, all drivers based on Adafruit_Sensor must also implement the following two functions:
```c++
bool getEvent(sensors_event_t*);
```
Calling this function will populate the supplied sensors\_event\_t reference with the latest available sensor data. You should call this function as often as you want to update your data.
```c++
void getSensor(sensor_t*);
```
Calling this function will provide some basic information about the sensor (the sensor name, driver version, min and max values, etc.
## Standardised SI values for `sensors_event_t`
A key part of the abstraction layer is the standardisation of values on SI units of a particular scale, which is accomplished via the data[4] union in sensors\_event\_t above. This 16 byte union includes fields for each main sensor type, and uses the following SI units and scales:
- **accele
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
嵌入式优质项目,资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松copy复刻,拿到资料包后可轻松复现出一样的项目。 本人单片机开发经验充足,深耕嵌入式领域,有任何使用问题欢迎随时与我联系,我会及时为你解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明,项目具体内容可查看下方的资源详情。 【附带帮助】: 若还需要嵌入式物联网单片机相关领域开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步。 【本人专注嵌入式领域】: 有任何使用问题欢迎随时与我联系,我会及时解答,第一时间为你提供帮助,CSDN博客端可私信,为你解惑,欢迎交流。 【建议小白】: 在所有嵌入式开发中硬件部分若不会画PCB/电路,可选择根据引脚定义将其代替为面包板+杜邦线+外设模块的方式,只需轻松简单连线,下载源码烧录进去便可轻松复刻出一样的项目 【适合场景】: 相关项目设计中,皆可应用在项目开发、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面中 可借鉴此优质项目实现复刻,也可以基于此项目进行扩展来开发出更多功能
资源推荐
资源详情
资源评论
收起资源包目录
基于Arduino设计的指纹解锁门禁系统.zip(皆可应用在毕设/课设/大作业/实训/竞赛/项目开发) (248个子文件)
README.adoc 991B
u8g_font_data.c 4.25MB
chessengine.c 62KB
u8g_font.c 36KB
u8g_dev_ssd1351_128x128.c 19KB
u8g_dev_ssd1306_128x64.c 18KB
u8g_ll_api.c 15KB
u8g_dev_st7687_c144mvgd.c 14KB
u8g_com_i2c.c 13KB
u8g_dev_ili9325d_320x240.c 13KB
u8g_rot.c 13KB
u8g_dev_ssd1353_160x128.c 12KB
u8g_dev_ssd1322_nhd31oled_bw.c 12KB
u8g_dev_ssd1322_nhd31oled_gr.c 12KB
u8g_com_arduino_t6963.c 12KB
u8g_dev_ssd1306_128x32.c 12KB
u8g_com_arduino_hw_spi.c 11KB
u8g_dev_ssd1327_96x96_gr.c 11KB
u8g_dev_uc1610_dogxl160.c 11KB
u8g_dev_ssd1325_nhd27oled_bw.c 10KB
u8g_dev_st7565_lm6063.c 10KB
u8g_dev_ssd1325_nhd27oled_bw_new.c 10KB
u8g_dev_ssd1325_nhd27oled_gr.c 9KB
u8g_dev_ssd1325_nhd27oled_gr_new.c 9KB
u8g_pb8h1.c 9KB
u8g_circle.c 9KB
u8g_com_arduino_st7920_custom.c 9KB
u8g_com_arduino_st7920_spi.c 9KB
u8g_dev_st7565_64128n.c 8KB
u8g_dev_ht1632.c 8KB
u8g_dev_st7565_lm6059.c 8KB
u8g_com_io.c 8KB
u8g_com_arduino_sw_spi.c 8KB
u8g_dev_ld7032_60x32.c 8KB
u8g_dev_ssd1306_64x48.c 8KB
u8g_dev_st7565_nhd_c12864.c 8KB
u8g_dev_uc1601_c128032.c 8KB
u8g_ellipse.c 8KB
u8g_polygon.c 8KB
u8g_dev_st7565_dogm128.c 8KB
u8g_dev_uc1608_240x128.c 8KB
u8g_com_arduino_st7920_hw_spi.c 7KB
u8g_com_arduino_fast_parallel.c 7KB
u8g_dev_t6963_240x128.c 7KB
u8g_dev_t6963_240x64.c 7KB
u8g_dev_t6963_128x128.c 7KB
u8g_dev_t6963_128x64.c 7KB
u8g_com_arduino_no_en_parallel.c 7KB
u8g_dev_st7920_128x64.c 7KB
u8g_delay.c 7KB
u8g_dev_a2_micro_printer.c 7KB
u8g_dev_uc1608_240x64.c 7KB
u8g_pbxh24.c 7KB
u8g_dev_uc1701_dogs102.c 6KB
u8g_dev_uc1701_mini12864.c 6KB
u8g_dev_st7565_dogm132.c 6KB
u8g_dev_st7920_202x32.c 6KB
u8g_com_arduino_ssd_i2c.c 6KB
u8g_dev_st7920_192x32.c 6KB
u8g_com_arduino_uc_i2c.c 6KB
u8g_com_msp430_hw_spi.c 6KB
u8g_com_atmega_st7920_hw_spi.c 6KB
u8g_dev_pcd8544_84x48.c 6KB
u8g_dev_st7565_nhd_c12832.c 6KB
u8g_dev_pcf8812_96x65.c 6KB
u8g_dev_lc7981_160x80.c 5KB
u8g_dev_lc7981_320x64.c 5KB
u8g_pb16h1.c 5KB
u8g_com_atxmega_st7920_hw_spi.c 5KB
u8g_pb32h1.c 5KB
u8g_pb16h2.c 5KB
u8g_dev_lc7981_240x128.c 5KB
u8g_dev_lc7981_240x64.c 5KB
u8g_dev_ssd1309_128x64.c 5KB
u8g_pb8h1f.c 5KB
u8g_scale.c 5KB
u8g_com_arduino_parallel.c 5KB
u8g_pb14v1.c 5KB
u8g_com_atmega_parallel.c 5KB
u8g_pb16v1.c 5KB
u8g_rect.c 5KB
u8g_com_arduino_port_d_wr.c 5KB
u8g_pb8v1.c 5KB
u8g_com_atmega_st7920_spi.c 5KB
u8g_pb8h8.c 5KB
u8g_pbxh16.c 5KB
u8g_dev_uc1611_dogxl240.c 5KB
u8g_com_arduino_attiny85_hw_spi.c 5KB
u8g_dev_uc1611_dogm240.c 5KB
u8g_dev_tls8204_84x48.c 5KB
u8g_com_api.c 4KB
u8g_virtual_screen.c 4KB
u8g_com_atmega_hw_spi.c 4KB
u8g_clip.c 4KB
u8g_pb16v2.c 4KB
u8g_pb.c 4KB
u8g_pb8h2.c 4KB
u8g_com_raspberrypi_ssd_i2c.c 4KB
u8g_com_linux_ssd_i2c.c 4KB
u8g_com_atxmega_hw_spi.c 4KB
共 248 条
- 1
- 2
- 3
资源评论
阿齐Archie
- 粉丝: 1w+
- 资源: 2303
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功