Adafruit_SGP30.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*!
  2. * @file Adafruit_SGP30.h
  3. *
  4. * This is the documentation for Adafruit's SGP30 driver for the
  5. * Arduino platform. It is designed specifically to work with the
  6. * Adafruit SGP30 breakout: http://www.adafruit.com/products/3709
  7. *
  8. * These sensors use I2C to communicate, 2 pins (SCL+SDA) are required
  9. * to interface with the breakout.
  10. *
  11. * Adafruit invests time and resources providing this open source code,
  12. * please support Adafruit and open-source hardware by purchasing
  13. * products from Adafruit!
  14. *
  15. * Written by Ladyada for Adafruit Industries.
  16. *
  17. * BSD license, all text here must be included in any redistribution.
  18. *
  19. */
  20. #include "Arduino.h"
  21. #include <Wire.h>
  22. // the i2c address
  23. #define SGP30_I2CADDR_DEFAULT 0x58 ///< SGP30 has only one I2C address
  24. // commands and constants
  25. #define SGP30_FEATURESET 0x0020 ///< The required set for this library
  26. #define SGP30_CRC8_POLYNOMIAL 0x31 ///< Seed for SGP30's CRC polynomial
  27. #define SGP30_CRC8_INIT 0xFF ///< Init value for CRC
  28. #define SGP30_WORD_LEN 2 ///< 2 bytes per word
  29. /**************************************************************************/
  30. /*! Class that stores state and functions for interacting with SGP30 Gas Sensor */
  31. /**************************************************************************/
  32. class Adafruit_SGP30 {
  33. public:
  34. Adafruit_SGP30();
  35. boolean begin(TwoWire *theWire = NULL);
  36. boolean IAQinit(void);
  37. boolean IAQmeasure(void);
  38. boolean getIAQBaseline(uint16_t *eco2_base, uint16_t *tvoc_base);
  39. boolean setIAQBaseline(uint16_t eco2_base, uint16_t tvoc_base);
  40. /**
  41. * The last measurement of the IAQ-calculated Total Volatile Organic Compounds in ppb. This value is set when you call {@link IAQmeasure()}
  42. */
  43. uint16_t TVOC;
  44. /**
  45. * The last measurement of the IAQ-calculated equivalent CO2 in ppm. This value is set when you call {@link IAQmeasure()}
  46. */
  47. uint16_t eCO2;
  48. /**
  49. * The 48-bit serial number, this value is set when you call {@link begin()}
  50. */
  51. uint16_t serialnumber[3];
  52. private:
  53. TwoWire *_i2c;
  54. uint8_t _i2caddr;
  55. void write(uint8_t address, uint8_t *data, uint8_t n);
  56. void read(uint8_t address, uint8_t *data, uint8_t n);
  57. boolean readWordFromCommand(uint8_t command[], uint8_t commandLength, uint16_t delay, uint16_t *readdata = NULL, uint8_t readlen = 0);
  58. uint8_t generateCRC(uint8_t data[], uint8_t datalen);
  59. };