Professional Documents
Culture Documents
Raspberry Pi Pico & MAX6675 K-Type Thermocouple (MicroPython)
Raspberry Pi Pico & MAX6675 K-Type Thermocouple (MicroPython)
Search
Table of Contents
What is a K-Type Thermocouple?
A thermocouple is a temperature sensor commonly used to measure high
temperatures in industrial applications. They consist of two different wires joined
at an end(called the junction). A temperature difference between this junction and
the other ends of the metal can generate a voltage, which can be measured to
estimate the temperature at the hot end.
PIN DESCRIPTION
Specifications
Advertisement
GPIO2(Pin 4) SCK
GPIO3(Pin 5) CS
GPIO4(Pin 6) SO
GND(Pin18) GND
import time
class MAX6675:
MEASUREMENT_PERIOD_MS = 220
With all connections done, connect the Pico to your computer using a USB
cable. Open Thonny IDE, and paste the following code into a new project.
while True:
print("temperature=")
print(sensor.read())
Run the code by clicking the Run icon or by pressing the F5 key.
Save the script as main.py or with any other name with a “.py” filename
extension.
You should now see the sensor output on the Shell of Thonny IDE as shown
in the image below.
Set the pins for communicating with MAX6675. The Raspberry Pi Pico pins
connected to SCK and CS pins are set as output. The SO pin is connected to
GPIO4 as set as input. This pin will carry the temperature data from the MAX6675
sensor to Pico.
sck = Pin(2, Pin.OUT)
cs = Pin(3, Pin.OUT)
so = Pin(4, Pin.IN)
An object called ‘sensor’ is created and initialized with the input and output pins
that we set in the code above.
Inside the while loop, we obtain the temperature in Celcius using the
‘sensor.read()’ function and print it. The loop continues printing with a delay of 1
second in between prints.
while True:
print("temperature=")
print(sensor.read())
time.sleep(1)
Connecting An LCD
Let us now try to connect a 16×2 LCD with Raspberry Pi Pico to view the output
from the MAX6675 sensor. We shall use I2C communication in Raspberry Pi Pico
for interfacing the LCD.
We need to install the appropriate MicroPython module for the LCD display to
work. Kindly follow our guide to interface Raspberry Pi Pico with LCD to learn
more about installing the library.
After the library scripts are installed, upload the following code to your Raspberry
Pi Pico and save it as ‘main.py’.
I2C_ADDR = 0x27
I2C_NUM_ROWS = 2
When the code is successfully uploaded, you must see the temperature displayed
on the LCD as shown in the image below.
Code explanation
After importing the libraries for I2C LCD, we set the I2C address and set the rows
and columns of our LCD. You can find the I2C address of your LCD which is
discussed in the LCD interfacing guide that is linked above. Note that if you are
using a 20×4 LCD, set ‘I2C_NUM_ROWS= 4’ and ‘I2C_NUM_COLS = 20’.
I2C_ADDR = 0x27
I2C_NUM_ROWS = 2
I2C_NUM_COLS = 16
An object called ‘i2c’ is initialized with GPIO0 as the SDA pin and GPIO1 as the
SCL pin for the LCD. An ‘lcd’ object is also created with the parameters specifying
the I2C address, rows, and columns.
Finally, in the while loop, we print the value of the temperature obtained from the
MAX6675 sensor.
lcd.putstr("Temperature={}C".format(int(sensor.read())))
Troubleshooting
What if the distance between MAX6675 and Raspberry Pi Pico is more than the
wires provided with the sensor? MAX6675 IC and the point where the
thermocouple wires are attached to the MAX6675 board should be at the same
temperature. So avoid extending the thermocouple wires by using additional
wires. The wires used for SPI communication can be elongated up to some extent
if the thermocouple wires are short.
Wrapping Up
MAX6675 is a preferred sensor in industrial applications as it can withstand high
temperatures. There is also an internal temperature sensor in Raspberry Pi Pico
that you can use, although it is not as accurate as MAX6675. We also have guides
on other environmental sensors which you can take a look at:
Thank you for reading. Please leave your thoughts in the comments below.
Recent Posts
MicroPython Web Server Guide | ESP32, Pi Pico W Examples
How to Power Raspberry Pi Pico with Batteries: Li-ion, 9V, 12V, AA, AAA Examples
Abhilekh Das
Comments
Reply
Leave a Reply
Your email address will not be published. Required fields
are marked *
Comment *
Name *
Email *
Website
Post Comment
MicroPython Articles
Technical Articles