It's easy to use the AD8495 sensor with CircuitPython. This board does not require a separate library. The built in analogio
module lets you easily read voltage from a thermocouple and use a simple equation to turn it into temperature.
CircuitPython Microcontroller Wiring
First, wire up your AD8495. Here is an example of it wired up to a Feather M0:
- Board V+ to Feather 3V
- Board GND to Feather GND
- Board OUT to Feather A1
- Board RED- to thermocouple red- wire
- Board YLW+ to thermocouple yellow+ wire
CircuitPython Usage
To demonstrate use of this board, we'll initialise it and read the voltage and use the equation to turn it into temperature using the board's Python REPL.
First, run the following code to import the necessary modules and initialise the board on pin A1:
import board import analogio ad8495 = analogio.AnalogIn(board.A1)
Next, we'll need a helper function to take the raw data from the thermocouple and turn it into voltage.
def get_voltage(pin): return (pin.value * 3.3) / 65536
Next, we set temperature
equal to the equation necessary to convert the voltage from the thermocouple into temperature, using the get_voltage
helper.
The equation is (voltage - 1.25) / 0.005
.
temperature = (get_voltage(ad8495) - 1.25) / 0.005
Now we can print the current temperature in C.
print(temperature)
That's all there is to using the AD8495 with CircuitPython!
# SPDX-FileCopyrightText: 2019 Kattni Rembor for Adafruit Industries # # SPDX-License-Identifier: MIT # import time import analogio import board ad8495 = analogio.AnalogIn(board.A1) def get_voltage(pin): return (pin.value * 3.3) / 65536 while True: temperature = (get_voltage(ad8495) - 1.25) / 0.005 print(temperature) print(get_voltage(ad8495)) time.sleep(0.5)