code.py
 1  # SPDX-FileCopyrightText: 2019 Mikey Sklar for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  import os
 6  import time
 7  import board
 8  import busio
 9  import adafruit_mcp9808
10  
11  # This example shows how to get the temperature from a MCP9808 board
12  i2c_bus = busio.I2C(board.SCL, board.SDA)
13  mcp = adafruit_mcp9808.MCP9808(i2c_bus)
14  
15  while True:
16      # print precise temperature values to console
17      tempC = mcp.temperature
18      tempF = tempC * 9 / 5 + 32
19      print('Temperature: {} C {} F '.format(tempC, tempF))
20  
21      # drop decimal points and convert to string for speech
22      tempC = str(int(tempC))
23      tempF = str(int(tempF))
24      os.system("echo 'The temperature is " + tempF + " degrees' | festival --tts")
25  
26      time.sleep(60.0)