Set Up a Raspberry Pi I2C Temperature Sensor

by | Jul 17, 2016

Atlas Scientific Temperature Sensor KitThere are several temperature sensors that are available for your Raspberry Pi one of the most popular being the DS18B20, however, if you are looking for an I2C connected temperature sensor then the Atlas Scientific RTD Temperature sensor is an excellent option. If your project already involves the use of other I2C sensors then this can be easily added in parallel without using any additional GPIO pins on your Pi. This sensor also provides onboard logging capabilities and provides readouts in either Celsius, Fahrenheit or Kelvin, with the addition of a thermowell you will be able to insert your temperature probe into your plumbing.

To configure the Pi I am assuming that you are running the latest version of Raspbian and have the ability to connect to your Pi either through SSH with putty and FTP with Filezilla or directly with a keyboard and monitor. If you haven’t set-up your Pi yet then check out my getting started section.




In this tutorial I will be using the following materials:


The first thing we need to do is enable the I2C modules on the RPi. This is done by entering the following at the command prompt to start the configuration tool.


select option 9 – Advanced Options
select option A7 – I2C
select “Yes” for all the questions and reboot the RPi


Note: The GPIO pins 2&3 on the Pi have now been configured as the Serial Data Line (SDA) and Serial Clock Line (SCL) for use by the I2C protocol.


After the reboot open the terminal and ensure that all the Raspbian packages are up to date, enter the following


Next, check/add the i2c tools package



This should produce the following without the sensor attached.


Raspberry Pi I2C detect screen capture


Now that we have our I2C module working correctly we can go ahead and connect our temperature sensor. When describing the physical pin connections I will be following the GPIO pin numbering convention shown below.


Raspberry Pi GPIO pin number layout


Firstly we need to get the temperature circuit into the correct mode, when delivered the temperature circuit will be in UART (serial) mode, the temperature circuit has to be manually switched from UART mode to I2C mode. When this is done the temperature circuit will have its I2C address set to 102 (0x66).

Using your breadboard perform the following actions

  • Cut the power to the device
  • Disconnect any jumper wires going from TX and RX to the Pi
  • Short the PRB pin to the TX pin
  • Power the device
  • Wait for LED to change from Green to Blue
  • Remove the short from the probe pin to the TX pin
  • Power cycle the device


Atlas Scientific Temperature sensor I2C Manual Change Flow Diagram


The device is now I2C mode.

The Pi and temperature circuit are now configured so we can go ahead and connect it all together


Atlas Scientific Temperature Sensor to Raspberry Pi Circuit diagram


Assuming that all of the parts are now mounted on your breadboard

  • Connect the GND pin of the temperature circuit to the ground pin of your RPi.
  • Connect the TX(SDA) pin to GPIO pin 2.
  • Connect the RX(SCL) pin to GPIO pin 3.
Note: Do Not Use jumper wires for these connections or your readings will not be accurate.Atlas Scientific Temperature Sensor Correct Connection
Atlas Scientific Temperture Sensor Incorrect Connection


  • The PRB and PGND pins should be connected via your breadboard to the center and shield pins of your BNC connector.
  • Finally, power your temperature circuit by connecting the Vcc pin to the +3.3V pin.


You can now run a quick test to prove that we are set up correctly, from the command prompt enter the following:



you should see the following response, if not then check your connections, ensure the light on the temperature circuit is blue and reboot your Pi.


Raspberry Pi with 4 sensors I2C detect screen capture


In the image above I have 4 sensors connected to my Pi, the Temperature sensor connection is indicated by Hex value 66. The factory preset address for the pH sensor is 102 or 66 in hexadecimal as mentioned above, if you have more than 1 temperature circuit connected then you will need to specify a different value. To do this we need to add some python code to our Pi.

Atlas Scientific provides the python code that I will be using here for interfacing with the temperature circuit.

We start by importing the required python modules



Next, we add the class code to interface with the temperature circuit (or any other Atlas Scientific circuit for that matter)



Finally, we will add our main program



All of this python code is available on my HydroPi GitHub repository.

We now transfer our code to our chosen folder on the Pi using an FTP client and then run the program.


Atlas Scientific Temperature Sensor Code screen capture


The screenshot above shows that we are ready to start sending commands to our temperature circuit, to confirm that the sensor is now fully functioning we will enter the following command



This will poll the sensor every 2 seconds and return the result until a ctrl-c command is entered as shown below, to stop the program enter ctrl-c again.


Atlas Scientific Temperature Polling screen capture


With the sensor now working, there are also a series of other commands that we now have available to us to configure our probe. Above I have shown how to change the reading from Celsius to Fahrenheit.


Enable/disable the LED on the Temperature circuit:

L,1 – LED enable
L,0 – LED disable
L,? – Query the LED


Set the temperature scale required for output:

S,C – Sets the output of the sensor to Celsius (Default)
S,F – Sets the output of the sensor to Fahrenheit
S,K – Sets the output of the sensor to Kelvin
S,? – Queries the output temperature scale.


Take a single reading:

R – Returns a single result



The temperature circuit can be calibrated using a single point calibration. While this is possible, RTD temperature sensors have very predictable behavior at varying temperatures, because of this fact calibration is not absolutely required.

Cal,n – Where n is any temperature
Cal,clear – Clears all calibration data
Cal,? – Query the calibration


Circuit Address Change:

I2c,n – n is the new decimal address

Changes to the address of the circuit will cause a loss of connectivity until the python script is restarted with the new address.


Info, Status, Low Power and Factory Reset:

I – Device information
STATUS – Reports reason for last reboot and Vcc voltage
FACTORY – Factory reset. This will not change the communications protocol back to UART.
SLEEP – Enter a low power sleep state.

Note: Any command sent to the temperature circuit will wake it but 4 readings should be taken before considering them to be accurate.


The Temperature sensor circuit also provides for some additional settings that allow for the use of its internal data logger (up to 50 readings) and the protocol lock feature. More information on the configuration of the temperature circuit is available here.

There we have it, you have now configured your Pi to interface with the Atlas Scientific Temperature Sensor.

If you have any thought’s about this article, improvements or errors let me know in the comments below and if you found this helpful, why not share it with others.

Pin It on Pinterest

Share This