Project 1

Temperature Reader

Temperature output project using a python script which outputs the temperature to two TIL311 segment displays. The segment displays are located on a breadboard and is controlled via GPIO output pins from a raspberry pi 4. The TIL311 are no longer manufactured, originally made by Texas Instruments. These are from a project I completed in 1983, I was amazed they still functioned.


TIL311_1.pdf

To download the python script click on the word document. Copy contents to a text document and rename with a .py extension.

Project 1.docx

The TIL311 are quite easy to setup. the inputs DCBA represent binary 8421. You will need to supply a strobe t latch on the data. For this project I have not used the Right and Left decimal points. Check out the data sheet for all the info. I have connected together "pin 1 to pin 14" and also connected "Pin7 to Pin 8" Pin 5 is the latch strobe input and that needs to go from high to low to read the input.

To control the TIL311s I have written a python script. This is my first attempt at this so apologies if this could be done in a different manner. I will place the script below and insert comments where appropriate.

==========================================================

# FXV300 This script reads GPU temp

# and writes values to two TIL311 segment displays

# GPU and CPU are on the same SoC so temperature should be similar.

# could not find a system call to read CPU temp

#PIN 2 LATCH DATA INPUT B 0010

#PIN 3 LATCH DATA INPUT A 0001

#PIN 5 LATCH STROBE INPUT _[ ]_

#PIN 12 LATCH DATA INPUT D 1000

#PIN 13 LATCH DATA INPUT C 0100

# this section imports some system calls

import RPi.GPIO as gpio

import os

import time

import binascii


# this part sets up the GPIO pins as output

# The first value is the GPIO pin label, and the comment is the physical pin value


gpio.setmode(gpio.BCM)

gpio.setup(6, gpio.OUT) #pin 31

gpio.setup(13, gpio.OUT) #pin 33

gpio.setup(19, gpio.OUT) #pin 35

gpio.setup(26, gpio.OUT) #pin 37


gpio.setup(8, gpio.OUT) #pin 24

gpio.setup(7, gpio.OUT) #pin 26

gpio.setup(1, gpio.OUT) #pin 28

gpio.setup(12, gpio.OUT) #pin 32


gpio.setup(25, gpio.OUT) #latch pin 22



while True:


def measure_temp():

temp = os.popen("vcgencmd measure_temp").readline()

return (temp.replace("temp=",""))

x=measure_temp()

print (x)

y=x[0] #1st char of xx'c

z=x[1] #2nd char of xx'c

v1=ord(y)

v2=ord(z)

# so v1 and v2 should have the ascii value for the two digits

print (v1), print(v2) # this is the ASCII value of the two numbers

time.sleep(5)

print('waiting 5 seconds')

#get date and time

from datetime import datetime

now = datetime.now()

print(now) # print date and time


# First TIL311 showing 10s

# have started with the value 3 as temperature unlikely to be below 30C

# I could not find how to output all 4 bits to the GPIO via one call

# any suggestions welcome

if v1 == 51: # ascii 51 hex 33 dec 3

gpio.output(6, gpio.HIGH)

gpio.output(13, gpio.HIGH)

gpio.output(19, gpio.LOW)

gpio.output(26, gpio.LOW)


if v1 == 52: # ascii 52 hex 34 dec 4

gpio.output(6, gpio.LOW)

gpio.output(13, gpio.LOW)

gpio.output(19, gpio.HIGH)

gpio.output(26, gpio.LOW)


if v1 == 53: # ascii 53 hex 35 dec 5

gpio.output(6, gpio.HIGH)

gpio.output(13, gpio.LOW)

gpio.output(19, gpio.HIGH)

gpio.output(26, gpio.LOW)

if v1 == 54: # ascii 54 hex 36 dec 6

gpio.output(6, gpio.LOW)

gpio.output(13, gpio.HIGH)

gpio.output(19, gpio.HIGH)

gpio.output(26, gpio.LOW)


if v1 == 55: # ascii 55 hex 37 dec 7

gpio.output(6, gpio.HIGH)

gpio.output(13, gpio.HIGH)

