Browse Source

TMP36 temperature analog sensor support

rfm69
Xose Pérez 6 years ago
parent
commit
3280742656
4 changed files with 104 additions and 12 deletions
  1. +3
    -3
      README.md
  2. +28
    -9
      code/espurna/config/sensors.h
  3. +7
    -0
      code/espurna/sensor.ino
  4. +66
    -0
      code/espurna/sensors/TMP36Sensor.h

+ 3
- 3
README.md View File

@ -4,9 +4,9 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smar
It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries.
[![version](https://img.shields.io/badge/version-1.12.6a-brightgreen.svg)](CHANGELOG.md)
![branch](https://img.shields.io/badge/branch-dev-orange.svg)
[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna)
[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/dev.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard)
![branch](https://img.shields.io/badge/branch-sensors-orange.svg)
[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=sensors)](https://travis-ci.org/xoseperez/espurna)
[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/sensors.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard)
[![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)
<br />
[![donate](https://img.shields.io/badge/donate-PayPal-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=xose%2eperez%40gmail%2ecom&lc=US&no_note=0&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHostedGuest)


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

@ -109,6 +109,7 @@
#define SENSOR_AM2320_ID 0x19
#define SENSOR_GUVAS12SD_ID 0x20
#define SENSOR_CSE7766_ID 0x21
#define SENSOR_TMP36_ID 0x22
//--------------------------------------------------------------------------------
// Magnitudes
@ -514,6 +515,20 @@
#define I2C_SUPPORT 1
#endif
//------------------------------------------------------------------------------
// TMP36 analog temperature sensor
// Enable support by passing TMP36_SUPPORT=1 build flag
//------------------------------------------------------------------------------
#ifndef TMP36_SUPPORT
#define TMP36_SUPPORT 1
#endif
#if TMP36_SUPPORT
#undef ADC_VCC_ENABLED
#define ADC_VCC_ENABLED 0
#endif
//------------------------------------------------------------------------------
// V9261F based power sensor
// Enable support by passing SI7021_SUPPORT=1 build flag
@ -582,7 +597,7 @@
|| EMON_ANALOG_SUPPORT || EVENTS_SUPPORT || HLW8012_SUPPORT \
|| MHZ19_SUPPORT || PMSX003_SUPPORT || SHT3X_I2C_SUPPORT \
|| SI7021_SUPPORT || V9261F_SUPPORT || AM2320_SUPPORT \
|| GUVAS12SD_SUPPORT || CSE7766_SUPPORT
|| GUVAS12SD_SUPPORT || CSE7766_SUPPORT || TMP36_SUPPORT
#define SENSOR_SUPPORT 1
#else
#define SENSOR_SUPPORT 0
@ -701,6 +716,10 @@ PROGMEM const char* const magnitude_units[] = {
#include "../sensors/BaseSensor.h"
#if AM2320_SUPPORT
#include "../sensors/AM2320Sensor.h"
#endif
#if ANALOG_SUPPORT
#include "../sensors/AnalogSensor.h"
#endif
@ -751,6 +770,10 @@ PROGMEM const char* const magnitude_units[] = {
#include "../sensors/EventSensor.h"
#endif
#if GUVAS12SD_SUPPORT
#include "../sensors/GUVAS12SDSensor.h"
#endif
#if HLW8012_SUPPORT
#include <HLW8012.h>
#include "../sensors/HLW8012Sensor.h"
@ -780,17 +803,13 @@ PROGMEM const char* const magnitude_units[] = {
#include "../sensors/SHT3XI2CSensor.h"
#endif
#if TMP36_SUPPORT
#include "../sensors/TMP36Sensor.h"
#endif
#if V9261F_SUPPORT
#include <SoftwareSerial.h>
#include "../sensors/V9261FSensor.h"
#endif
#if AM2320_SUPPORT
#include "../sensors/AM2320Sensor.h"
#endif
#if GUVAS12SD_SUPPORT
#include "../sensors/GUVAS12SDSensor.h"
#endif
#endif // SENSOR_SUPPORT

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

@ -484,6 +484,13 @@ void _sensorLoad() {
}
#endif
#if TMP36_SUPPORT
{
TMP36Sensor * sensor = new TMP36Sensor();
_sensors.push_back(sensor);
}
#endif
#if V9261F_SUPPORT
{
V9261FSensor * sensor = new V9261FSensor();


+ 66
- 0
code/espurna/sensors/TMP36Sensor.h View File

@ -0,0 +1,66 @@
// -----------------------------------------------------------------------------
// Analog Sensor (maps to an analogRead)
// Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
// -----------------------------------------------------------------------------
#if SENSOR_SUPPORT && TMP36_SUPPORT
#pragma once
#include "Arduino.h"
#include "BaseSensor.h"
class TMP36Sensor : public BaseSensor {
public:
// ---------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------
TMP36Sensor(): BaseSensor() {
_count = 1;
_sensor_id = SENSOR_TMP36_ID;
}
// ---------------------------------------------------------------------
// Sensor API
// ---------------------------------------------------------------------
// Initialization method, must be idempotent
void begin() {
pinMode(0, INPUT);
_ready = true;
}
// Descriptive name of the sensor
String description() {
return String("TMP36 @ TOUT");
}
// 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) {
return String("0");
}
// Type for slot # index
unsigned char type(unsigned char index) {
if (index == 0) return MAGNITUDE_TEMPERATURE;
return MAGNITUDE_NONE;
}
// Current value for slot # index
double value(unsigned char index) {
if (index == 0) return (double) analogRead(0) * 100 * (3.3 / 1024) - 50;
return 0;
}
};
#endif // SENSOR_SUPPORT && TMP36_SUPPORT

Loading…
Cancel
Save