ESPHome
2026.5.0-dev
Loading...
Searching...
No Matches
esphome
components
max6675
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
9
void
MAX6675Sensor::update
() {
10
this->
enable
();
11
delay
(1);
12
// conversion initiated by rising edge
13
this->
disable
();
14
15
// Conversion time typ: 170ms, max: 220ms
16
this->
set_timeout
(
"value"
, 250, [
this
]() { this->
read_data_
(); });
17
}
18
19
void
MAX6675Sensor::setup
() { this->
spi_setup
(); }
20
void
MAX6675Sensor::dump_config
() {
21
LOG_SENSOR(
""
,
"MAX6675"
,
this
);
22
LOG_PIN(
" CS Pin: "
, this->
cs_
);
23
LOG_UPDATE_INTERVAL(
this
);
24
}
25
void
MAX6675Sensor::read_data_
() {
26
this->
enable
();
27
delay
(1);
28
uint8_t data[2];
29
this->
read_array
(data, 2);
30
uint16_t
val
= data[1] | (uint16_t(data[0]) << 8);
31
this->
disable
();
32
33
if
((val & 0x04) != 0) {
34
// Thermocouple open
35
ESP_LOGW(TAG,
"Got invalid value from MAX6675Sensor (0x%04X)"
,
val
);
36
this->
status_set_warning
();
37
return
;
38
}
39
40
float
temperature
= float(
val
>> 3) / 4.0f;
41
ESP_LOGD(TAG,
"'%s': Got temperature=%.1f°C"
, this->
name_
.
c_str
(), temperature);
42
this->
publish_state
(temperature);
43
this->
status_clear_warning
();
44
}
45
46
}
// namespace max6675
47
}
// namespace esphome
esphome::Component::status_set_warning
void status_set_warning()
Definition
component.cpp:379
esphome::Component::set_timeout
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
esphome::Component::status_clear_warning
void status_clear_warning()
Definition
component.h:306
esphome::EntityBase::name_
StringRef name_
Definition
entity_base.h:257
esphome::StringRef::c_str
constexpr const char * c_str() const
Definition
string_ref.h:73
esphome::max6675::MAX6675Sensor::dump_config
void dump_config() override
Definition
max6675.cpp:20
esphome::max6675::MAX6675Sensor::setup
void setup() override
Definition
max6675.cpp:19
esphome::max6675::MAX6675Sensor::read_data_
void read_data_()
Definition
max6675.cpp:25
esphome::max6675::MAX6675Sensor::update
void update() override
Definition
max6675.cpp:9
esphome::sensor::Sensor::publish_state
void publish_state(float state)
Publish a new state to the front-end.
Definition
sensor.cpp:68
esphome::spi::SPIClient::cs_
GPIOPin * cs_
Definition
spi.h:414
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_1MHZ >::enable
void enable()
Definition
spi.h:501
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_1MHZ >::spi_setup
void spi_setup() override
Definition
spi.h:438
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_1MHZ >::disable
void disable()
Definition
spi.h:503
esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_1MHZ >::read_array
void read_array(uint8_t *data, size_t length)
Definition
spi.h:454
log.h
max6675.h
val
mopeka_std_values val[3]
Definition
mopeka_std_check.h:8
esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition
a01nyub.cpp:7
esphome::delay
void HOT delay(uint32_t ms)
Definition
core.cpp:28
temperature
uint16_t temperature
Definition
sun_gtil2.cpp:12
Generated by
1.12.0