Browse Source

Support for TMP35 & TMP37 temperature sensors

rfm69
Xose Pérez 6 years ago
parent
commit
39a9fddc62
3 changed files with 51 additions and 20 deletions
  1. +13
    -9
      code/espurna/config/sensors.h
  2. +3
    -2
      code/espurna/sensor.ino
  3. +35
    -9
      code/espurna/sensors/TMP3XSensor.h

+ 13
- 9
code/espurna/config/sensors.h View File

@ -109,7 +109,7 @@
#define SENSOR_AM2320_ID 0x19 #define SENSOR_AM2320_ID 0x19
#define SENSOR_GUVAS12SD_ID 0x20 #define SENSOR_GUVAS12SD_ID 0x20
#define SENSOR_CSE7766_ID 0x21 #define SENSOR_CSE7766_ID 0x21
#define SENSOR_TMP36_ID 0x22
#define SENSOR_TMP3X_ID 0x22
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Magnitudes // Magnitudes
@ -516,15 +516,19 @@
#endif #endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// TMP36 analog temperature sensor
// Enable support by passing TMP36_SUPPORT=1 build flag
// TMP3X analog temperature sensor
// Enable support by passing TMP3X_SUPPORT=1 build flag
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#ifndef TMP36_SUPPORT
#define TMP36_SUPPORT 1
#ifndef TMP3X_SUPPORT
#define TMP3X_SUPPORT 1
#endif #endif
#if TMP36_SUPPORT
#ifndef TMP3X_TYPE
#define TMP3X_TYPE TMP3X_TMP35
#endif
#if TMP3X_SUPPORT
#undef ADC_VCC_ENABLED #undef ADC_VCC_ENABLED
#define ADC_VCC_ENABLED 0 #define ADC_VCC_ENABLED 0
#endif #endif
@ -597,7 +601,7 @@
|| EMON_ANALOG_SUPPORT || EVENTS_SUPPORT || HLW8012_SUPPORT \ || EMON_ANALOG_SUPPORT || EVENTS_SUPPORT || HLW8012_SUPPORT \
|| MHZ19_SUPPORT || PMSX003_SUPPORT || SHT3X_I2C_SUPPORT \ || MHZ19_SUPPORT || PMSX003_SUPPORT || SHT3X_I2C_SUPPORT \
|| SI7021_SUPPORT || V9261F_SUPPORT || AM2320_SUPPORT \ || SI7021_SUPPORT || V9261F_SUPPORT || AM2320_SUPPORT \
|| GUVAS12SD_SUPPORT || CSE7766_SUPPORT || TMP36_SUPPORT
|| GUVAS12SD_SUPPORT || CSE7766_SUPPORT || TMP3X_SUPPORT
#define SENSOR_SUPPORT 1 #define SENSOR_SUPPORT 1
#else #else
#define SENSOR_SUPPORT 0 #define SENSOR_SUPPORT 0
@ -803,8 +807,8 @@ PROGMEM const char* const magnitude_units[] = {
#include "../sensors/SHT3XI2CSensor.h" #include "../sensors/SHT3XI2CSensor.h"
#endif #endif
#if TMP36_SUPPORT
#include "../sensors/TMP36Sensor.h"
#if TMP3X_SUPPORT
#include "../sensors/TMP3XSensor.h"
#endif #endif
#if V9261F_SUPPORT #if V9261F_SUPPORT


+ 3
- 2
code/espurna/sensor.ino View File

@ -484,9 +484,10 @@ void _sensorLoad() {
} }
#endif #endif
#if TMP36_SUPPORT
#if TMP3X_SUPPORT
{ {
TMP36Sensor * sensor = new TMP36Sensor();
TMP3XSensor * sensor = new TMP3XSensor();
sensor->setType(TMP3X_TYPE);
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif


code/espurna/sensors/TMP36Sensor.h → code/espurna/sensors/TMP3XSensor.h View File

@ -1,16 +1,20 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Analog Sensor (maps to an analogRead)
// Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
// TMP3X Temperature Analog Sensor
// Copyright (C) 2018 by Xose Pérez <xose dot perez at gmail dot com>
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#if SENSOR_SUPPORT && TMP36_SUPPORT
#if SENSOR_SUPPORT && TMP3X_SUPPORT
#pragma once #pragma once
#include "Arduino.h" #include "Arduino.h"
#include "BaseSensor.h" #include "BaseSensor.h"
class TMP36Sensor : public BaseSensor {
#define TMP3X_TMP35 35
#define TMP3X_TMP36 36
#define TMP3X_TMP37 37
class TMP3XSensor : public BaseSensor {
public: public:
@ -18,9 +22,21 @@ class TMP36Sensor : public BaseSensor {
// Public // Public
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
TMP36Sensor(): BaseSensor() {
TMP3XSensor(): BaseSensor() {
_count = 1; _count = 1;
_sensor_id = SENSOR_TMP36_ID;
_sensor_id = SENSOR_TMP3X_ID;
}
void setType(unsigned char type) {
if (type == _type) return;
if (35 <= type && type <= 37) {
_type = type;
_dirty = true;
}
}
unsigned char getType() {
return _type;
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -35,7 +51,9 @@ class TMP36Sensor : public BaseSensor {
// Descriptive name of the sensor // Descriptive name of the sensor
String description() { String description() {
return String("TMP36 @ TOUT");
char buffer[14];
snprintf(buffer, sizeof(buffer), "TMP%d @ TOUT", _type);
return String(buffer);
} }
// Descriptive name of the slot # index // Descriptive name of the slot # index
@ -56,11 +74,19 @@ class TMP36Sensor : public BaseSensor {
// Current value for slot # index // Current value for slot # index
double value(unsigned char index) { double value(unsigned char index) {
if (index == 0) return (double) analogRead(0) * 100 * (3.3 / 1024) - 50;
if (index == 0) {
double mV = 3300.0 * analogRead(0) / 1024.0;
if (_type == TMP3X_TMP35) return mV / 10.0;
if (_type == TMP3X_TMP36) return mV / 10.0 - 50.0;
if (_type == TMP3X_TMP37) return mV / 20.0;
}
return 0; return 0;
} }
private:
unsigned char _type = TMP3X_TMP35;
}; };
#endif // SENSOR_SUPPORT && TMP36_SUPPORT
#endif // SENSOR_SUPPORT && TMP3X_SUPPORT

Loading…
Cancel
Save