1.. zephyr:code-sample:: jc42 2 :name: JEDEC JC 42.4 compliant Temperature Sensor 3 :relevant-api: sensor_interface 4 5 Get ambient temperature from a JEDEC JC 42.4 compliant temperature sensor (polling & trigger 6 mode). 7 8Overview 9******** 10 11This sample application periodically (0.5 Hz) measures the ambient 12temperature. The result is written to the console. 13 14If triggered measurements are enabled the sample initializes and 15maintains a |plusminus| 2 |deg| C window around the current temperature. 16When the temperature moves outside the window an alert is given, and the 17window is moved to center on the new temperature. 18 19Requirements 20************ 21 22The sample requires a JEDEC JC 42.4 compliant temperature sensor. The 23sample is configured to use the MCP9808 sensor. 24 25The MCP9808 digital temperature sensor converts temperatures between -20 |deg| 26C and +100 |deg| C to a digital word with |plusminus| 0.5 |deg| C (max.) 27accuracy. It is I2C compatible and supports up to 16 devices on the bus. 28 29Wiring 30******* 31 32The MCP9808, which is a JEDEC JC 42.4 compliant temperature sensor, is 33available in a discrete component form but it is much easier to 34use it mounted on a breakout board. We used the Adafruit `MCP9808 35Sensor`_ breakout board. 36 37.. _`MCP9808 Sensor`: https://www.adafruit.com/product/1782 38 39Building and Running 40******************** 41 42After providing a devicetree overlay that specifies the sensor I2C bus 43and alert GPIO, build this sample app using: 44 45.. zephyr-app-commands:: 46 :zephyr-app: samples/sensor/jc42 47 :board: particle_xenon 48 :goals: build flash 49 50Sample Output 51============= 52 53Note that in the capture below output from the trigger callback and the 54main thread are interleaved. 55 56.. code-block:: console 57 58 *** Booting Zephyr OS build zephyr-v2.1.0-537-gbbdeaa1ae5bb *** 59 Alert on temp outside [24500, 25500] milli-Celsius 60 Trtrigger fired 1, temp 15.9375 C 61 iggAlert on temp outside [15437, 16437] milli-Celsius 62 er set got 0 63 0:00:00.017: 15.9375 C 64 0:00:02.020: 16 C 65 0:00:04.022: 16.125 C 66 0:00:06.024: 16.1875 C 67 trigger fired 2, temp 16.3125 C 68 Alert on temp outside [15812, 16812] milli-Celsius 69 0:00:08.027: 16.3125 C 70 0:00:10.029: 16.375 C 71 0:00:12.032: 16.5 C 72 0:00:14.034: 16.5625 C 73 0:00:16.037: 16.5625 C 74 0:00:18.039: 16.625 C 75 0:00:20.042: 16.6875 C 76 trigger fired 3, temp 16.8125 C 77 Alert on temp outside [16312, 17312] milli-Celsius 78 0:00:22.044: 16.8125 C 79 0:00:24.047: 16.875 C 80