Giter Site home page Giter Site logo

adafruit_sensor's Introduction

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

Gyroscope

Light

Magnetometers

Barometric Pressure

Humidity & Temperature

Humidity, Temperature, & Barometric Pressure

Orientation

All in one device

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.

/** 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),
  SENSOR_TYPE_TVOC                  = (18),
  SENSOR_TYPE_VOC_INDEX             = (19),
  SENSOR_TYPE_NOX_INDEX             = (20),
  SENSOR_TYPE_CO2                   = (21),
  SENSOR_TYPE_ECO2                  = (22),
  SENSOR_TYPE_PM10_STD              = (23),
  SENSOR_TYPE_PM25_STD              = (24),
  SENSOR_TYPE_PM100_STD             = (25),
  SENSOR_TYPE_PM10_ENV              = (26),
  SENSOR_TYPE_PM25_ENV              = (27),
  SENSOR_TYPE_PM100_ENV             = (28),
  SENSOR_TYPE_GAS_RESISTANCE        = (29),
  SENSOR_TYPE_UNITLESS_PERCENT      = (30),
  SENSOR_TYPE_ALTITUDE              = (31),
} 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.

/* 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.

/* 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;
        float           tvoc;
        float           voc_index;
        float           nox_index;
        float           CO2,
        float           eCO2,
        float           pm10_std,
        float           pm25_std,
        float           pm100_std,
        float           pm10_env,
        float           pm25_env,
        float           pm100_env,
        float           gas_resistance,
        float           unitless_percent,
        float           altitude,
        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:

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.

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 standardization 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:

  • acceleration: values are in meter per second per second (m/s^2)
  • magnetic: values are in micro-Tesla (uT)
  • orientation: values are in degrees
  • gyro: values are in rad/s
  • temperature: values in degrees centigrade (Celsius)
  • distance: values are in centimeters
  • light: values are in SI lux units
  • pressure: values are in hectopascal (hPa)
  • relative_humidity: values are in percent
  • current: values are in milliamps (mA)
  • voltage: values are in volts (V)
  • color: values are in 0..1.0 RGB channel luminosity and 32-bit RGBA format
  • tvoc: values are in parts per billion (ppb)
  • voc_index: values are an index from 1-500 with 100 being normal
  • nox_index: values are an index from 1-500 with 100 being normal
  • CO2: values are in parts per million (ppm)
  • eCO2: values are in parts per million (ppm)
  • pm10_std: values are in parts per million (ppm)
  • pm25_std: values are in parts per million (ppm)
  • pm100_std: values are in parts per million (ppm)
  • pm10_env: values are in parts per million (ppm)
  • pm25_env: values are in parts per million (ppm)
  • pm100_env: values are in parts per million (ppm)
  • gas_resistance: values are in ohms
  • unitless_percent: values are in %
  • altitude: values are in meters (m)

The Unified Driver Abstraction Layer in Practice

Using the unified sensor abstraction layer is relatively easy once a compliant driver has been created.

Every compliant sensor can now be read using a single, well-known 'type' (sensors_event_t), and there is a standardized way of interrogating a sensor about its specific capabilities (via sensor_t).

An example of reading the TSL2561 light sensor can be seen below:

 Adafruit_TSL2561 tsl = Adafruit_TSL2561(TSL2561_ADDR_FLOAT, 12345);
 ...
 /* Get a new sensor event */ 
 sensors_event_t event;
 tsl.getEvent(&event);
 
 /* Display the results (light is measured in lux) */
 if (event.light)
 {
   Serial.print(event.light); Serial.println(" lux");
 }
 else
 {
   /* If event.light = 0 lux the sensor is probably saturated
      and no reliable data could be generated! */
   Serial.println("Sensor overload");
 }

Similarly, we can get the basic technical capabilities of this sensor with the following code:

 sensor_t sensor;
 
 sensor_t sensor;
 tsl.getSensor(&sensor);

 /* Display the sensor details */
 Serial.println("------------------------------------");
 Serial.print  ("Sensor:       "); Serial.println(sensor.name);
 Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
 Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
 Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");
 Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");
 Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux");  
 Serial.println("------------------------------------");
 Serial.println("");

adafruit_sensor's People

Contributors

brentru avatar donck avatar evaherrada avatar georgeharker avatar happyfacade avatar hathach avatar ladyada avatar madhephaestus avatar malachib avatar maribu avatar microbuilder avatar mrjimenez avatar nikai3d avatar patridge avatar phildubach avatar stappon avatar tdicola avatar toddtreece avatar tyeth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_sensor's Issues

power/energy meter

Hi, I was wondering how to implement the interface toward a power/energy meter that gives me reading in W/Wh respectively. Thanks

