Back to Home

Assignment 8: Input Devices

Update: I got the serial communication working in output devices week.

Before I started this week's assignment, I first adjusted my final project. In my final project I want to build an eye which can detect the light and roll to avoid glare (there will be a rotation axis which let the eye look left or right, also there will be a control to move the eyelid). So this week I looked through light sensors and decided to try phototransistor. Besides the datasheet, I found two useful resources to understand phototransistor.

Phototransistor tutorial: Basic theory on YouTube.

Phototransistor application: An array of phototransistor.

For phototransistor, C and E stand for Collector and Emitter, The current can flow only in one direction, determined by which pin is connected to VCC and which connected to GND.

Also, for my final project, I considered that I will need 4 sensors as input devices and 2 motors as output devices to control the rotation of the eye. Since last time my Arduino on my laptop refused to work with my attiny44-based board (it only worked on TA's laptop and shop's desktop), I decided to practice to use different microcontroller, such as Atmega to see what will happen. Instead of modifying my previous design in "electric design" week, I use "hello.arduion.328P" board as the basis, redrew it and added one phototransistor.

Board design and making

Thanks to the skill I learned in electric design week, drawing in eagle went quickly. I connected the phototransistor to PD4. When drawing board, I found it difficult to route without crossing, so I added one jumper. Yasi helped me to check my design before milling. Carefully I finished soldering and prepared to test it.

Eagle scheme:


Board drawing:

Milling:


Soldering:

Test and measurement

I start my test in Arduino IDE. By following the instruction in Dan Chen's page, I pasted this URL to add ATmega board into Arduino:

https://adafruit.github.io/arduino-board-index/package_adafruit_index.json,https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json,https://raw.githubusercontent.com/sleemanj/optiboot/master/dists/package_gogo_diy_atmega8_series_index.json

According to the pinout of ATmega328p, then I wrote the code below to open the pin connected to phototransistor.



Uploading done successfully, the led blinked when uploading.


when I opened the serial monitor, something weird happened. My serial monitor kept rolling and rolling, and nothing was printed. If I change the value of delay, it will roll faster. I added x in my code to see if the serial monitor will print it, still doesn't work. And I also checked 9600 baud. With Yasi, we tried again and again, googled, and I also re-soldered several pins to ensure the connection, but the serial monitor still kept rolling!



Finally I decided to have a break and tried some other things to clear my mind. I really wanted to see how phototransistor works, so I decided to make Neil's board.

Try hello.light.45

I made Neil's board and tried to use it to measure light.


To program it, I used programmer's notepad[winAVR] (see my steps in 'embedded programming' week). I used c code wrote by Neil. Besides, I defined the make file by Mfile[winAVR].

Makefile steps:


Then save make file and .c file in one folder, go back to programmer's notepad. I selected tools-[winAVR]make all. The board was initialized and waited for program. Then I selected tools – [winAVR]program. Success!


A failure: Python interface in windows

Then I tried to open the python interface. I know I have Tkinter module in my python, so I installed pythonserial. I opened CMD to open python interface, typed "python hello.light.45.py COM3", fixed the missing parentheses, but then it said it could not find Tkinter! Then I installed Tkinter, but still the same problem.

Install PythonSerial:


Tkinter:


I thought this is the problem caused by multi versions of python on my laptop. After several times of trying and failures, I decided to use shop's desktop. I opened the terminal, went to desktop(where I put the .py file), typed "sudo hello.light.45.py", entered the password, then it worked! The sensor can detect my hand by detecting light. By now I am still debugging my ATmega328p board. I think it will work eventually.






Video: Sensoring the light.