ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
max6675.cpp
Go to the documentation of this file.
1#include "max6675.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace max6675 {
6
7static 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
22 LOG_SENSOR("", "MAX6675", this);
23 LOG_PIN(" CS Pin: ", this->cs_);
24 LOG_UPDATE_INTERVAL(this);
25}
28 this->enable();
29 delay(1);
30 uint8_t data[2];
31 this->read_array(data, 2);
32 uint16_t val = data[1] | (uint16_t(data[0]) << 8);
33 this->disable();
34
35 if ((val & 0x04) != 0) {
36 // Thermocouple open
37 ESP_LOGW(TAG, "Got invalid value from MAX6675Sensor (0x%04X)", val);
38 this->status_set_warning();
39 return;
40 }
41
42 float temperature = float(val >> 3) / 4.0f;
43 ESP_LOGD(TAG, "'%s': Got temperature=%.1f°C", this->name_.c_str(), temperature);
44 this->publish_state(temperature);
46}
47
48} // namespace max6675
49} // namespace esphome
void status_set_warning(const char *message=nullptr)
void status_clear_warning()
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
constexpr const char * c_str() const
Definition string_ref.h:69
float get_setup_priority() const override
Definition max6675.cpp:26
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:45
mopeka_std_values val[4]
const float DATA
For components that import data from directly connected sensors like DHT.
Definition component.cpp:50
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
void IRAM_ATTR HOT delay(uint32_t ms)
Definition core.cpp:29
uint16_t temperature
Definition sun_gtil2.cpp:12