ESPHome 2026.5.0b1
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
6static const char *const TAG = "max6675";
7
9 this->enable();
10 delay(1);
11 // conversion initiated by rising edge
12 this->disable();
13
14 // Conversion time typ: 170ms, max: 220ms
15 this->set_timeout("value", 250, [this]() { this->read_data_(); });
16}
17
20 LOG_SENSOR("", "MAX6675", this);
21 LOG_PIN(" CS Pin: ", this->cs_);
22 LOG_UPDATE_INTERVAL(this);
23}
25 this->enable();
26 delay(1);
27 uint8_t data[2];
28 this->read_array(data, 2);
29 uint16_t val = data[1] | (uint16_t(data[0]) << 8);
30 this->disable();
31
32 if ((val & 0x04) != 0) {
33 // Thermocouple open
34 ESP_LOGW(TAG, "Got invalid value from MAX6675Sensor (0x%04X)", val);
35 this->status_set_warning();
36 return;
37 }
38
39 float temperature = float(val >> 3) / 4.0f;
40 ESP_LOGD(TAG, "'%s': Got temperature=%.1f°C", this->name_.c_str(), temperature);
41 this->publish_state(temperature);
43}
44
45} // namespace esphome::max6675
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
Definition component.h:510
void status_clear_warning()
Definition component.h:306
constexpr const char * c_str() const
Definition string_ref.h:73
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68
mopeka_std_values val[3]
void HOT delay(uint32_t ms)
Definition hal.cpp:82
uint16_t temperature
Definition sun_gtil2.cpp:12