gpio.output(19, gpio.HIGH)

gpio.output(26, gpio.LOW)


if v1 == 56: # ascii 56 hex 38 dec 8

gpio.output(6, gpio.LOW)

gpio.output(13, gpio.LOW)

gpio.output(19, gpio.LOW)

gpio.output(26, gpio.HIGH)

if v1 == 57: # ascii 57 hex 39 dec 9

gpio.output(6, gpio.HIGH)

gpio.output(13, gpio.LOW)

gpio.output(19, gpio.LOW)

gpio.output(26, gpio.HIGH)


# second TIL311 showing 0-9 decimal

if v2 == 48: # ascii 48 hex 30 dec 0

gpio.output(8, gpio.LOW)

gpio.output(7, gpio.LOW)

gpio.output(1, gpio.LOW)

gpio.output(12, gpio.LOW)

gpio.output(25, gpio.HIGH)

gpio.output(25, gpio.LOW)


if v2 == 49: # ascii 49 hex 31 dec 1

gpio.output(8, gpio.HIGH)

gpio.output(7, gpio.LOW)

gpio.output(1, gpio.LOW)

gpio.output(12, gpio.LOW)


gpio.output(25, gpio.HIGH)

gpio.output(25, gpio.LOW)


if v2 == 50: # ascii 50 hex 32 dec 2

gpio.output(8, gpio.LOW)

gpio.output(7, gpio.HIGH)

gpio.output(1, gpio.LOW)

gpio.output(12, gpio.LOW)

gpio.output(25, gpio.HIGH)

gpio.output(25, gpio.LOW)



if v2 == 51: # ascii 51 hex 33 dec 3

gpio.output(8, gpio.HIGH)

gpio.output(7, gpio.HIGH)

gpio.output(1, gpio.LOW)

gpio.output(12, gpio.LOW)

gpio.output(25, gpio.HIGH)

gpio.output(25, gpio.LOW)


if v2 == 52: # ascii 52 hex 34 dec 4

gpio.output(8, gpio.LOW)

gpio.output(7, gpio.LOW)

gpio.output(1, gpio.HIGH)

gpio.output(12, gpio.LOW)

gpio.output(25, gpio.HIGH)

gpio.output(25, gpio.LOW)

if v2 == 53: # ascii 53 hex 35 dec 5

gpio.output(8, gpio.HIGH)

gpio.output(7, gpio.LOW)

gpio.output(1, gpio.HIGH)

gpio.output(12, gpio.LOW)

gpio.output(25, gpio.HIGH)

gpio.output(25, gpio.LOW)


if v2 == 54: # ascii 54 hex 35 dec 6

gpio.output(8, gpio.LOW)

gpio.output(7, gpio.HIGH)

gpio.output(1, gpio.HIGH)

gpio.output(12, gpio.LOW)

gpio.output(25, gpio.HIGH)

gpio.output(25, gpio.LOW)

if v2 == 55: # ascii 55 hex 35 dec 7

gpio.output(8, gpio.HIGH)

gpio.output(7, gpio.HIGH)

gpio.output(1, gpio.HIGH)

gpio.output(12, gpio.LOW)

gpio.output(25, gpio.HIGH)

gpio.output(25, gpio.LOW)


if v2 == 56: # ascii 56 hex 36 dec 8

gpio.output(8, gpio.LOW)

gpio.output(7, gpio.LOW)

gpio.output(1, gpio.LOW)

gpio.output(12, gpio.HIGH)

gpio.output(25, gpio.HIGH)

gpio.output(25, gpio.LOW)

if v2 == 57: # ascii 57 hex 37 dec 9

gpio.output(8, gpio.LOW)

gpio.output(7, gpio.LOW)

gpio.output(1, gpio.LOW)

gpio.output(12, gpio.HIGH)

gpio.output(25, gpio.HIGH)

gpio.output(25, gpio.LOW)


# Comments welcome, please bear in mind I am new to all this and only bought my first PI 4 - 1st August 2020

# You can post comments on the Raspberry forum (FXV300) or via Youtube (FrankVella300)