1 /* 2 * Copyright (c) 2021 Teslabs Engineering S.L. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <stdio.h> 8 9 #include <zephyr/kernel.h> 10 #include <zephyr/device.h> 11 #include <zephyr/drivers/sensor.h> 12 13 /** 14 * @file Sample app using the MAX6675 cold-junction-compensated K-thermocouple 15 * to digital converter. 16 * 17 * This app will read and display the sensor temperature every second. 18 */ 19 main(void)20int main(void) 21 { 22 const struct device *const dev = DEVICE_DT_GET_ONE(maxim_max6675); 23 struct sensor_value val; 24 25 if (!device_is_ready(dev)) { 26 printk("sensor: device not ready.\n"); 27 return 0; 28 } 29 30 while (1) { 31 int ret; 32 33 ret = sensor_sample_fetch_chan(dev, SENSOR_CHAN_AMBIENT_TEMP); 34 if (ret < 0) { 35 printf("Could not fetch temperature (%d)\n", ret); 36 return 0; 37 } 38 39 ret = sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &val); 40 if (ret < 0) { 41 printf("Could not get temperature (%d)\n", ret); 42 return 0; 43 } 44 45 printf("Temperature: %.2f C\n", sensor_value_to_double(&val)); 46 47 k_sleep(K_MSEC(1000)); 48 } 49 return 0; 50 } 51