sensors_type_t has no power/energy constant. I wonder if it's "by design" or it's only a matter of defining a new enum value

Adafruit_Sensor.h:75:5: error: 'int8_t' does not name a type

Hello
i'm beginer in arduino and don't know how to fix this error
thanx

Arduino: 1.6.7 Hourly Build 2015/11/04 11:34 (Windows 7), Board: "Arduino/Genuino Uno"

In file included from C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.cpp:1:0:

C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.h:75:5: error: 'int8_t' does not name a type

     int8_t status;

     ^

C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.h:76:5: error: 'uint8_t' does not name a type

     uint8_t reserved[3];

     ^

C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.h:90:5: error: 'uint32_t' does not name a type

     uint32_t rgba;         /**< 24-bit RGBA value */

     ^

C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.h:97:5: error: 'int32_t' does not name a type

     int32_t version;                          /**< must be sizeof(struct sensors_event_t) */

     ^

C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.h:98:5: error: 'int32_t' does not name a type

     int32_t sensor_id;                        /**< unique sensor identifier */

     ^

C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.h:99:5: error: 'int32_t' does not name a type

     int32_t type;                             /**< sensor type */

     ^

C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.h:100:5: error: 'int32_t' does not name a type

     int32_t reserved0;                        /**< reserved */

     ^

C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.h:101:5: error: 'int32_t' does not name a type

     int32_t timestamp;                        /**< time is in milliseconds */

     ^

C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.h:125:5: error: 'int32_t' does not name a type

     int32_t  version;                         /**< version of the hardware + driver */

     ^

C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.h:126:5: error: 'int32_t' does not name a type

     int32_t  sensor_id;                       /**< unique sensor identifier */

     ^

C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.h:127:5: error: 'int32_t' does not name a type

     int32_t  type;                            /**< this sensor's type (ex. SENSOR_TYPE_LIGHT) */

     ^

C:\Users\hdp-1\Documents\Arduino\libraries\Adafruit_Sensor-master\Adafruit_Sensor.h:131:5: error: 'int32_t' does not name a type

     int32_t  min_delay;                       /**< min delay in microseconds between events. zero = not a constant rate */

     ^

exit status 1
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

Will not compile on the ESP Huzzah

This is likely because it requires avr/pgmspace.h, which won't exist on a non-AVR.

I am wanting to get the BNO055 to be read on this device, so I may tinker a bit.

License?

The repository doesn't have a LICENSE or COPYING file, which license is the library distributed under?

If it's up for a vote, I'd suggest MIT or some other permissive license.

Adafruit_ADXL343.h: No such file or directory

Arduino: 1.8.9 (Mac OS X), Board: "Arduino Ethernet"

Multiple libraries were found for "Adafruit_Sensor.h"
Used: /Users/imac/Documents/Arduino/libraries/Adafruit_Sensor
Not used: /Users/imac/Documents/Arduino/libraries/Adafruit_Unified_Sensor
sensortest:3:30: error: Adafruit_ADXL343.h: No such file or directory
compilation terminated.
exit status 1
Adafruit_ADXL343.h: No such file or directory

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Provide distinction in terms of BNO055

Hi I just spent half a day pondering upon the fact that BNO055 can be used along with this library only to obtain orientation and not the accelerometer values.

I was aiming to use the event method to use event.orientation for Roll, Pitch, Yaw and event.acceleration to obtain linear accerleration in X, Y, Z directions but if I use the code I get the same values for event.acceleration and event.orientation

SE Query supporting this Issue created by Me

Looking for some discussion on the same.

Ver 6.3.3 Sensor ASAIR 2302

Three months ago I am operating 5 mushroom growing houses without any problem. Each room has 5 ASAIR 2302 sensors. Everything worked fine on a Raspberry PI3 B +
Two days ago I switched to version 6.3.3 and the sensors no longer work.
What should I do?
Thank you

sensor_t typename clash

typedef struct {
char name[12]; /**< sensor name */
int32_t version; /**< version of the hardware + driver */
int32_t sensor_id; /**< unique sensor identifier */
int32_t type; /**< this sensor's type (ex. SENSOR_TYPE_LIGHT) */
float max_value; /**< maximum value of this sensor's value in SI units */
float min_value; /**< minimum value of this sensor's value in SI units */
float resolution; /**< smallest difference between two values reported by this
sensor */
int32_t min_delay; /**< min delay in microseconds between events. zero = not a
constant rate */
} sensor_t;

with its very generic sensor_t typename directly clashes with

https://github.com/espressif/arduino-esp32/blob/5f6d093d4a8a371c78acd6e1a0e7a95b7346cbec/tools/sdk/esp32/include/esp32-camera/driver/include/esp_camera.h#L193

A type used in the esp_camera system, aka a camera sensor. Using both these libraries in the same code file is not possible (but in split files it is).

