ESPHome  2024.3.1
max6675.cpp
Go to the documentation of this file.
1 #include "max6675.h"
2 #include "esphome/core/log.h"
3 
4 namespace esphome {
5 namespace max6675 {
6 
7 static const char *const TAG = "max6675";
8 
10  this->enable();
11  delay(1);
12  // conversion initiated by rising edge
13  this->disable();
14 
15  // Conversion time typ: 170ms, max: 220ms
16  auto f = std::bind(&MAX6675Sensor::read_data_, this);
17  this->set_timeout("value", 250, f);
18 }
19 
21  ESP_LOGCONFIG(TAG, "Setting up MAX6675Sensor '%s'...", this->name_.c_str());
22  this->spi_setup();
23 }
25  LOG_SENSOR("", "MAX6675", this);
26  LOG_PIN(" CS Pin: ", this->cs_);
27  LOG_UPDATE_INTERVAL(this);
28 }
31  this->enable();
32  delay(1);
33  uint8_t data[2];
34  this->read_array(data, 2);
35  uint16_t val = data[1] | (uint16_t(data[0]) << 8);
36  this->disable();
37 
38  if ((val & 0x04) != 0) {
39  // Thermocouple open
40  ESP_LOGW(TAG, "Got invalid value from MAX6675Sensor (0x%04X)", val);
41  this->status_set_warning();
42  return;
43  }
44 
45  float temperature = float(val >> 3) / 4.0f;
46  ESP_LOGD(TAG, "'%s': Got temperature=%.1f°C", this->name_.c_str(), temperature);
47  this->publish_state(temperature);
48  this->status_clear_warning();
49 }
50 
51 } // namespace max6675
52 } // namespace esphome
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
void status_set_warning(const char *message="unspecified")
Definition: component.cpp:146
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
Definition: component.cpp:69
float temperature
Definition: qmp6988.h:71
void dump_config() override
Definition: max6675.cpp:24
mopeka_std_values val[4]
GPIOPin * cs_
Definition: spi.h:395
void status_clear_warning()
Definition: component.cpp:161
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
float get_setup_priority() const override
Definition: max6675.cpp:29
constexpr const char * c_str() const
Definition: string_ref.h:68
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26