# Week 9: Input Devices, or My Board Hates Me <a href="../index.html">Back to Home</a> This week we had to incorporate a sensor that reads some sort of signal into our circuit boards. My interest was immediately piqued when Neil mentioned dielectric spectroscopy: in general spectroscopy calls to mind expensive equipment, so making a super simple device that can do some rudimentary differentiation between materials sounded very appealing. Luckily, someone's <a href="http://thras.me/projects/htmaa/spect.html">done it before</a>. Unluckily, his documentation wasn't terribly thorough. Still, it was enough to get me going. ## Milling the board I recycled my schematic from the button/LED circuit board in Week 7, making the following changes: * removed the external crystal oscillator, because I figured I didn't need very accurate timing and wanted to have to route as few things as possible * incorporated the 2x2 header pin and the accompanying resistors from Neil's design for a transmit-receive, two-pad capacitance measuring <a href="http://academy.cba.mit.edu/classes/input_devices/step/hello.txrx.45.png">circuit</a>. <img src="images/schematic.jpg"/> I mostly copied the routing from the previous design as well, putting the 2x2 header pin where the oscillator had been and the new set of resistors where the LED had been. I made a few changes: * trimmed the insides of the ATtiny44 footprints to allow more space to route traces through. To edit footprints manually: * find the footprint design under the library; for the ATtiny44, this was in the Footprints folder, called SOIC14 * right-click to "Open footprint in library" * right-click footprint to "Edit properties" * in this case, I shortened the footprints until the inside edge lined up with the edge of the t44 * save footprint * in the Schematic file, add the part, and "Update" when prompted * changed the design rules such that the traces were 16mil wide (or 15mil, which Zach said was a good minimum width, for tight spaces) and the clearance was 16mil. As it turns out, 16mil is not always quite enough to ensure that the Roland mills it properly; 17mil would be good to be safe. <img src="images/traces.jpg"/> <img src="images/interior.jpg"/> Note on the interior: if you don't leave enough black space between the shape you want to cutout and the border of the image, mods might not recognize all the edges and calculate the right toolpaths, especially if you have a Mac and have to change the DPI when importing to mods. Milling went slightly less frustratingly than before, and I only had to manually sever one undesired connection with a razor blade. Stuffing went way more smoothly than before; if you aren't using a thin-tip soldering iron for surface-mounts, you're doing surface-mounts wrong (like I've been till now). ## Making a coaxial probe of sorts I completely based this design on the aforementioned previous student's work. He used two nested test tubes, the outer one with copper tape on the exterior surface and the inside one with copper tape on the interior surface, as electrodes. One is connected to the header pin that's connected to the t44 pin designated as the transmit pin, the other to the receive pin. Liquid (or a semi-solid, or, theoretically, a solid that wedges precisely between the test tubes) is poured between the tubes so that its permittivity can be measured when a signal is sent through the transmit pin and received by the receive pin. <img src="images/probe.jpg"/> ## The software part, or where everything falls apart I used <a href="http://academy.cba.mit.edu/classes/input_devices/step/hello.txrx.45.c">Neil's code</a>, changing the pins to match my setup and removing the REFS2 VCC reference since it doesn't exist in the t44: <img src="images/code_changes.jpg"/> The code compiled, the program was successfully loaded onto the board. Alas, when I tried to run the python code for visualizing the data transmission, all I got was a blank screen. I then, on Zach's suggestion, opened up the serial port connection through the Arduino IDE's Serial Monitor. Upon increasing the baudrate, or the rate at which the board sends a signal to the serial port, from the 9600 that was set, I was able to see something happening: <img src="images/serial_monitor.mp4"/> Unfortunately, that was all nonsense. Ben then helped me try to diagnose the issue with the oscilloscope. We confirmed that data was being sent, and in a pattern matching what the program dictated, but at way too fast a rate (Ben calculated the delay time to be 2.8 us instead of 102 us, as specified in Neil's code). <img src="images/oscilloscope.jpg"/> Update 11/13/18 I decided to try again with Arduino code. The Arduino library on capacitive sensing seemed suitable enough for the purposes, so I adapted the demo code for my board: <img src="images/capsense_code.jpg"/> I had to make the following changes: - deleted a few unnecessary lines of code because the code wouldn’t fit in the t44’s minuscule storage space - Used SoftwareSerial library instead of Serial, which t44 doesn’t have I had to switch the baud rate to 2400 to see anything that wasn’t gibberish. At times it appeared to be capable of stably sensing air: <embed src="images/air_screencap.mp4"/> What’s being measured should be the time delay between the output signal from the transmitting reaching the receiving/sensing pin. When I added water, the time delay seemed to decrease (to a few thousand), as appropriate (water is more conductive than air) but it was very noisy and prone to giving readings of 0. <embed src="images/air_water_video.mp4"/>