This notebook contains material from CBE32338; content is available on Github.

1.11 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:

1.11.1 Procedures

  1. Select a lab partner. The lab sessions are often more productive when bringing the experiences of two students together to work on a task. The interaction between lab partners also enchances the learning opportunity.
  1. Check out a TCLab kit. The kit consists of
    • plastic container
    • Arduino device with the TCLab shield installed
    • 5 watt USB power supply
    • USB power cable
    • USB data cable
    • equipment log sheet
  1. Before going further, sign and date the equipment log sheet.
  1. Note that you may need to check out a power strip to share with other groups using the same lab bench.
  1. Download a copy of this notebook to your laptop, and complete the exercises shown below. Under each exercise heading, add as many text and code cells as needed to complete the exercise. The results should be embedded in the notebook. Be sure to 'save-as-you-go' to avoid losing your work.
  1. Add any relevant notes to the equipment log and return the kit to equipment at the front of the lab. Return any malfunctioning kit to the instructor for repair.
  1. Submit your completed lab notebook via Sakai. The notebook should contain the name of both lab partners. Both partners should submit a copy of the notebook.

1.11.2 Exercise 1. Download and install TCLab.py

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

In [1]:
!pip install tclab --upgrade
Requirement already up-to-date: tclab in ./anaconda3/lib/python3.7/site-packages (0.4.9)
Requirement already satisfied, skipping upgrade: pyserial in ./anaconda3/lib/python3.7/site-packages (from tclab) (3.4)

1.11.3 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.

In [2]:
from tclab import TCLab

with TCLab() as lab:
    lab.LED(0)
TCLab version 0.4.9
Arduino Leonardo connected on port /dev/cu.usbmodem144101 at 115200 baud.
TCLab Firmware Version 1.01.
TCLab disconnected successfully.

1.11.4 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 TCLab Python Package notebook for relevant code examples. You will need the clock function from tclab for this exercise.

In [2]:
# put your code here.

1.11.5 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.

In [3]:
# put your code here.

1.11.6 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?

Write your answers in this markdown cell.

In [ ]: