Table of Contents
Introduction
Temperature data is possibly the most common information collected by scientists, engineers, and hobbyists. With a TINKERplate, it is possible to connect up to eight temperature sensors to the Digital I/O connector. What follows is some examples of how to read and display the temperature from these sensors.
What You'll Need
- A DS18B20 temperature sensor. You can use the one shipped with the TINKERkit that looks like:
And plug it into the mini breadboard which is also in the kit:
If you have never used a breadboard before, here is a tutorial you may find useful: https://www.sciencebuddies.org/science-fair-projects/references/how-to-use-a-breadboard
Or you can use a DS18B20 that has wires attached like the kind we sell here. - A TINKERplate attached to a programmed Raspberry Pi
Steps
Connections
- Connect the sensor to channel 1 of the Digital I/O port on the TINKERplate.
If using parts from the TINKERkit then your setup should look like:
If using a wire sensor then your setup would look like:
Code 1 - Simple
Use the Thonny IDE again to write and run the program as shown below. The output is displayed in the window labeled "Shell" on the bottom.
Again, if you don't feel like typing, here is the code you can copy and paste:
1 2 3 4 5 6 7 8 9 |
import piplates.TINKERplate as TINK #load TINKERplate module import time #load time functions d = '\u00b0' #create the degree symbol TINK.setMODE(0,1,'temp') #setmode while(True): #loop forever t=TINK.getTEMP(0,1) #fetch temperature #print to the console print('Time:',time.ctime(),' - Temperature is:',t,d+'F') time.sleep(1) #delay 1 second |
The above code can be downloaded from github by typing the following instructions on the command line:
- git clone https://github.com/pi-plates/TINKERplate-Projects.git
- cd TINKERplate-Projects
- python3 SimpleTemp.py
Code 2 - a Thermometer
Let's make things a -little- more interesting by displaying the temperature on a Meter panel. Again, use Thonny and enter the following program:
This time after clicking the RUN button a panel meter will pop up showing the temperature in large colorful characters:
Here is the code again:
1 2 3 4 5 6 7 8 9 10 11 12 |
import piplates.TINKERplate as TINK #load TINKERplate module import time #load time functions d = '\u00b0' TINK.setDEFAULTS(0) #set all digital channel to defaults. TINK.setMODE(0,1,'temp') #Set channel 1 to read a temperature sensor time.sleep(1) #wait 1 second for stabilization TINK.openMETER() #Create a display meter on the screen TINK.setTITLE('My Thermometer') while(True): temp=TINK.getTEMP(0,1) TINK.setMETER(temp,d+'F','Channel 1:') time.sleep(1) |
The above code can be downloaded from github by typing the following instructions on the command line:
- git clone https://github.com/pi-plates/TINKERplate-Projects.git
- cd TINKERplate-Projects
- python3 aThermometer.py