TCLab Lab 1: Coding a relay controller

The purpose of this first laboratory session is to verify that you can interface and interact with the TCLab hardware, and familiarize you with the TCLab library. The first exercise will be to code a rudimentary relay (also called ‘on-off’ or thermostat) controller for one of the two heaters.

Before you begin, you should be familiar with the following reading meterials:

Exercise 1. Download and install TCLab.py

Execute the following cell to download and install the TCLab.py python library.

!pip install tclab --upgrade

Exercise 2. Verify that your hardware and software are working correctly.

The following cell should cause the LED on the TCLab shield to light up to 100% maximum brightness.

from tclab import TCLab

with TCLab() as lab:
    lab.LED(0)

Exercise 3. Turn on the heaters for 120 seconds and log temperature response.

For this exercise, write a code cell that turns on heater 1 at 100% power, then log the temperature response once per second for 120 seconds. The output of the cell should report the time, power level, and temperature for each measurement. You may wish to consult 01_Understanding_TCLab notebook for relevant code examples. You will need the clock function from tclab for this exercise.

# put your code here.

Exercise 4. Code an on-off controller.

Code an on-off controller for a setpoint of 40 degrees C using heater 1 as the manipulated variable, and temperature 1 as the measured variable. Operate the controller for at least 5 minutes (600 seconds), reporting time/power/temperature measurements every 2 seconds.

# put your code here.

Exercise 5. Analysis

Examine the results of the previous exercise and answer the following questions.

  1. Approximately how much time elapses between power on and power off events?

  2. What is the approximate duty cycle (i.e, fraction of time the heater is in the ‘on’ state) once the initial start-up period has passed.

  3. What is the size of the oscillation around the setpoint? Why does this occur?