ESPHome 2026.11.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::max6675 {
5
6ESPHOME_LOG_TAG(TAG, "max6675");
7
8static constexpr uint32_t READ_TIMEOUT_ID = 0;
9
11 this->enable();
12 delay(1);
13 // conversion initiated by rising edge
14 this->disable();
15
16 // Conversion time typ: 170ms, max: 220ms
17 this->set_timeout(READ_TIMEOUT_ID, 250, [this]() { this->read_data_(); });
18}
19
22 LOG_SENSOR("", "MAX6675", this);
23 LOG_PIN(" CS Pin: ", this->cs_);
24 LOG_UPDATE_INTERVAL(this);
25}
27 this->enable();
28 delay(1);
29 uint8_t data[2];
30 this->read_array(data, 2);
31 uint16_t val = data[1] | (uint16_t(data[0]) << 8);
32 this->disable();
33
34 // Bit 2 set means the thermocouple is open
35 if (!this->status_comm_result((val & 0x04) == 0, nullptr)) {
36 ESP_LOGW(TAG, "Got invalid value from MAX6675Sensor (0x%04X)", val);
37 return;
38 }
39
40 float temperature = float(val >> 3) / 4.0f;
41 ESP_LOGD(TAG, "'%s': Got temperature=%.1f°C", LOG_STR_ARG(this->get_log_name()), temperature);
42 this->publish_state(temperature);
43}
44
45} // namespace esphome::max6675
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
Definition component.cpp:96
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:65
mopeka_std_values val[3]
ESPHOME_LOG_TAG(TAG, "max6675")
void HOT delay(uint32_t ms)
Definition hal.cpp:85
static void uint32_t
uint16_t temperature
Definition sun_gtil2.cpp:12