Tim Bruening - Fab Academy 2016

Week #16 - Interface and Applications Programming

In the sixteenth week we were tasked with creating code to interface with an input &/or an output.

Here is a list of tasks as I see them for the sixteenth week.

Choose a previous PCB to work with.

I choose to work with the hello.temp.45.py circuit from week eleven.  This board has an FTDI interface.  I will be able to see the results on the PC.

The following is the modified version of the original file.

I highlighted items in red that I will discuss further. I used standard strikethrough/underline methods to show what I removed or added to the file.

-------------------------------------------------
#
# hello.temp.45.py     #tim.py
#
# receive and display temperature
# hello.temp.45.py serial_port
#
# Neil Gershenfeld
# CBA MIT 3/27/12
#
# (c) Massachusetts Institute of Technology 2012
# Permission granted for experimental and personal use;
# license for commercial sale available from MIT
#

from Tkinter import *
from numpy import log
import serial

WINDOW = 600 # window size
eps = 0.5 # filter time constant
filter = 0.0 # filtered value

def idle(parent,canvas):
   global filter, eps

   #
   # idle routine
   #
   byte2 = 0
   byte3 = 0
   byte4 = 0
   ser.flush()
   while 1:
      #
      # find framing
      #
      byte1 = byte2
      byte2 = byte3
      byte3 = byte4
      byte4 = ord(ser.read())
      if ((byte1 == 1) & (byte2 == 2) & (byte3 == 3) & (byte4 == 4)):
         break
   low = ord(ser.read())
   high = ord(ser.read())
   value = 256*high + low
   if (value > 511):
      value -= 1024
   V = 2.5 - value*5.0/(20.0*512.0)
   R = 10000.0/(5.0/V-1.0)
   # NHQ103B375R5
   # R25 10000 (O)Document the process and list any problems encountered.
   # B (25/85) 3750 (K)
   # R(T(C)) = R(25)*exp(B*(1/(T(C)+273.15)-(1/(25+273.15))))
   B = 3750.0
   R25 =  10000.0
   T = 1.0/(log(R/R25)/B+(1/(25.0+273.15))) - 273.15
  
   F=(T*(9.0/5.0))+32
   filter = (1-eps)*filter + eps*F

   x = int(.2*WINDOW + (.9-.2)*WINDOW*(filter-20.0)/10.0)
   canvas.itemconfigure("text",text="%.2f"%filter)
   canvas.coords('rect1',.2*WINDOW,.05*WINDOW,x,.2*WINDOW)
   canvas.coords('rect2',x,.05*WINDOW,.9*WINDOW,.2*WINDOW)
   canvas.update()
   parent.after_idle(idle,parent,canvas)

#
#  check command line arguments
#
if (len(sys.argv) != 2):
   print "command line: hello.temp.45.py serial_port"
   sys.exit()
port = sys.argv[1]
#
# open serial port
#
ser = serial.Serial(port,9600)
ser.setDTR()
#
# start plotting
#
root = Tk()
root.title('hello.temp.45.py (q to exit)')
root.bind('q','exit')
canvas = Canvas(root, width=WINDOW, height=.25*WINDOW, background='white')
canvas.create_text(.1*WINDOW,.125*WINDOW,text=".33",font=("Helvetica" "times", 24),tags="text",fill="#0000b0" "#b22222")
canvas.create_rectangle(.2*WINDOW,.05*WINDOW,.3*WINDOW,.2*WINDOW, tags='rect1', fill='#b00000' '#d8bfd8')
canvas.create_rectangle(.3*WINDOW,.05*WINDOW,.9*WINDOW,.2*WINDOW, tags='rect2', fill='#0000b0' '#dda0dd')
canvas.pack()
root.after(100,idle,root,canvas)
root.mainloop()

 
---------------------------------------------------------------------------------------

EDIT #1

The first edit was the name of the file: tim.py.  You can also see the original colors and fonts of the temperaure window.

smiley face

COMMENT #1

   # NHQ103B375R5     This is the serial number of the chip used in the example.

   # R25 10000 (O)         At 25°C the chip will have 10K ohms of resistance.

COMMENT #2

T =1.0/(log(R/R25)/B+(1/(25.0+273.15))) - 273.15      The first part of this formula calculates degrees Kelvin.  subtracting 273.15 converts it to celsius.

EDIT #2

F=(T*(9.0/5.0))+32      This formula I inserted converts the Celsius into Fahrenheit. The value in "F" is sent to the readout box.
When this formula was first inserted I entered 9/5 and the readouts were incorrect.

smiley face

It was discovered that the formula turned 9/5 into 1.0. The value was truncated.
When I entered the formala as 9.0/5.0 it was turned into 1.8, the correct value was then displayed in the box.


smiley face

EDIT #3

"Helvetica" "times"      Here I changed the font from Helvetica to Times.


smiley face

EDIT #4

"#0000b0" "#b22222"     This changes the text color from Blue to Firebrick.

smiley face

EDIT #5 

'#b00000' '#d8bfd8'     This changes the left box color from Red to Thistle.

smiley face

EDIT #6

'#0000b0' '#dda0dd'     This changes the right box from Blue to Plum.

smiley face

Document the process and list any problems encountered.

The only problem I ran into was the one I discussed about the truncating of values when a whole number instead of a decimal is inserted into a formula.

In general I did have a bit of fun learning some of the meanings of the codes that we are working with.  This should help me with my final programming.

Here is my "Hero shot" of the final appearance of the circuit.

smiley face

Tim's Files:

Color Files

  • Blue color chart showing hex equivalent
  • Red color chart showing hex equivalent
  • Python Files

  • Original Python file
  • Tim's Python file

  • Back to index