http://daten.andreas-grabner.net:3000/i4a/IAQ2000DHT11.git Conflicts: .projectmaster
@@ -34,12 +34,12 @@ | |||
<link> | |||
<name>I2Cdev</name> | |||
<type>2</type> | |||
<location>C:/Users/agr/Nextcloud3/Fileserver/inet4all/Projekte/SmartFarm/Libraries/I2Cdev</location> | |||
<locationURI>PROJECT_LOC/I2Cdev</locationURI> | |||
</link> | |||
<link> | |||
<name>IAQ2000</name> | |||
<type>2</type> | |||
<location>C:/Users/agr/Nextcloud3/Fileserver/inet4all/Projekte/SmartFarm/Libraries/IAQ2000</location> | |||
<locationURI>PROJECT_LOC/IAQ2000</locationURI> | |||
</link> | |||
<link> | |||
<name>core/core</name> | |||
@@ -51,11 +51,6 @@ | |||
<type>2</type> | |||
<locationURI>ECLIPSE_HOME/arduinoPlugin/packages/arduino/hardware/avr/1.8.2/variants/eightanaloginputs</locationURI> | |||
</link> | |||
<link> | |||
<name>libraries/Adafruit_Sensor_Lab</name> | |||
<type>2</type> | |||
<locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/Adafruit_Sensor_Lab/0.4.0</locationURI> | |||
</link> | |||
<link> | |||
<name>libraries/Adafruit_Unified_Sensor</name> | |||
<type>2</type> | |||
@@ -4,7 +4,7 @@ | |||
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider"> | |||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> | |||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> | |||
<provider class="io.sloeber.core.toolchain.ArduinoLanguageProvider" console="false" env-hash="950558152315445550" id="io.sloeber.languageSettingsProvider" keep-relative-paths="false" name="Arduino Compiler Settings" parameter="${COMMAND} -E -P -v -dD -D__IN_ECLIPSE__ "${INPUTS}"" prefer-non-shared="true"> | |||
<provider class="io.sloeber.core.toolchain.ArduinoLanguageProvider" console="false" env-hash="1043980802443853318" id="io.sloeber.languageSettingsProvider" keep-relative-paths="false" name="Arduino Compiler Settings" parameter="${COMMAND} -E -P -v -dD -D__IN_ECLIPSE__ "${INPUTS}"" prefer-non-shared="true"> | |||
<language-scope id="org.eclipse.cdt.core.gcc"/> | |||
<language-scope id="org.eclipse.cdt.core.g++"/> | |||
</provider> | |||
@@ -0,0 +1 @@ | |||
/I2Cdev.cpp |
@@ -0,0 +1,289 @@ | |||
// I2Cdev library collection - Main I2C device class header file | |||
// Abstracts bit and byte I2C R/W functions into a convenient class | |||
// 2013-06-05 by Jeff Rowberg <jeff@rowberg.net> | |||
// | |||
// Changelog: | |||
// 2020-01-20 - hardija : complete support for Teensy 3.x | |||
// 2015-10-30 - simondlevy : support i2c_t3 for Teensy3.1 | |||
// 2013-05-06 - add Francesco Ferrara's Fastwire v0.24 implementation with small modifications | |||
// 2013-05-05 - fix issue with writing bit values to words (Sasquatch/Farzanegan) | |||
// 2012-06-09 - fix major issue with reading > 32 bytes at a time with Arduino Wire | |||
// - add compiler warnings when using outdated or IDE or limited I2Cdev implementation | |||
// 2011-11-01 - fix write*Bits mask calculation (thanks sasquatch @ Arduino forums) | |||
// 2011-10-03 - added automatic Arduino version detection for ease of use | |||
// 2011-10-02 - added Gene Knight's NBWire TwoWire class implementation with small modifications | |||
// 2011-08-31 - added support for Arduino 1.0 Wire library (methods are different from 0.x) | |||
// 2011-08-03 - added optional timeout parameter to read* methods to easily change from default | |||
// 2011-08-02 - added support for 16-bit registers | |||
// - fixed incorrect Doxygen comments on some methods | |||
// - added timeout value for read operations (thanks mem @ Arduino forums) | |||
// 2011-07-30 - changed read/write function structures to return success or byte counts | |||
// - made all methods static for multi-device memory savings | |||
// 2011-07-28 - initial release | |||
/* ============================================ | |||
I2Cdev device library code is placed under the MIT license | |||
Copyright (c) 2013 Jeff Rowberg | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. | |||
=============================================== | |||
*/ | |||
#ifndef _I2CDEV_H_ | |||
#define _I2CDEV_H_ | |||
// ----------------------------------------------------------------------------- | |||
// I2C interface implementation setting | |||
// ----------------------------------------------------------------------------- | |||
#ifndef I2CDEV_IMPLEMENTATION | |||
#define I2CDEV_IMPLEMENTATION I2CDEV_ARDUINO_WIRE | |||
//#define I2CDEV_IMPLEMENTATION I2CDEV_TEENSY_3X_WIRE | |||
//#define I2CDEV_IMPLEMENTATION I2CDEV_BUILTIN_SBWIRE | |||
//#define I2CDEV_IMPLEMENTATION I2CDEV_BUILTIN_FASTWIRE | |||
#endif // I2CDEV_IMPLEMENTATION | |||
// comment this out if you are using a non-optimal IDE/implementation setting | |||
// but want the compiler to shut up about it | |||
#define I2CDEV_IMPLEMENTATION_WARNINGS | |||
// ----------------------------------------------------------------------------- | |||
// I2C interface implementation options | |||
// ----------------------------------------------------------------------------- | |||
#define I2CDEV_ARDUINO_WIRE 1 // Wire object from Arduino | |||
#define I2CDEV_BUILTIN_NBWIRE 2 // Tweaked Wire object from Gene Knight's NBWire project | |||
// ^^^ NBWire implementation is still buggy w/some interrupts! | |||
#define I2CDEV_BUILTIN_FASTWIRE 3 // FastWire object from Francesco Ferrara's project | |||
#define I2CDEV_I2CMASTER_LIBRARY 4 // I2C object from DSSCircuits I2C-Master Library at https://github.com/DSSCircuits/I2C-Master-Library | |||
#define I2CDEV_BUILTIN_SBWIRE 5 // I2C object from Shuning (Steve) Bian's SBWire Library at https://github.com/freespace/SBWire | |||
#define I2CDEV_TEENSY_3X_WIRE 6 // Teensy 3.x support using i2c_t3 library | |||
// ----------------------------------------------------------------------------- | |||
// Arduino-style "Serial.print" debug constant (uncomment to enable) | |||
// ----------------------------------------------------------------------------- | |||
//#define I2CDEV_SERIAL_DEBUG | |||
#ifdef ARDUINO | |||
#if ARDUINO < 100 | |||
#include "WProgram.h" | |||
#else | |||
#include "Arduino.h" | |||
#endif | |||
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE | |||
#include <Wire.h> | |||
#endif | |||
#if I2CDEV_IMPLEMENTATION == I2CDEV_TEENSY_3X_WIRE | |||
#include <i2c_t3.h> | |||
#endif | |||
#if I2CDEV_IMPLEMENTATION == I2CDEV_I2CMASTER_LIBRARY | |||
#include <I2C.h> | |||
#endif | |||
#if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_SBWIRE | |||
#include "SBWire.h" | |||
#endif | |||
#endif | |||
#ifdef SPARK | |||
#include <spark_wiring_i2c.h> | |||
#define ARDUINO 101 | |||
#endif | |||
// 1000ms default read timeout (modify with "I2Cdev::readTimeout = [ms];") | |||
#define I2CDEV_DEFAULT_READ_TIMEOUT 1000 | |||
class I2Cdev { | |||
public: | |||
I2Cdev(); | |||
static int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout); | |||
static int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout); | |||
static int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout); | |||
static int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout); | |||
static int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout); | |||
static int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout); | |||
static int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout); | |||
static int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout); | |||
static bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data); | |||
static bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data); | |||
static bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data); | |||
static bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data); | |||
static bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data); | |||
static bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data); | |||
static bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data); | |||
static bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data); | |||
static uint16_t readTimeout; | |||
}; | |||
#if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE | |||
////////////////////// | |||
// FastWire 0.24 | |||
// This is a library to help faster programs to read I2C devices. | |||
// Copyright(C) 2012 | |||
// Francesco Ferrara | |||
////////////////////// | |||
/* Master */ | |||
#define TW_START 0x08 | |||
#define TW_REP_START 0x10 | |||
/* Master Transmitter */ | |||
#define TW_MT_SLA_ACK 0x18 | |||
#define TW_MT_SLA_NACK 0x20 | |||
#define TW_MT_DATA_ACK 0x28 | |||
#define TW_MT_DATA_NACK 0x30 | |||
#define TW_MT_ARB_LOST 0x38 | |||
/* Master Receiver */ | |||
#define TW_MR_ARB_LOST 0x38 | |||
#define TW_MR_SLA_ACK 0x40 | |||
#define TW_MR_SLA_NACK 0x48 | |||
#define TW_MR_DATA_ACK 0x50 | |||
#define TW_MR_DATA_NACK 0x58 | |||
#define TW_OK 0 | |||
#define TW_ERROR 1 | |||
class Fastwire { | |||
private: | |||
static boolean waitInt(); | |||
public: | |||
static void setup(int khz, boolean pullup); | |||
static byte beginTransmission(byte device); | |||
static byte write(byte value); | |||
static byte writeBuf(byte device, byte address, byte *data, byte num); | |||
static byte readBuf(byte device, byte address, byte *data, byte num); | |||
static void reset(); | |||
static byte stop(); | |||
}; | |||
#endif | |||
#if I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE | |||
// NBWire implementation based heavily on code by Gene Knight <Gene@Telobot.com> | |||
// Originally posted on the Arduino forum at http://arduino.cc/forum/index.php/topic,70705.0.html | |||
// Originally offered to the i2cdevlib project at http://arduino.cc/forum/index.php/topic,68210.30.html | |||
#define NBWIRE_BUFFER_LENGTH 32 | |||
class TwoWire { | |||
private: | |||
static uint8_t rxBuffer[]; | |||
static uint8_t rxBufferIndex; | |||
static uint8_t rxBufferLength; | |||
static uint8_t txAddress; | |||
static uint8_t txBuffer[]; | |||
static uint8_t txBufferIndex; | |||
static uint8_t txBufferLength; | |||
// static uint8_t transmitting; | |||
static void (*user_onRequest)(void); | |||
static void (*user_onReceive)(int); | |||
static void onRequestService(void); | |||
static void onReceiveService(uint8_t*, int); | |||
public: | |||
TwoWire(); | |||
void begin(); | |||
void begin(uint8_t); | |||
void begin(int); | |||
void beginTransmission(uint8_t); | |||
//void beginTransmission(int); | |||
uint8_t endTransmission(uint16_t timeout=0); | |||
void nbendTransmission(void (*function)(int)) ; | |||
uint8_t requestFrom(uint8_t, int, uint16_t timeout=0); | |||
//uint8_t requestFrom(int, int); | |||
void nbrequestFrom(uint8_t, int, void (*function)(int)); | |||
void send(uint8_t); | |||
void send(uint8_t*, uint8_t); | |||
//void send(int); | |||
void send(char*); | |||
uint8_t available(void); | |||
uint8_t receive(void); | |||
void onReceive(void (*)(int)); | |||
void onRequest(void (*)(void)); | |||
}; | |||
#define TWI_READY 0 | |||
#define TWI_MRX 1 | |||
#define TWI_MTX 2 | |||
#define TWI_SRX 3 | |||
#define TWI_STX 4 | |||
#define TW_WRITE 0 | |||
#define TW_READ 1 | |||
#define TW_MT_SLA_NACK 0x20 | |||
#define TW_MT_DATA_NACK 0x30 | |||
#define CPU_FREQ 16000000L | |||
#define TWI_FREQ 100000L | |||
#define TWI_BUFFER_LENGTH 32 | |||
/* TWI Status is in TWSR, in the top 5 bits: TWS7 - TWS3 */ | |||
#define TW_STATUS_MASK (_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|_BV(TWS3)) | |||
#define TW_STATUS (TWSR & TW_STATUS_MASK) | |||
#define TW_START 0x08 | |||
#define TW_REP_START 0x10 | |||
#define TW_MT_SLA_ACK 0x18 | |||
#define TW_MT_SLA_NACK 0x20 | |||
#define TW_MT_DATA_ACK 0x28 | |||
#define TW_MT_DATA_NACK 0x30 | |||
#define TW_MT_ARB_LOST 0x38 | |||
#define TW_MR_ARB_LOST 0x38 | |||
#define TW_MR_SLA_ACK 0x40 | |||
#define TW_MR_SLA_NACK 0x48 | |||
#define TW_MR_DATA_ACK 0x50 | |||
#define TW_MR_DATA_NACK 0x58 | |||
#define TW_ST_SLA_ACK 0xA8 | |||
#define TW_ST_ARB_LOST_SLA_ACK 0xB0 | |||
#define TW_ST_DATA_ACK 0xB8 | |||
#define TW_ST_DATA_NACK 0xC0 | |||
#define TW_ST_LAST_DATA 0xC8 | |||
#define TW_SR_SLA_ACK 0x60 | |||
#define TW_SR_ARB_LOST_SLA_ACK 0x68 | |||
#define TW_SR_GCALL_ACK 0x70 | |||
#define TW_SR_ARB_LOST_GCALL_ACK 0x78 | |||
#define TW_SR_DATA_ACK 0x80 | |||
#define TW_SR_DATA_NACK 0x88 | |||
#define TW_SR_GCALL_DATA_ACK 0x90 | |||
#define TW_SR_GCALL_DATA_NACK 0x98 | |||
#define TW_SR_STOP 0xA0 | |||
#define TW_NO_INFO 0xF8 | |||
#define TW_BUS_ERROR 0x00 | |||
//#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr)) | |||
//#define _SFR_BYTE(sfr) _MMIO_BYTE(_SFR_ADDR(sfr)) | |||
#ifndef sbi // set bit | |||
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) | |||
#endif // sbi | |||
#ifndef cbi // clear bit | |||
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) | |||
#endif // cbi | |||
extern TwoWire Wire; | |||
#endif // I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE | |||
#endif /* _I2CDEV_H_ */ |
@@ -0,0 +1,38 @@ | |||
####################################### | |||
# Syntax Coloring Map For I2Cdev | |||
####################################### | |||
####################################### | |||
# Datatypes (KEYWORD1) | |||
####################################### | |||
I2Cdev KEYWORD1 | |||
####################################### | |||
# Methods and Functions (KEYWORD2) | |||
####################################### | |||
readBit KEYWORD2 | |||
readBitW KEYWORD2 | |||
readBits KEYWORD2 | |||
readBitsW KEYWORD2 | |||
readByte KEYWORD2 | |||
readBytes KEYWORD2 | |||
readWord KEYWORD2 | |||
readWords KEYWORD2 | |||
writeBit KEYWORD2 | |||
writeBitW KEYWORD2 | |||
writeBits KEYWORD2 | |||
writeBitsW KEYWORD2 | |||
writeByte KEYWORD2 | |||
writeBytes KEYWORD2 | |||
writeWord KEYWORD2 | |||
writeWords KEYWORD2 | |||
####################################### | |||
# Instances (KEYWORD2) | |||
####################################### | |||
####################################### | |||
# Constants (LITERAL1) | |||
####################################### | |||
@@ -0,0 +1,18 @@ | |||
{ | |||
"name": "I2Cdevlib-Core", | |||
"keywords": "i2cdevlib, i2c", | |||
"description": "The I2C Device Library (I2Cdevlib) is a collection of uniform and well-documented classes to provide simple and intuitive interfaces to I2C devices.", | |||
"include": "Arduino/I2Cdev", | |||
"repository": | |||
{ | |||
"type": "git", | |||
"url": "https://github.com/jrowberg/i2cdevlib.git" | |||
}, | |||
"frameworks": "arduino", | |||
"platforms": "atmelavr", | |||
"dependencies": [ | |||
{ | |||
"name": "Wire" | |||
} | |||
] | |||
} |
@@ -0,0 +1,141 @@ | |||
// I2Cdev library collection - iAQ-2000 I2C device class | |||
// Based on AppliedSensor iAQ-2000 Interface Description, Version PA1, 2009 | |||
// 2012-04-01 by Peteris Skorovs <pskorovs@gmail.com> | |||
// | |||
// This I2C device library is using (and submitted as a part of) Jeff Rowberg's I2Cdevlib library, | |||
// which should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib | |||
// | |||
// Changelog: | |||
// 2012-04-01 - initial release | |||
// 2012-11-08 - added TVoc and Status | |||
/* ============================================ | |||
I2Cdev device library code is placed under the MIT license | |||
Copyright (c) 2012 Peteris Skorovs, Jeff Rowberg | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. | |||
=============================================== | |||
*/ | |||
#include "IAQ2000.h" | |||
/** Default constructor, uses default I2C address. | |||
* @see IAQ2000_DEFAULT_ADDRESS | |||
*/ | |||
IAQ2000::IAQ2000() { | |||
devAddr = IAQ2000_DEFAULT_ADDRESS; | |||
} | |||
/** Specific address constructor. | |||
* @param address I2C address | |||
* @see IAQ2000_DEFAULT_ADDRESS | |||
* @see IAQ2000_ADDRESS | |||
*/ | |||
IAQ2000::IAQ2000(uint8_t address) { | |||
devAddr = address; | |||
} | |||
/** Power on and prepare for general usage. | |||
*/ | |||
void IAQ2000::initialize() { | |||
// Nothing is required, but | |||
// the method should exist anyway. | |||
} | |||
/** Very primitive method o verify the I2C connection. | |||
* Make sure the device is connected and responds as expected. | |||
* @return True if connection is valid, false otherwise | |||
*/ | |||
bool IAQ2000::testConnection() { | |||
if (getIaqpred() >= 450) { | |||
return true; | |||
} | |||
else { | |||
return false; | |||
} | |||
} | |||
/** Read iAQ-2000 indoor air quality sensor. | |||
* @return Predicted CO2 concentration based on human induced volatile organic compounds (VOC) detection (in ppm VOC + CO2 equivalents) | |||
*/ | |||
uint16_t IAQ2000::getIaqpred() { | |||
// read bytes from the DATA0 AND DATA1 registers and bit-shifting them into a 16-bit value | |||
readAllBytes(devAddr, 2, buffer); | |||
return ((buffer[0] << 8) | buffer[1]); | |||
} | |||
uint8_t IAQ2000::getIaqstatus() { | |||
// read bytes from the DATA2 register | |||
readAllBytes(devAddr, 3, buffer); | |||
return (buffer[2]); | |||
} | |||
uint16_t IAQ2000::getIaqtvoc() { | |||
// read bytes from the DATA7 AND DATA8 registers and bit-shifting them into a 16-bit value | |||
readAllBytes(devAddr, 9, buffer); | |||
return ((buffer[7] << 8) | buffer[8]); | |||
} | |||
/** Read bytes from a slave device. | |||
* This is a "stripped-down" version of the standard Jeff Rowberg's I2Cdev::readBytes method | |||
* intended to provide compatibility with iAQ-2000, | |||
* which apparently does not support setting of an address pointer to indicate from which position is to start read from. | |||
* @param devAddr Address of the slave device to read bytes from | |||
* @param length Number of bytes to read | |||
* @param data Buffer to store read data in | |||
* @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) | |||
* @return Number of bytes read (0 indicates failure) | |||
*/ | |||
int8_t IAQ2000::readAllBytes(uint8_t devAddr, uint8_t length, uint8_t *data, uint16_t timeout) { | |||
#ifdef I2CDEV_SERIAL_DEBUG | |||
Serial.print("I2C (0x"); | |||
Serial.print(devAddr, HEX); | |||
Serial.print(") reading "); | |||
Serial.print(length, DEC); | |||
Serial.print(" bytes..."); | |||
#endif | |||
int8_t count = 0; | |||
Wire.requestFrom(devAddr, length); | |||
uint32_t t1 = millis(); | |||
for (; Wire.available() && (timeout == 0 || millis() - t1 < timeout); count++) { | |||
#if ((I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO < 100) || I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE) | |||
data[count] = Wire.receive(); | |||
#elif (I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE && ARDUINO >= 100) | |||
data[count] = Wire.read(); | |||
#endif | |||
#ifdef I2CDEV_SERIAL_DEBUG | |||
Serial.print(data[count], HEX); | |||
if (count + 1 < length) Serial.print(" "); | |||
#endif | |||
} | |||
if (timeout > 0 && millis() - t1 >= timeout && count < length) count = -1; // timeout | |||
#ifdef I2CDEV_SERIAL_DEBUG | |||
Serial.print(". Done ("); | |||
Serial.print(count, DEC); | |||
Serial.println(" read)."); | |||
#endif | |||
return count; | |||
} |
@@ -0,0 +1,64 @@ | |||
// I2Cdev library collection - iAQ-2000 I2C device class header file | |||
// Based on AppliedSensor iAQ-2000 Interface Description, Version PA1, 2009 | |||
// 2012-04-01 by Peteris Skorovs <pskorovs@gmail.com> | |||
// | |||
// This I2C device library is using (and submitted as a part of) Jeff Rowberg's I2Cdevlib library, | |||
// which should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib | |||
// | |||
// Changelog: | |||
// 2012-04-01 - initial release | |||
// 2015-11-08 - added TVoc and Status | |||
/* ============================================ | |||
I2Cdev device library code is placed under the MIT license | |||
Copyright (c) 2012 Peteris Skorovs, Jeff Rowberg | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. | |||
=============================================== | |||
*/ | |||
#ifndef _IAQ2000_H_ | |||
#define _IAQ2000_H_ | |||
#include "I2Cdev.h" | |||
#define IAQ2000_ADDRESS 0x5A | |||
#define IAQ2000_DEFAULT_ADDRESS IAQ2000_ADDRESS | |||
#define IAQ2000_RA_DATA1 0x00 | |||
#define IAQ2000_RA_DATA2 0x01 | |||
class IAQ2000 { | |||
public: | |||
IAQ2000(); | |||
IAQ2000(uint8_t address); | |||
void initialize(); | |||
bool testConnection(); | |||
uint16_t getIaqtvoc(); | |||
uint16_t getIaqpred(); | |||
uint8_t getIaqstatus(); | |||
private: | |||
uint8_t devAddr; | |||
uint8_t buffer[8]; | |||
int8_t readAllBytes(uint8_t devAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout); | |||
}; | |||
#endif /* _IAQ200_H_ */ |
@@ -0,0 +1,162 @@ | |||
// I2C device class (I2Cdev) demonstration Arduino sketch for IAQ2000 class | |||
// 2012-04-01 by Peteris Skorovs <pskorovs@gmail.com> | |||
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib | |||
// I2C Device Library hosted at http://www.i2cdevlib.com | |||
// | |||
// Changelog: | |||
// 2012-04-01 - initial release | |||
// 2015-11-08 - added TVoc and Status | |||
/* ============================================ | |||
IAQ2000 device library code is placed under the MIT license | |||
Copyright (c) 2012 Peteris Skorovs, Jeff Rowberg | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in | |||
all copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |||
THE SOFTWARE. | |||
=============================================== | |||
*/ | |||
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation | |||
// is used in I2Cdev.h | |||
#include "Wire.h" | |||
// I2Cdev and IAQ2000 must be installed as libraries, or else the .cpp/.h files | |||
// for both classes must be in the include path of your project | |||
#include "I2Cdev.h" | |||
#include "IAQ2000.h" | |||
// class default I2C address is 0x5A | |||
// specific I2C addresses may be passed as a parameter here | |||
// but this device only supports one I2C address (0x5A) | |||
IAQ2000 iaq; | |||
uint16_t airQuality; | |||
uint8_t iAQstatus; | |||
uint16_t airTvoc; | |||
unsigned long startTime; | |||
uint16_t oldairQuality = 0; | |||
uint8_t oldiAQstatus = 0; | |||
uint16_t oldairTvoc = 0; | |||
uint8_t result = 0; | |||
#define LED_PIN 13 | |||
bool blinkState = false; | |||
void setup() { | |||
// configure LED pin for output | |||
pinMode(LED_PIN, OUTPUT); | |||
// join I2C bus (I2Cdev library doesn't do this automatically) | |||
Wire.begin(); | |||
// initialize serial communication | |||
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but | |||
// it's really up to you depending on your project) | |||
Serial.begin(38400); | |||
delay(1000); | |||
Serial.println("Initializing Serial..."); | |||
delay(1000); | |||
while (!Serial) { | |||
; // wait for serial port to connect | |||
} | |||
startTime = millis(); | |||
// initialize device | |||
// Serial.println("Initializing I2C devices..."); | |||
iaq.initialize(); | |||
if (!iaq.testConnection()) { | |||
blinkState = !blinkState; | |||
digitalWrite(LED_PIN, blinkState); | |||
delay(500); | |||
} | |||
} | |||
void loop() { | |||
// display predicted CO2 concentration based on human induced volatile organic compounds (VOC) detection (in ppm VOC + CO2 equivalents) | |||
// during the first 6 hours of continuous operation (burn-in) the module will display 450ppm | |||
// the successful burn-in is saved to the EEPROM, the run-in time after restart is 15min | |||
Serial.print("CO2 = "); | |||
Serial.print(airQuality); | |||
Serial.print(" "); | |||
Serial.print("[ppm] 450-2000"); | |||
// blink LED to indicate activity | |||
blinkState = !blinkState; | |||
digitalWrite(LED_PIN, blinkState); | |||
// wait five seconds | |||
delay(5000); | |||
// read seansor | |||
iAQstatus = iaq.getIaqstatus(); | |||
// display predicted CO2 concentration based on human induced volatile organic compounds (VOC) detection (in ppm VOC + CO2 equivalents) | |||
// during the first 6 hours of continuous operation (burn-in) the module will display 450ppm | |||
// the successful burn-in is saved to the EEPROM, the run-in time after restart is 15min | |||
Serial.print(" -- Status = "); | |||
if (iAQstatus == 0) | |||
{ | |||
Serial.print("OK"); | |||
} | |||
if (iAQstatus == 1) | |||
{ | |||
Serial.print("BUSY"); | |||
} | |||
if (iAQstatus == 16) | |||
{ | |||
Serial.print("WARUMUP"); | |||
} | |||
if (iAQstatus == 128) | |||
{ | |||
Serial.print("ERROR"); | |||
} | |||
// blink LED to indicate activity | |||
blinkState = !blinkState; | |||
digitalWrite(LED_PIN, blinkState); | |||
// wait five seconds | |||
delay(5000); | |||
// read seansor | |||
airTvoc = iaq.getIaqtvoc(); | |||
// display predicted CO2 concentration based on human induced volatile organic compounds (VOC) detection (in ppm VOC + CO2 equivalents) | |||
// during the first 6 hours of continuous operation (burn-in) the module will display 450ppm | |||
// the successful burn-in is saved to the EEPROM, the run-in time after restart is 15min | |||
Serial.print(" -- TVoc = "); | |||
Serial.print(airTvoc); | |||
Serial.print(" "); | |||
Serial.println("[ppb] 125-600"); | |||
// blink LED to indicate activity | |||
blinkState = !blinkState; | |||
digitalWrite(LED_PIN, blinkState); | |||
// wait five seconds | |||
delay(5000); | |||
} |
@@ -0,0 +1,25 @@ | |||
####################################### | |||
# Syntax Coloring Map For IAQ2000 | |||
####################################### | |||
####################################### | |||
# Datatypes (KEYWORD1) | |||
####################################### | |||
IAQ2000 KEYWORD1 | |||
####################################### | |||
# Methods and Functions (KEYWORD2) | |||
####################################### | |||
initialize KEYWORD2 | |||
testConnection KEYWORD2 | |||
getIaq KEYWORD2 | |||
####################################### | |||
# Instances (KEYWORD2) | |||
####################################### | |||
####################################### | |||
# Constants (LITERAL1) | |||
####################################### | |||
@@ -0,0 +1,18 @@ | |||
{ | |||
"name": "I2Cdevlib-IAQ2000", | |||
"keywords": "co2, carbon, dioxide, sensor, i2cdevlib, i2c", | |||
"description": "The iAQ-2000 Indoor Air Quality Module is a sensitive, low-cost solution for detecting poor air quality", | |||
"include": "Arduino/IAQ2000", | |||
"repository": | |||
{ | |||
"type": "git", | |||
"url": "https://github.com/jrowberg/i2cdevlib.git" | |||
}, | |||
"dependencies": | |||
{ | |||
"name": "I2Cdevlib-Core", | |||
"frameworks": "arduino" | |||
}, | |||
"frameworks": "arduino", | |||
"platforms": "atmelavr" | |||
} |
@@ -1,2 +1,2 @@ | |||
spec.o: \ | |||
C:/Users/agr/Documents/sloeber-workspace/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C | |||
spec.o: \ | |||
C:/Users/andy/Documents/sloeber-workspace/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C |