Browse Source

MAX6675 Support

pull/1375/head
Luciano Andrade 5 years ago
parent
commit
36ef050fb6
5 changed files with 170 additions and 1 deletions
  1. +4
    -0
      code/espurna/config/sensors.h
  2. +1
    -0
      code/espurna/config/types.h
  3. +12
    -0
      code/espurna/sensor.ino
  4. +150
    -0
      code/espurna/sensors/MAX6675.h
  5. +3
    -1
      code/platformio.ini

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

@ -894,4 +894,8 @@
#include "../sensors/V9261FSensor.h"
#endif
#if MAX6675_SUPPORT
#include "../sensors/MAX6675.h"
#endif
#endif // SENSOR_SUPPORT

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

@ -279,6 +279,7 @@
#define SENSOR_SDS011_ID 0x27
#define SENSOR_MICS2710_ID 0x28
#define SENSOR_MICS5525_ID 0x29
#define SENSOR_MAX6675_ID 0x30
//--------------------------------------------------------------------------------
// Magnitudes


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

@ -705,6 +705,18 @@ void _sensorLoad() {
}
#endif
#if MAX6675_SUPPORT
{
MAX6675Sensor * sensor = new MAX6675Sensor();
sensor->setCS(MAX6675_CS_PIN);
sensor->setSO(MAX6675_SO_PIN);
sensor->setSCK(MAX6675_SCK_PIN);
_sensors.push_back(sensor);
}
#endif
}
void _sensorCallback(unsigned char i, unsigned char type, double value) {


+ 150
- 0
code/espurna/sensors/MAX6675.h View File

@ -0,0 +1,150 @@
// -----------------------------------------------------------------------------
// MAX6675 Sensor
// Uses MAX6675_Thermocouple library
// Copyright (C) 2017-2018 by Xose Pérez <andrade dot luciano at gmail dot com>
// -----------------------------------------------------------------------------
#if SENSOR_SUPPORT && MAX6675_SUPPORT
#pragma once
#include "Arduino.h"
#include "BaseSensor.h"
#include <vector>
#include <MAX6675.h>
#define MAX6675_READ_INTERVAL 3000
class MAX6675Sensor : public BaseSensor {
public:
// ---------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------
MAX6675Sensor(): BaseSensor() {
_sensor_id = SENSOR_MAX6675_ID;
}
~MAX6675Sensor() {
}
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
void setCS(unsigned char pin_cs) {
if (_pin_cs == pin_cs) return;
_pin_cs = pin_cs;
_dirty = true;
}
void setSO(unsigned char pin_so) {
if (_pin_so == pin_so) return;
_pin_so = pin_so;
_dirty = true;
}
void setSCK(unsigned char pin_sck) {
if (_pin_sck == pin_sck) return;
_pin_sck = pin_sck;
_dirty = true;
}
// ---------------------------------------------------------------------
// Sensor API
// ---------------------------------------------------------------------
// Initialization method, must be idempotent
void begin() {
if (!_dirty) return;
//// MAX6675
int units = 1; // Units to readout temp (0 = raw, 1 = ˚C, 2 = ˚F)
if (_max) delete _max;
_max = new MAX6675(_pin_cs,_pin_so,_pin_sck,units);
_count = 1;
_ready = true;
_dirty = false;
}
// Loop-like method, call it in your main loop
void tick() {
static unsigned long last = 0;
if (millis() - last < MAX6675_READ_INTERVAL) return;
last = millis();
last_read = _max->read_temp();
}
// Descriptive name of the sensor
String description() {
char buffer[20];
//snprintf(buffer, sizeof(buffer), "MAX6675 @ CS %d", _gpio);
snprintf(buffer, sizeof(buffer), "MAX6675 ");
return String(buffer);
}
String address(unsigned char index){
return String("@ address");
}
// Address of the device
// Descriptive name of the slot # index
String slot(unsigned char index) {
if (index < _count) {
// char buffer[40];
// uint8_t * address = _devices[index].address;
// snprintf(buffer, sizeof(buffer), "%s (%02X%02X%02X%02X%02X%02X%02X%02X) @ GPIO%d",
// chipAsString(index).c_str(),
// address[0], address[1], address[2], address[3],
// address[4], address[5], address[6], address[7],
// _gpio
// );
return description();
}
return String();
}
// Type for slot # index
unsigned char type(unsigned char index) {
if (index < _count) return MAGNITUDE_TEMPERATURE;
return MAGNITUDE_NONE;
}
// Pre-read hook (usually to populate registers with up-to-date data)
void pre() {
_error = SENSOR_ERROR_OK;
}
// Current value for slot # index
double value(unsigned char index) {
return last_read;
}
protected:
// ---------------------------------------------------------------------
// Protected
// ---------------------------------------------------------------------
unsigned int _pin_cs = MAX6675_CS_PIN;
unsigned int _pin_so = MAX6675_SO_PIN;
unsigned int _pin_sck = MAX6675_SCK_PIN;
bool _busy = false;
double last_read = 0;
MAX6675 * _max = NULL;
};
#endif // SENSOR_SUPPORT && MAX6675_SUPPORT

+ 3
- 1
code/platformio.ini View File

@ -41,7 +41,7 @@ debug_flags = -DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP
# -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY = v2 Lower Memory
# -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH = v2 Higher Bandwidth
# ------------------------------------------------------------------------------
build_flags = -g -w -DMQTT_MAX_PACKET_SIZE=400 -DNO_GLOBAL_EEPROM ${sysenv.ESPURNA_FLAGS} -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH
build_flags = -g -w -DMQTT_MAX_PACKET_SIZE=400 -DNO_GLOBAL_EEPROM ${sysenv.ESPURNA_FLAGS} -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH -DMAX6675_SUPPORT -DSENSOR_SUPPORT -DUSE_CUSTOM_H
build_flags_512k = ${common.build_flags} -Wl,-Teagle.flash.512k0m1s.ld
build_flags_1m0m = ${common.build_flags} -Wl,-Teagle.flash.1m0m1s.ld
build_flags_2m1m = ${common.build_flags} -Wl,-Teagle.flash.2m1m4s.ld
@ -97,6 +97,8 @@ lib_deps =
https://github.com/LowPowerLab/RFM69#1.1.3
https://github.com/xoseperez/Time
NewPing
https://github.com/mcleng/MAX6675-Library#2.0.1
lib_ignore =
# ------------------------------------------------------------------------------


Loading…
Cancel
Save