Input Devices

Assignments Goals

  • Measure something: add a sensor to a microcontroller board that you have designed and read it
Week's Lectures

Preface

During the years at my workplace, I had to deal with a lot of sensors, ranging from position sensors (accelerometers, gyroscopes, magnetometers) to proximity sensors, environmental gas sensors and so on...

So for this week assignment I wanted to try something different and learn something new. That's why I choose to try a quadrature rotary encoder (like the ones found in digital volume controls), a temperature sensor on I2C, and a neat technique to add touch sensor to a board, using only the internal ADC converter.

Moreover I intend to explain the procedure to etch a complex circuit board with high density pitch (such as the ATMega328P) and a useful tool to plot data in near real time using UART and FTDI converter chip.


Making the GF_SensingBoard

Since the several inputs/outputs needed to attach the sensors I choose, I had to select a different microcontroller than the usual ATTiny44 used in the previous weeks.

My choice fell back to the ATMega328P for several reasons: the first was that we had this component in the FabLab drawers, ready to be used; the second was the high number of I/O pins; the last was that it's the same uC used in the Arduino UNO boards, so the board I'm going to design could possibly be programmed using Arduino IDE if needed.

The components I used in my circuit are:

  • Rotary encoder:
    is the component I desoldered from THIS board
  • I2C Temperature Sensor:
    it's a ST Microelectronics STTS75
  • Copper pads:
    used for touch sensing! Simple and cheap...

The full circuit schematic and layout board I came up with is self-explainatory. The big round pads on the right has been created using the command POLY. The leds on the bottom left are used to signal the rotary encoder position in binary mode. Making a single sided circuit was nearly impossible, so I added two vias, to make a 1.5 sided board (blue signals are wires to achieve the "jumps").

The spacing between the pins of the uC is 8mils, but the minimum clearance I could achieve using the Roland MDX40-A, with the V-tip buring we have in our FabLab, is around 16mils. So I decided to use the Ferric Chloride to etch my board. I know that's not so eco-friendly as using a mill machine, but in this case I couldn't find another solution to overcome the small footprint of the component. Moreover it could be a good motive to document this process as well...

Disclaimer

I have extreme respect for environment and everytime I use chemical etching I go to a electronic distributor near me that provides safe hazardous waste disposal, even if I use less than 5ml of ferric chloride!
I have respect for my safety too, so I pay extreme attention when using nasty chemicals, I wear glasses and lattice gloves.

After creating the board layout, I exported the design as image, using a resolution of 2400 dpi, after hiding every layer other than Top, Pads, Vias, Dimension. Since I'm going to use the Toner Transfer Technique to transfer the board layout on the copper clad, you need to mirror the image before printing on a special paper sheet, called Toner Transfer Paper.

This paper is really glossy and "oily", and when heated permits the toner to detach from the paper and attach on the copper clad. To achieve the actual transfer, I used a hot laminator.

After the design is firmly imprinted on the copper, it's time to put it in the ferric chloride and leave it in there until the etching is done (about 10-15 minutes).

Eventually I sprayed the board with a coat layer, to protect the copper from oxidation, with a specific PCB paint that dissolves when soldered.

Work files links

Full Eagle Cad schematic and board layout of the GF_SensingBoard
GF_SensingBoard.zip
Firmware for GF_SensingBoard, with Atmel Studio project and CrossPack Makefile
firmware.zip

Rotary Encoder

After a bit of research on the inner working of the rotary encoder, I ended up on THIS website, and "borrowed" this simple javascript applet to better explain the digital signals generated by it.

Essentially, the blue wheel, is the Common signal, usually connected to GND. Pin 1 and 2 are connected to the microcontroller, and the relative internal pull-up resistors are enabled. The position in which Pin 1 and 2 are in the white area is called Retain, and you can feel it when rotating the shaft because of the typical click sound.


The code I used to detect the rotation, using Interrupts on edge changes is the following:


                        
                    

Temperature Sensor

The STTS75 is a high precision temperature sensor, based on CMOS technology, and uses a digital communication interface based on I2C. This is a commonly used half-duplex communication bus, based on 2 digital lines: SDA and SCL.

The full specification of I2C bus are described HERE, whilst the full technical details and electrical characteristics of STTS75 can be found HERE.

The device has a set of registers, used to control its behavior and to obtain temperature readings. The Register Address, made of 7 bit, is used to identify the device and to read/write data, through the digital interface. The 3 least significative bits of the address, are harware configurable, using a pull-up or a pull-down resistor. For my board I set these bits to 1.

To read data contained in the registers, you first need to "point" to them before the actual read operation, and consecutive read operations will continue to point to the same register. If you want to read/write to a different register, you need to point to the new register first.

The most relevant registers are:

  • CONF (01h):
    used to control standby state, datarate and functioning mode of the device
  • TEMP (00h):
    contains the measured temperature value of the sensor

When the device is turned on, the pointed register will be the TEMP (00h) one. So it's possible to read the temperature value immediately, with the procedure described in the following image

where:

  • AddressByte + R is the device address, with LSB = 1 [0x9F]
  • DATA is the value/s of the read register/s

To derive the actual temperature value in Celsius degrees, stored in the TEMP register, we need to execute the following mathematical and binary operations:

int digitalReading = ((TEMP_MSB << 8) | TEMP_LSB) >> 4;
float temperature = ((float) digitalReading * 0.0625);

The code I used to communicate over I2C bus and to read the temperature, is the following:


                    

Touch sensing

In order to explore further simple interaction and sensing on embedded systems, I decided to look into capacitive touch buttons. To add these in your design you usually need a separate chip for capacitive touch sensing. Knowing a bit of theory of operation of the internal ADC peripheral of the uC, you can however use a normal microcontroller to do the job, even using only a single pin and resistor.

Atmel actually provides a library for doing capacitive touch sensing on Atmel microcontrollers, it's called QTouch. Unfortunately, it's closed source. So I searched a bit on Google, and found out this Microchip application note and this web pages, that explain quite in detail the operation needed to use the internal ADC to achieve capacitive touch features.

The theory works quite well, but I noticed some crosstalk noise between two of the pads. I guess this is due to the traces routing, that should be more isolated than they are now. So I added a software calibration procedure to overcome a little bit this problem.

The code I used to implement the touch sensing, is the following:


                    

Plotting data using SerialOscilloscope

Having to deal with quick changing values, debugging through LEDs or text based serial port terminal could be really difficult. So I usually use a free and opensource program called SerialOscilloscope, that plots in nearly real time data feed through serial port.

If you want to use printf function with floating point numbers, you have to add these compiler flags in Makefile!

-Wl,-u,vfprintf -lprintf_flt -lm

More info about printf can be found here

It's quite a useful piece of software, that can visualize 3 measures at a time, as if it was a real oscilloscope. The only thing you need to do to use it, is to print on the serial port the data you want to draw, separated by commas.

The top side of the image shows the data coming from the serial port, as comma separated values.

The left side of the image shows the data coming from the touch sensors. As you can see, the distinction between pressed/not pressed is quite clear, but there's some crosstalk on one of the pads (the red line).

The right side of the image shows the data coming from the rotary encoder (the green line) and the temperature sensor (the red line).


Assignments Outcomes

  • Demonstrate workflows used in circuit board design and fabrication
  • Implement and interpret programming protocols

Have you:

described your design and fabrication process using words/images/screenshots
explained the programming process/es you used and how the microcontroller datasheet helped you
explained problems and how you fixed them
included original design files and code