First go through the VS Code setup page as we will be using this IDE in the walkthrough. However, you can use any other IDE you want.
This walkthrough guides you through installing the EdgePi SDK and creating and running a simple .py
script to measure temperature using a thermocouple and the TC port on the EdgePi.
Open the explorer
If needed, enter the password pi
again and accept the permissions prompt
Install the virtual environment (venv
) package
a. It's best to have projects and the associated packages, only installed with-in the confines of the virtual environment.
b. $ sudo apt-get install python3-venv
to install the venv package
Create a project folder within a venv
a. $ python -m venv simpleproject
and you should see the folder in the side bar
b. Now activate your simple project venv with $ source simpleproject/bin/activate
c. You should now be within your virtual environment workspace
The EdgePi SDK documentation can be found on Py Pi here.
$ python3 -m pip install edgepi-python-sdk
to install the SDKIn order to set temperature fault thresholds using this module, please refer to the table below for accepted temperature values by thermocouple type. Attempting to set a temperature threshold outside of your thermocouple type's range will raise an exception.
Thermocouple Type | Temperature Range (°C) | |||
---|---|---|---|---|
Cold Junction | Thermocouple | |||
Low | High | Low | High | |
Type B | 0 | 125 | 250 | 1820 |
Type E | -55 | 125 | -200 | 1000 |
Type J | -55 | 125 | -210 | 1200 |
Type K | -55 | 125 | -200 | 1372 |
Type N | -55 | 125 | -200 | 1300 |
Type R | -50 | 125 | -50 | 1768 |
Type S | -50 | 125 | -50 | 1768 |
Type T | -55 | 125 | -200 | 400 |
Plug the thermocouple into the correct TC port (29,30), please refer to the label.
Ensure that the wire polarity is correct when attaching the thermocouple to the EdgePi device.
In VS Code to go the simpleproject folder and create a new .py file called TC_Read.py
Open up this file and copy in the following code block.
from edgepi.tc.edgepi_tc import EdgePiTC
from edgepi.tc.tc_constants import ConvMode
# initialize thermocouple
edgepi_tc = EdgePiTC()
# set thermocouple to single sample mode
edgepi_tc.set_config(conversion_mode=ConvMode.SINGLE)
# make a single temperature measurement
temps = edgepi_tc.single_sample()
print(temps)
Run the code and you should see the temperature of the TC print out.
The format is (Cold Junction Voltage, Linearized Temperature)
Congratulations you just set up your EdgePi to read a thermocouple from the TC input.