Week | 11


Input Devices


How I’m designing a board, adding a sensor and reading from it.


24 April 2018 14:07:

This week’s assignment is again on electronics and about learning how to read a sensor from a board. Since I was away for more than 10 days, I would have loved to make one single assignment for both weeks (input and output) but, unfortunately, it is not seen as the best practice, so I decided to “accomplish” both, the output and input assignments, with a simple task each. For the input, I decided to use Neil’s example the hello.temp.45 board.

Designing/Redrawing the board


Based on Neil’s hello.temp.45 board, I have used Eagle to redesign it. For Designing, Routing, Checking and Exporting, I have followed the same steps already documented on Week 6 - Electronics Design.

Here are my files: Eagle Schematic, Eagle Board, Traces Image, Interior Image,Traces .rml and Interior .rml.

Milling the board


I had a minor issue with the milling and had to manually split a connected path by hand, using a cutter. Though I have used the right clearance (16mil), one path was connected to the other, as you can see in detail below:

Stuffing the board


I have, then, soldered all the components of the board, using the schematics and references as guides. I have already documented some of the soldering process here on week 4.

Programming the board


I used my previously done FabISP to program the board:

I’ve copied Neil’s makefile hello.temp.45.make and C code hello.temp.45.c to a local directory and used my FabISP to program the board.

When I tried to use Neil’s file to compile, by typing the following command:

make -f hello.temp.45.make

I would get an error: Error 1: hello.temp.45.make:13: *** missing separator. Stop.

Apparently Neil’s code is with spaces instead of tabs in some parts and C requires these to be corrected. I had to open the files on an editor and made sure to replace all spaces by tabs in the lines mentioned in the error.

Here are the corrected files: hello.temp.45.make and hello.temp.45.c.

Which allowed me compile it:

Then I was able to flash the board by typing:

sudo make -f hello.temp.45.make program-usbtiny

and the result:

Reading the board


I used Neil’s Python code hello.temp.45.py to read the temperature from the board.

First, I had to check from which serial port to read from. To list the devices, I’ve typed in terminal:

ls /dev/tty.*

And here’s the list I got in return:

The port I want to use is the “/dev/tty.usbserial-FT9P06BY”

I was using Atom as an editor and to run Neil’s script, but had a hard time in properly changing the code in order to add the serial address. So, as a recommendation from a classmate, instead of changing the serial inside Neil’s code, which is a less elegant option, I have ran the .py file through terminal, naming the serial port for communication, by typing the following:

python hello.temp.45.py "/dev/tty.usbserial-FT9P06BY"`

And it worked well.

Here’s a video of the board working. In order to “dramatise” the temperature variation, I’ve used a hot air blower to warm my finger (you can hear the noise on in the background):


The main component of the board is a thermistor, a sensor (sort of a resistor) that transforms temperature to resistance. NTC stands for Negative Temperature Coefficient, for sensing negative temperatures made with a semi-conducting material which resistance goes up with temperature. So, when temperature varies, the conductivity of the material on the thermistor also varies.

This board has 4 resistors with one of them (the NTC) being variable. All the resistors are fed by voltage and the temperature result is given by constantly reading the difference in voltage between the resistors. Two pins of the micro-controller receive the data (one for each voltage reading). The chip converts analog (voltage) to digital (numbers) (this system is called ADC - Analog to Digital Converter), measures the distance between the two voltages and amplifies it.

The Py code the code is using imports the following libraries:

Tkinter a Python GUI (Graphic User Interface) to Tcl (programming language)/Tk (a widget toolkit for GUI’s):

      `from Tkinter import *`

Logarithm from Numpy. This is a mathematical function to calculate Natural logarithm of x where x belongs to all the input array elements. I suppose this is used to store the information

      `from numpy import log`

Serial. which will give access to the serial port to enable serial communication, so we can actually see the information being output from the board.

      `import serial`

As far as my small coding knowledge goes (specially in Py), I understand that the code used is reading each resistor (“bytes” in the code), starting the Analog to Digital conversion, waiting for it to complete and printing its results.

You can find the further information about this board in Neil’s description here at 32m30s.