Browse Source

Telaire T6613 Support (#1956)

* Added T6613

* Added T6613

* Added T6613

* Added T6613

* Added T6613

* Added T6613

* Added T6613

* Added T6613

* Added T6613

* Updated copyright string

* Buffer from 6 bytes to 8 bytes

Current gcc-4 does not mark this as warning, but gcc-9 notices the 3 char size requirement. Buffer should be 8

* Use 5000ppm max
master
James 5 years ago
committed by Max Prokhorov
parent
commit
d177634a70
9 changed files with 226 additions and 1 deletions
  1. +1
    -0
      README.md
  2. +1
    -0
      code/espurna/config/arduino.h
  3. +3
    -0
      code/espurna/config/progmem.h
  4. +22
    -0
      code/espurna/config/sensors.h
  5. +1
    -0
      code/espurna/config/types.h
  6. +9
    -0
      code/espurna/sensor.ino
  7. +187
    -0
      code/espurna/sensors/T6613Sensor.h
  8. +1
    -1
      code/html/custom.js
  9. +1
    -0
      code/test/build/sensor.h

+ 1
- 0
README.md View File

@ -101,6 +101,7 @@ Since November 2018, Max Prokhorov (**@mcspr**) is also actively working as a co
* **AM2320** temperature and humidity sensor over I2C
* **Dallas OneWire sensors** like the DS18B20
* **MHZ19** CO2 sensor
* **T6613** CO2 sensor
* **MICS2710** CO2 & NO2 sensor
* **MICS5525** CO & CO2 sensor
* **SenseAir S8** CO2 sensor


+ 1
- 0
code/espurna/config/arduino.h View File

@ -217,6 +217,7 @@
//#define SHT3X_I2C_SUPPORT 1
//#define SI7021_SUPPORT 1
//#define SONAR_SUPPORT 1
//#define T6613_SUPPORT 1
//#define TMP3X_SUPPORT 1
//#define V9261F_SUPPORT 1
//#define VEML6075_SUPPORT 1


+ 3
- 0
code/espurna/config/progmem.h View File

@ -264,6 +264,9 @@ PROGMEM const char espurna_sensors[] =
#if SONAR_SUPPORT
"SONAR "
#endif
#if T6613_SUPPORT
"T6613 "
#endif
#if TMP3X_SUPPORT
"TMP3X "
#endif


+ 22
- 0
code/espurna/config/sensors.h View File

@ -1052,6 +1052,23 @@
#define SONAR_ITERATIONS 5 // Number of iterations to ping for
#endif // error correction.
//------------------------------------------------------------------------------
// T6613 CO2 sensor
// Enable support by passing T6613_SUPPORT=1 build flag
//------------------------------------------------------------------------------
#ifndef T6613_SUPPORT
#define T6613_SUPPORT 0
#endif
#ifndef T6613_RX_PIN
#define T6613_RX_PIN 4
#endif
#ifndef T6613_TX_PIN
#define T6613_TX_PIN 5
#endif
//------------------------------------------------------------------------------
// TMP3X analog temperature sensor
// Enable support by passing TMP3X_SUPPORT=1 build flag
@ -1216,6 +1233,7 @@
SHT3X_I2C_SUPPORT || \
SI7021_SUPPORT || \
SONAR_SUPPORT || \
T6613_SUPPORT || \
TMP3X_SUPPORT || \
V9261F_SUPPORT || \
VEML6075_SUPPORT || \
@ -1403,6 +1421,10 @@
#include "../sensors/SonarSensor.h"
#endif
#if T6613_SUPPORT
#include "../sensors/T6613Sensor.h"
#endif
#if TMP3X_SUPPORT
#include "../sensors/TMP3XSensor.h"
#endif


+ 1
- 0
code/espurna/config/types.h View File

@ -316,6 +316,7 @@
#define SENSOR_MAX6675_ID 35
#define SENSOR_LDR_ID 36
#define SENSOR_ADE7953_ID 37
#define SENSOR_T6613_ID 38
//--------------------------------------------------------------------------------
// Magnitudes


+ 9
- 0
code/espurna/sensor.ino View File

@ -1028,6 +1028,15 @@ void _sensorLoad() {
_sensors.push_back(sensor);
}
#endif
#if T6613_SUPPORT
{
T6613Sensor * sensor = new T6613Sensor();
sensor->setRX(T6613_RX_PIN);
sensor->setTX(T6613_TX_PIN);
_sensors.push_back(sensor);
}
#endif
#if TMP3X_SUPPORT
{


+ 187
- 0
code/espurna/sensors/T6613Sensor.h View File

@ -0,0 +1,187 @@
// -----------------------------------------------------------------------------
// T6613 CO2 sensor
// https://www.amphenol-sensors.com/en/telaire/co2/525-co2-sensor-modules/321-t6613
// Uses SoftwareSerial library
// Copyright (C) 2017-2019 by Xose Pérez <xose dot perez at gmail dot com>
// -----------------------------------------------------------------------------
#if SENSOR_SUPPORT && T6613_SUPPORT
#pragma once
#include "Arduino.h"
#include "BaseSensor.h"
#include <SoftwareSerial.h>
#define T6613_REQUEST_LEN 5
#define T6613_RESPONSE_LEN 5
#define T6613_TIMEOUT 1000
#define T6613_GETPPM 0x020203
class T6613Sensor : public BaseSensor {
public:
// ---------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------
T6613Sensor(): BaseSensor() {
_count = 1;
_sensor_id = SENSOR_T6613_ID;
}
~T6613Sensor() {
if (_serial) delete _serial;
}
// ---------------------------------------------------------------------
void setRX(unsigned char pin_rx) {
if (_pin_rx == pin_rx) return;
_pin_rx = pin_rx;
_dirty = true;
}
void setTX(unsigned char pin_tx) {
if (_pin_tx == pin_tx) return;
_pin_tx = pin_tx;
_dirty = true;
}
// ---------------------------------------------------------------------
unsigned char getRX() {
return _pin_rx;
}
unsigned char getTX() {
return _pin_tx;
}
// ---------------------------------------------------------------------
// Sensor API
// ---------------------------------------------------------------------
// Initialization method, must be idempotent
void begin() {
if (!_dirty) return;
if (_serial) delete _serial;
_serial = new SoftwareSerial(_pin_rx, _pin_tx, false, 32);
_serial->enableIntTx(false);
_serial->begin(19200);
_ready = true;
_dirty = false;
}
// Descriptive name of the sensor
String description() {
char buffer[28];
snprintf(buffer, sizeof(buffer), "T6613 @ SwSerial(%u,%u)", _pin_rx, _pin_tx);
return String(buffer);
}
// Descriptive name of the slot # index
String slot(unsigned char index) {
return description();
};
// Address of the sensor (it could be the GPIO or I2C address)
String address(unsigned char index) {
char buffer[8];
snprintf(buffer, sizeof(buffer), "%u:%u", _pin_rx, _pin_tx);
return String(buffer);
}
// Type for slot # index
unsigned char type(unsigned char index) {
if (index == 0) return MAGNITUDE_CO2;
return MAGNITUDE_NONE;
}
void pre() {
_read();
}
// Current value for slot # index
double value(unsigned char index) {
if (index == 0) return _co2;
return 0;
}
protected:
// ---------------------------------------------------------------------
// Protected
// ---------------------------------------------------------------------
void _write(unsigned char * command) {
_serial->write(command, T6613_REQUEST_LEN);
_serial->flush();
}
void _write(unsigned int command, unsigned char * response) {
unsigned char buffer[T6613_REQUEST_LEN] = {0};
buffer[0] = 0xFF;
buffer[1] = 0xFE;
buffer[2] = command >> 16;
buffer[3] = (command >> 8) & 0xFF;
buffer[4] = command & 0xFF;
_write(buffer);
if (response != NULL) {
unsigned long start = millis();
while (_serial->available() == 0) {
if (millis() - start > T6613_TIMEOUT) {
_error = SENSOR_ERROR_TIMEOUT;
return;
}
yield();
}
_serial->readBytes(response, T6613_RESPONSE_LEN);
}
}
void _write(unsigned int command) {
_write(command, NULL);
}
void _read() {
unsigned char buffer[T6613_RESPONSE_LEN] = {0};
_write(T6613_GETPPM, buffer);
// Check response
if ((buffer[0] == 0xFF)
&& (buffer[1] == 0xFA)
&& (buffer[2] == 0x02)) {
unsigned int value = buffer[3] * 256 + buffer[4];
if (0 <= value && value <= 5000) {
_co2 = value;
_error = SENSOR_ERROR_OK;
} else {
_error = SENSOR_ERROR_OUT_OF_RANGE;
}
} else {
_error = SENSOR_ERROR_CRC;
}
}
double _co2 = 0;
unsigned int _pin_rx;
unsigned int _pin_tx;
SoftwareSerial * _serial = NULL;
};
#endif // SENSOR_SUPPORT && T6613_SUPPORT

+ 1
- 1
code/html/custom.js View File

@ -51,7 +51,7 @@ function sensorName(id) {
"HLW8012", "V9261F", "ECH1560", "Analog", "Digital",
"Events", "PMSX003", "BMX280", "MHZ19", "SI7021",
"SHT3X I2C", "BH1750", "PZEM004T", "AM2320 I2C", "GUVAS12SD",
"TMP3X", "Sonar", "SenseAir", "GeigerTicks", "GeigerCPM",
"T6613", "TMP3X", "Sonar", "SenseAir", "GeigerTicks", "GeigerCPM",
"NTC", "SDS011", "MICS2710", "MICS5525", "VL53L1X", "VEML6075",
"EZOPH"
];


+ 1
- 0
code/test/build/sensor.h View File

@ -13,6 +13,7 @@
#define MICS5525_SUPPORT 1
#define MAX6675_SUPPORT 1
#define DHT_SUPPORT 1
#define T6613_SUPPORT 1
#define TMP3X_SUPPORT 1
#define EVENTS_SUPPORT 1
#define DIGITAL_SUPPORT 1


Loading…
Cancel
Save