Not sure if that should be fixed since changing the name breaks compatibility, but at least FYI for other people running into this error during development, as they did in our forum.

compilation error

Arduino: 1.8.7 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Enabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

In file included from C:\Users\shalinee mishra\Documents\Arduino\libraries\Adafruit_IO_Arduino\src/wifi/AdafruitIO_ESP8266.h:18:0,

             from C:\Users\shalinee mishra\Documents\Arduino\libraries\Adafruit_IO_Arduino\src/AdafruitIO_WiFi.h:32,

             from C:\Users\SHALIN~1\AppData\Local\Temp\arduino_modified_sketch_178491\adafruitio_15_temp_humidity.ino:26:

C:\Users\shalinee mishra\Documents\Arduino\libraries\Adafruit_IO_Arduino\src/AdafruitIO.h:23:31: fatal error: ArduinoHttpClient.h: No such file or directory

#include "ArduinoHttpClient.h"

                           ^

compilation terminated.

exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

avr\pgmspace.h Compilation Error

I am unable to compile, as it is looking for that file. Does it expect the file to be in the library, or as part of a base path?

I am using the esptool programmer, and targeting the generic esp8266 board.

Resolution or Accuracy

There is a mixup of using sensor Resolution vs. Accuracy.

The AHT10 sensor reports the following:

Adafruit AHT10 test!
AHT10 Found!
------------------------------------
Sensor:       AHT10_T
Type:         Ambient Temp (C)
Driver Ver:   1
Unique ID:    257
Min Value:    -40.00
Max Value:    85.00
Resolution:   0.30
------------------------------------

------------------------------------
Sensor:       AHT10_H
Type:         Relative Humidity (%)
Driver Ver:   1
Unique ID:    256
Min Value:    0.00
Max Value:    100.00
Resolution:   2.00
------------------------------------

The AHT10 temperature resolution is 0.01C but its overall accuracy is +/- 0.30 C.
The same goes for RH.

What is expected of sensor to enter as "resolution" parameter?
I gather that is not made clear, and causes this mixup.

