Name 1:
Login: ee16a-
Name 2:
Login: ee16a-
"YOUR CODE HERE"
or "YOUR COMMENTS HERE"
.YOU MUST ATTEND THE LAB SECTION YOU ARE ENROLLED IN. If you anticipate missing a section please notify your GSI in advance.
You are required to return all parts checked out at the beginning of the lab section unless told otherwise.
Food and drinks are not allowed in the lab.
Clean up, turn off all equipment, and log off of computers before leaving.
Welcome to the first lab of EE16A! This is the first of a series of 3 labs in the imaging module in which you will actually build the imaging system introduced in Lecture 2. The physical components of this system include a projector, a solar cell, sensing circuit, and an Arduino microcontroller. The full imaging system is shown below:
The image below shows a brief overview of how our camera converts the photons of light bouncing off of an object and converts them into the numbers that represent images on a computer.
Commercial cameras such as those found in smartphones use chips called CMOS image sensors to measure millions of pixel values at a time (think of this as millions of devices like the solar cells that all fit on an approximately 30mm$^2$ chip). In contrast our system can only measure one light intensity value at a time, so we will instead use a controlled energy source, the projector, to illuminate specific regions of the image at a time and record the energy that reflects off the subject for one region at a time.
The solar cell converts light to induce a flow of electrons, and the circuit then outputs a voltage corresponding to light intensity. The specific configuration of the circuit sets the solar cell up so it is most sensitive to changes in light.
This changing voltage is now a set of real numbers and much closer to something we can use to represent our image on a computer. Unfortunately, our computers don't have enough memory to represent an infinite number of values so we use the Arduino to take samples of this signal and convert it to a set of numbers we can then use in IPython.
The table below shows the circuit symbols relevant to this lab and a picture of the real component they represent.
As explained in Lecture 2, there exist devices that are capable of measuring voltages and currents. A multimeter is one such device that is capable of measuring voltage, current, resistance, and in this case even capacitance. The Agilent 34405A digital multimeter available in the lab is very useful for "debugging" a circuit.
Connect a black test lead to the black port on the device.
Connect a red test lead to one of the red ports on the device
The ports are each labeled with what they should be used to measure. The top right port should be used to measure voltage, resistance, capacitance, etc. The other two ports should be used for current measurements and are capable of measuring up to a the marked maximum value.
Select the quanitity you wish to measure (e.g. DC voltage, resistance, etc)
Connect the multimeter to your circuit.
Measuring voltages requires that the test leads are connected to the circuit in parallel as shown for the $V$ measurement, while current measurements require the test leads to be connected in series as shown for the $A$ measurement.
The oscilloscope is another useful piece of test equipment that can be used to measure signals that vary over time. Unlike the multimeter which only shows the instantaneous voltage value, the oscilloscope shows a graph of a voltage versus time. This is particularly useful for measuring how devices like sensors respond to inputs. Although this instrument may appear complicated, half of the knobs are just to adjust the axes of the voltage plot. Below is a brief overview of how to use this oscilloscope:
Use the oscilloscope to measure the output of the solar cell in different lighting conditions. Compare the waveform on the oscilloscope when you cover the cell completely with the waveform measured under direct light.
How does the waveform on the oscilloscope vary with light intensity?
YOUR COMMENTS HERE
What is the average voltage of the cell in ambient light?
YOUR COMMENTS HERE
Use the oscilloscope to zoom in to 50-100 mV/division. What do you notice about the waveform? How does it differ from what you would expect an ideal device to look like?
YOUR COMMENTS HERE
How does the waveform differ from the one you saw in Task 1?
YOUR COMMENTS HERE
How is this difference useful in the context of building an imaging system?
YOUR COMMENTS HERE
An Arduino is a popular microcontroller, a small computer on a single chip. Microcontrollers are found at the heart of all embedded devices and have enough processing power to perform simple tasks using very little power. Because of its limited processing capabilites, the Arduino doesn't run an operating system like desktop computers or servers; instead the device just executes a single function continuously in a loop as soon as it is powered on. For our application this simple program reads a single voltage value and sends it to a computer via the USB connection. We will now walk through the process of using an Arduino and uploading code to it.
Use the USB cable to connect the the Arduino to your computer. Verify that the LED on the Arduino is blinking once it is connected to the computer.
Open the Arduino IDE The Arduino IDE is used to compile and upload code to the microcontroller.
Select "Board > Arduino Uno" This software supports a wide variety of Arduino boards, some of which have different chips. In order to make sure that code is uploaded to the device we need to make sure we have specified we are using the Arduino Uno board.
Select serial port The Arduino uses a serial interface to communicate with computers. In order to upload code to the device we have to select the serial port that the Arduino is connected to. On the lab computers there should be two options, select the one that is not "COM1" (most likely something between "COM20" and "COM49"). If you are using your laptop, there will most likely be only one port on this menu which should correspond to the Arduino.
If at any time you are unable to upload code or communicate with the Arduino, this menu can be used to check if the port is still recognized. If not options appear in this menu try unplugging the Arduino and plugging it back in.
Open the file "LightSensor.ino"
Note that the Arduino IDE requires that the ".ino" source file be placed in a folder with the same name. This file has code to periodically read the voltage of pin "A0" and send this data over serial to a computer.
Click the "Upload" button This should compile and upload code to the Arduino. Once the "Programming successful" message is displayed, the Arduino will repeatedly execute the code whenever it is powered on.
Connect the Arduino to the sensor circuit Our goal is to use the Arduino board to replace the oscilloscope and external power supply; the Arduino is capable of supplying the 5V necessary to power the circuit, and can also read and send voltage values to our computer.
Run the code block below and try covering part of the solar cell
import subprocess
from light_sensor import serial_ports
def get_port():
ports = serial_ports()
if len(ports) > 1:
for p in ports:
if p != "COM1":
return p
else:
print "No serial ports detected. Connect the Arduino and try again."
port = get_port()
correct = raw_input("Port %s selected, is this correct? (y/n) "%port).lower()
if correct == 'y':
subprocess.call(["python", "light_sensor.py", "-D", port])
else:
print "Check Arduino connection"
Congratulations, you can now record sensor data on a computer! There are all kinds of exciting things you can do with this exact setup; once your sensor data is accessible in Python, you can use your sensor input as a cue to send a text message or tweet, start or stop programs, the possibilites are endless!
If you're interested applying what you've learned to your own personal projects there are a variety of spaces on campus with additional resources to support these kinds of activities: