Example Code for Raspberry Pi-Read Temperature
Last revision 2025/12/11
The guide on setting up a Raspberry Pi to measure temperature using DFRobot's digital high temperature sensor and K-type thermocouple. It includes hardware and software preparation steps, a wiring diagram, and instructions for installing necessary Python libraries. Readers can follow a step-by-step guide to configure the Raspberry Pi's I2C interface, download and run the driver library, and execute sample code to read temperature data. The guide ensures users can troubleshoot common issues, like reversed probe connections, to obtain accurate temperature readings.
Hardware Preparation
- Raspberry Pi 4 Model B (or similar) * 1
- Gravity Digital High Temperature Sensor (K-type) * 1
- K-Type Thermocouple Probe * 1 (Comes with Gravity Digital High Temperature Sensor)
- Gravity 4P sensor wire (or Dupont wires) * 1 (Comes with Gravity Digital High Temperature Sensor)
Software Preparation
Wiring Diagram
Other Preparation Work
Step 1. Start the I2C interface of the Raspberry Pi. If it is already open, skip this step. Open Terminal, type the following command, and press Enter:
sudo raspi-config
Then use the up and down keys to select “5 Interfacing Options” -> “P5 I2C” and press Enter to confirm “YES”. Reboot the Raspberry Pi.
Step 2. Installing Python libraries and git (networking required). If it is already installed, skip this step. In the Terminal, type the following commands, and press Enter:
sudo apt-get update
sudo pip install wiringpi
Step 3. Download the driver library and run it.
In Terminal, type the following commands
Connect the probe and RaspberryPi to the module according to the connection diagram. The I2C address is fixed to 0x10.
git clone https://github.com/DFRobot/DFRobot_MAX31855.git
cd DFRobot_MAX31855/raspberrypi/python/examples
/read_temp/
python DFRobot_MAX31855.py
Result
If the reading falls as the temperature becoming higher. Positive and negative connections of the probe may be reversed. Try to exchange them.
Was this article helpful?