(i'll enter also ticket in AHT1x library about this; these Adafruit libraries should agree on how to use this)

make: don't know how to make Adafruit_Sensor.o

Hello,

I'm trying to play with samples scripts and meet troubles while compilation.
My env : OS: OpenBSD 6.1 with arduino package.
My Board is a Arduino MEGA 2560.
The sample script is the one available with Adafruit_FXAS21002C driver.
The make stop with this message :
make: don't know how to make Adafruit_Sensor.o (prerequisite of: applet/core.a)

I tried other libs like Servo without issues.

Note : I'm note using Arduino IDE (not available)

Thank's for your help

Bruno.

Dependency on ADXL345 is excessive

I've noticed that this library depends on Adafruit ADXL343, which also pulls in Adafruit BusIO.
This seems rather excessive just for an example.

As a suggestion, maybe a smaller dependency could be used instead?

Add support for particles...

There is a PM2.5 sensor as part of wippersnapper, and wippersnapper have listed the following relevant supported sensor types (although the _env variants seem unimplemented):
"pm10-std"
"pm25-std"
"pm100-std"
"pm10-env"
"pm25-env"
"pm100-env"

I plan to add the Sensirion SEN55, which has particle sensing at 0.5, 1, 2.5, 4, and 10 (micron?) in particles per cm3, and for all except <0.5um there are readings in ug/m3 (SI unit?), along with Temp(c)/Humidity(%RH), a Voc index and Nox index both without units. I assume the nox and voc are irrelevant as the device doesn't offer units but an "index".

The wippersnapper adding a sensor guide says to file an issue here for unsupported sensor types.
https://learn.adafruit.com/how-to-add-a-new-component-to-adafruit-io-wippersnapper/adding-an-i2c-component-driver#:~:text=NOTE%20%2D%20If%20you%27re%20adding%20a%20sensor%20that%20does%20not%20yet%20have%20a%20predefined%20sensor_type%2C%20please%20add%20a%20new%20issue%20to%20Adafruit_Sensor.

I guess I'm filing an issue to get support for count(#)/cm3 as that seems to be the preferred SI unit. I do commonly see a converted ug/m3 so anyone's input here would be good. I'd love support for the pm05 pm10 pm25 pm40 and pm100 too.

Normalized way for multiple sensor magnitudes

Hi! This library is very nice! But an event can't contain multiple values (because it is an union) neither the interface offers a way to provide them. I was checking some libraries for sensors to see how do you deal with that and I saw the following:
In DHT you handle this doing dht.temperature().getSensor(&sensor);
And in BMP183 you get the event and then bmp.getTemperature();

As you can see you handle this by two different ways and I think that a normalized way to do this would be great. I am doing a library that needs sensors as much generic as possible and at this moment I can't use sensors as "generic" sensor when the sensor provides multiple values.

Thank you!

Add support for load cell / weight sensors

Currently, there is no support for Load cell or weight sensors in the Sensor type and standardized SI values. Is there a plan to add support or open to contributing to add support?

I am looking to add support for NAU7802 to wippersnapper

warning: unused parameter 'enabled'

Hi,

I have encountered this warning while using your library in the context of an ADXL345 sensor.

The problem could be solved in two different ways, depending on what you really want with the code.

The warning is the following:

/sketchbook/arduino/libraries/Adafruit_Unified_Sensor/Adafruit_Sensor.h:146:37: warning: unused parameter 'enabled' [-Wunused-parameter]
virtual void enableAutoRange(bool enabled) {};

The relevant code is the following:

// These must be defined by the subclass
virtual void enableAutoRange(bool enabled) {};
virtual bool getEvent(sensors_event_t*) = 0;
virtual void getSensor(sensor_t*) = 0;

The comment above the statement causing the warning implies that maybe the enableAutoRange method should be pure virtual as the other two methods below it. But that breaks the code in the sensor, because this method is not implemented there.

An easy way to avoid the warning in the case that the code should stay like this is to change the line to

virtual void enableAutoRange(bool) {}

I can do a pull request for that if this is the case. The other option has a lot of breaking potential, but could in fact be the most correct one.

Regards,
Marcelo.

Questions and Improvements?

Hello!

I love the idea of this type of abstraction library and it looks like it has a lot of great things going for it. I'm a little confused at the moment about certain things.

  1. Why the finite list of sensors types?
    Can't we just store sensors in an array and provide some compiler definitions to get to friendly named ones?
    For example:

define LIGHT sensor[0]

And to event.LIGHT() would call it instead

The reason is, what if I have sensors that aren't on this list? What if I have multiples of one sensor? Sure I could easily modify this library to accommodate that but shouldn't an abstraction library not need to be updated per application?

I am sure this has a large part to do with the SIs but that seems more like something that needs to be a convention for people writing the drivers. It can't really be enforced by explicitly naming the sensors.

  1. Can we have a single location with sensor_ids and what sensor has taken it?
    If I am about to create a driver for a new sensor, I want to make sure the sensor_id is not taken! We could just keep track of this in the README perhaps...

Anyway, I'm really glad there's some people thinking about this. Maybe my desires for a library are a little different then what this library intends on having here.

Another thing I am interested in is decoupling getEvent() into: startEvent(), getEventRaw() and getEvent(). This would be useful so that a microcontroller could launch many sensor conversion in a series without waiting to hear back from them. Data could be transmitted in raw form offloading the parsing to SI to another system. getEvent() could still be there for those who just want the parsed form as soon as it can be available.

Issue with Unified sensor library or Adafruit BNO055

Hi,

The Adafruit BNO055 seems to have some issues with the Adafruit unified sensor library. The sensors_event_t returned seems to contain incorrect components. The acceleration, and gyro components both return the orientation data. Here is a stack exchange question that details this more.
https://arduino.stackexchange.com/questions/56937/get-accelerometer-values-from-bno055-using-adafruits-unified-sensor-library?newreg=c6a3bcfaa15e48438c38521da1a330b5

I'm not exactly sure where to put this information but I'll leave it here as well as some other places.

Here is the code that yields this problem:
#include <math.h>

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>

Adafruit_BNO055 bno = Adafruit_BNO055(55);

void setup(void)
{
Serial.begin(9600);
Serial.println("Orientation Sensor Test"); Serial.println("");

/* Initialise the sensor */

if(!bno.begin())
{
/* There was a problem detecting the BNO055 ... check your connections */
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while(1);
}

delay(1000);

bno.setExtCrystalUse(true);
}

void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
bno.getEvent(&event);

/* Display the floating point data */
Serial.print("RPY X: ");
Serial.print(event.orientation.x, 4);
Serial.print("\tY: ");
Serial.print(event.orientation.y, 4);
Serial.print("\tZ: ");
Serial.print(event.orientation.z, 4);
Serial.println("");

Serial.print("Gyro X: ");
Serial.print(event.gyro.x, 4);
Serial.print("\tY: ");
Serial.print(event.gyro.y, 4);
Serial.print("\tZ: ");
Serial.print(event.gyro.z, 4);
Serial.println("");

Serial.print("Acceleration X: ");
Serial.print(event.acceleration.x, 4);
Serial.print("\tY: ");
Serial.print(event.acceleration.y, 4);
Serial.print("\tZ: ");
Serial.print(event.acceleration.z, 4);
Serial.println("");

delay(100);
}

Thanks for your time!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.