Week 7: Input Devices

This week was an introduction to various input devices that are commonly used in electronics. I personally found it very challenging just to get the software to work on a Windows operating system, however, so most of this page will chronicle what I did to get the software to work - I had proportionately less time to work on different input devices, as a result.

Hopefully this page will help people struggling to get their software to work, because I've found a lot of non-Mac users have more difficulty with Python than normal...Also, I found documentation a little thin on the ground in general for this week, so hopefully this will clarify some things.

Building and Programming the Boards

This was a straightforward task - I chose to make Neil's step-response board (hello.load.45.c) that would measure the capacitance between two copper pads, indicating whether someone was touching them or not.

My first round of milling, however, was proof that just because you've used a machine for multiple weeks, it doesn't mean that you can just skip steps like a pro. I ended up cutting my traces unevenly (and then too deeply); I had to stop and remember to zero my endmill before each cut, even for cuts on the same piece of board. (I have put up evidence of my blunder below.)

In terms of programming the board, I went with just using Neil's code without any modifications. One note of caution to people who are modifying previous Make files for this code: DOUBLE CHECK THE MICROCONTROLLER YOU ARE USING. If you're using a different microcontroller to what is listed on the Makefile, it won't work until you change every instance of the microcontroller to reference the correct one. I did that and wasted about an hour trying to figure out what went wrong. Oops.

Oh the shame.

Running the Python Interface

Here is where the trouble begins. I've numbered the steps I took in my problem-solving process below - try any of them if you are having similar difficulties! Here's the situation: I was working in Windows with Python 2.6.6, and when I tried to enter "python hello.load.45.py" into my Cygwin command line, I was told that the Tkinter module couldn't be found. Tkinter is a graphics module in Python that is used to create the rectangle display showing the capacitance read by the board. (Note: I had already installed Pyserial, term.py and rx.py, which are all needed to run the interface software.)

  1. Since that didn't work, I tried running Python through Cygwin by typing "python" into the line - it brings up a couple header lines displaying the version of Python you're running. Once I had Python running, I typed in:
    "import Tkinter"
    "import serial"
  2. Neither of these would work because my computer couldn't find the modules, even though I could! Then it was suggested that I try entering the following lines in the Python shell within Cygwin to point Python to the correct subfolder containing the modules I needed:
    "import sys"
  3. Still no luck, since the paths listed INCLUDED the one that contained the module (why couldn't it realize it was RIGHT THERE?). I tried uninstalling the current version of Python and installed a different version hoping it would come with the Tkinter all ready to go.
  4. That didn't go, and its also not recommended to have multiple versions of Python running, since they conflict with each other - its better to use just the one that is installed natively with Windows or whatever operating system you're using.
  5. At this point Moritz suggested I try loading Ubuntu instead, which I did. You can download it for free at Ubuntu's website and run it alongside your existing operating system. For instance, I can switch between Ubuntu and Windows by restarting my computer. Some notes on loading Ubuntu as an alternative operating system:
    • It takes a couple of hours - this is not a last-minute solution!!!
    • If you have a wireless network card to connect to the internet, you may have to configure/upload new drivers to run the card since it is a "proprietary driver" (i.e. its not run on free software). This will require a connection to the internet, so you will need to connect another way - Ethernet cables work pretty well.
  6. Ubuntu comes with a native version of Python, so you don't need to download that - but you will need to download Pyserial, term.py and rx.py again.
  7. In the terminal, I entered this line of code to get the Tkinter graphics module to work:
    "sudo apt-get install python-tk"
  8. Once Tkinter is installed, you have to check to see which of your serial ports is connected to your board - you can do this by entering this line into Terminal:
    "dmesg | grep tty"
  9. Now that you know the serial port, enter this line of code to get the terminal window to run (but not the actual program itself):
    "python term.py /dev/ttyUSB* 9600"
    You should replace * with the serial port number you found, and if for some reason you're running at something other than 9600 baud, then change that number too.
  10. Next, enter the code to run the actual interface program:
    "python hello.load.45.py /dev/ttyUSB*"
    Note that you don't need to enter the speed in this line.

With this last step, I finally had my program working! Some images below show my setup and the display.

I was unsure about how many copper pads we needed and what configuration we needed to use - I started with each wire connected to an individual copper pad. Then I figured out that only two of the pads were needed, so I re-did my copper pads.

It works! This shows my original 4-pad configuration, as well.

After hacking apart my 4 pads to get 2.

The display when the copper pads aren't connected.

The display when the copper pads are both connected.