Due: 2:00 p.m. on the next Wednesday or Thursday.
- Report Format: Submit a formal, typed lab report in PDF format. Handwritten lab reports will not be accepted. Hand-drawn circuit diagrams will not be accepted; draw every schematic with software (see Software at the end of this manual). Include screenshots, code, and simulation or measurement results where specified.
- AI Policy: The use of any AI tool, including a large language model (LLM), to write, generate, debug, or modify code or any portion of the lab report is prohibited unless the course instructor grants explicit permission in advance. A teaching assistant (TA) cannot grant permission to use AI tools.
By signing below, I acknowledge that I have read and understood the policies and instructions above and agree to follow them.
Student Name (print):
Student Signature: Date:
Introduction
This week, we continue to explore different sensors communicating with a Raspberry Pi via serial protocols. While I2C is a popular serial protocol due to its simplicity, we will investigate another synchronous serial protocol called SPI (Serial Peripheral Interface) with an analog-to-digital converter chip, the MCP3008. Throughout the lab, capture screenshots, pictures, and videos as necessary and include them in your report. Remember to annotate your Python scripts with descriptive comments.
Tasks
- Initial Setup and Configuration
- Connect your Raspberry Pi to the internet.
- Create a new directory for this lab using terminal commands.
- Update and upgrade the operating system.
- Enable SPI in the Raspberry Pi settings.
- Download the instructor-provided
ADC3008_SPI.pyfrom the course files to your new directory.
- ADC Implementation
- With the power off, wire the MCP3008 to the Raspberry Pi as shown in the Lecture 8 notes. Connect VDD and VREF to 3.3 V, connect both grounds, and put the bypass capacitor right next to the chip.
- Write code to read the output as a voltage (
v_volt). - Demonstrate your program to the course instructor or a TA.
- Voltage Testing and Calibration
- Build a circuit that can output various voltages from 0 V to 3.3 V.
- Connect the circuit output to a digital multimeter (DMM).
- Verify that your Python code output matches the DMM readings, with proper error handling.
- Document the testing process and results.
Course Instructor or TA Signature:
Date and Time:
- Code Enhancement and Data Analysis
- Modify your code to report both the raw integer count,
v_frac(0 to 1023), and the calculated voltage,v_volt. Take readings at 20 or more input voltages spread across the range, and measure each one with the DMM as well. - Plot
v_voltagainstv_fracto show your conversion rule. Then plot the DMM voltage againstv_frac, fit a straight line, and plot the residuals (how far each point lies from the line). - Use the DMM comparison to judge the ADC's linearity and accuracy, including the uncertainty of the reference voltage and of the meter. The
v_voltplot cannot test linearity: you calculatedv_voltfrom the count, so it is a straight line by design.
- Modify your code to report both the raw integer count,
Course Instructor or TA Signature:
Date and Time:
- SSH Remote Control
- Find and document your Raspberry Pi’s IP address.
- Enable remote control in the settings.
- Establish an SSH connection from your laptop.
- Demonstrate remote operation of your voltage measurement program.
- VNC Remote Desktop
- Configure a VNC server on the Raspberry Pi.
- Install a VNC viewer on your laptop.
- Demonstrate remote desktop access.
- Run and display the temperature sensor program remotely.
Course Instructor or TA Signature:
Date and Time:
Extra Credit (up to +18 points)
These tasks are optional and meant for students who finish the required tasks early. The course instructor and TAs will not provide any help with them: no hints, no debugging, and no checking of your design, wiring or code. Do them entirely by yourself.
Finish every required task and get it signed off first. For the shared Lab 7 Task 7, a TA may sign off completed parts for partial credit; clearly identify those parts in your report. For other extra-credit tasks, a TA will sign off a finished task only when it works. A TA will still stop any setup that could damage the equipment or the Raspberry Pi. Points count only for work that is signed off and written up in your report, with an error analysis where it applies, as for every task.
You can earn up to +8 points for the waveform analysis, plus up to +10 points for the shared Lab 7 Task 7 if you did not claim it on Lab 7. Two tasks here are numbered 7: the waveform analysis is this lab's Task 7, and the shared sensor task below keeps its Lab 7 name, Lab 7 Task 7.
You may complete Lab 7 Task 7 during Lab 7, during Lab 8, or across both labs. This is one shared extra-credit assignment worth up to 10 points total, not 10 points for each lab. If you finish it in Lab 7, include it in your Lab 7 report and the points will be added to Lab 7. If you finish it later, include it in your Lab 8 report and the points will be added to Lab 8. Credit is awarded only once, on one lab report; work already credited in Lab 7 cannot earn credit again in Lab 8.
Partial credit is available. In the report where you claim credit, clearly list which of the six parts you completed, which are incomplete or unattempted, and the supporting code, measurements, plots, and analysis for each completed part. Have the completed parts signed off and identify whether you are claiming the credit on Lab 7 or Lab 8. If you plan to continue in Lab 8, wait and claim your Task 7 credit in the Lab 8 report, so all your work on it is graded together, once.
- Waveform Analysis (+8 points)
- Use a function generator to create a sine wave input. Before connecting it to the ADC, confirm on the oscilloscope that the signal stays between 0 V and 3.3 V.
- Connect the signal to both the ADC and an oscilloscope.
- Modify your code to plot voltage vs. time, matching the oscilloscope trace.
- Measure the time between samples, and find the highest input frequency your setup still measures well. Say what "well" means for you, for example the largest amplitude or frequency error you will accept.
- Analyze and document the frequency limitations.
Course Instructor or TA Signature:
Date and Time:
Shared extra credit, Lab 7 Task 7: Temperature-Compensated Range Finder with Threads and Processes (up to +10 points)
- Temperature Compensation: Connect the MCP9808 temperature sensor to your circuit alongside the LIS3DH, giving the two chips different I2C addresses. Modify your code so the range finder outputs distance based on the MCP9808 temperature reading.
- One Loop (Baseline): Write a program that reads the accelerometer, the temperature, and the distance in a single loop, and records a time stamp with every reading. With the range finder aimed at a fixed target, collect at least 100 distance readings. Determine the accelerometer sampling interval (mean, standard deviation, and maximum) and the standard deviation of the distance.
- Threads: Rewrite the program with the
threadingmodule so that the accelerometer, the range finder, and the temperature sensor each run in their own thread, with the accelerometer aiming for 100 Hz. Repeat the baseline measurements from One Loop. Then change the switch interval withsys.setswitchinterval()and measure again. - Processes: Rewrite the program with the
multiprocessingmodule so that the range finder runs in its own process and sends its readings back through a queue. Repeat the baseline measurements from One Loop. - Calculation Test: Time a CPU-bound calculation run as 1, 2, and 4 threads and as 1, 2, and 4 processes. Repeat each timing at least three times, and calculate the speedup for each case.
- Comparison: Tabulate all your results with their uncertainties, and explain the differences using the global interpreter lock (GIL) and the difference between threads and processes. Show an instructor your running programs.
Course Instructor or TA Signature:
Date and Time:
Submission Reminder
- Complete circuit diagrams and connections for the MCP3008 ADC setup.
- An explanation of the functionality of
ADC3008_SPI.py. - Your modified Python scripts with clear comments explaining the functionality.
- Plots and analysis of voltage measurements.
- Screenshots demonstrating successful remote access implementations.
- An error analysis for every task where it applies, including extra-credit tasks: the uncertainty of each measured or calculated value, its main sources of error, and a comparison with the expected, simulated, or datasheet value.
- A discussion of any challenges encountered and their solutions.
- If you did the extra credit (Task 7): your waveform plots beside the matching oscilloscope traces, and documentation of your frequency-limitation testing and results.
- If you are claiming credit for the shared Lab 7 Task 7: list the parts you completed, the parts you did not finish, and the parts you did not attempt; include their schematic, Python scripts, timing results with uncertainties, and explanations; and state that you are claiming the credit on Lab 8 and did not receive it on Lab 7. Submit this shared task only once.
- (Optional) A link to a video demonstrating the remote control capabilities.
Draw every circuit diagram with software; hand-drawn circuit diagrams will not be accepted. We recommend the free draw.io; the course’s Drawing Circuit Diagrams page shows how to set it up. If a component has no symbol of its own, use the closest one and label it clearly.
Where a task asks for a simulation: the web version of Multisim is no longer available. If you have a Windows computer, you can install the offline (desktop) version of Multisim; ask a TA for the serial number to install it. Otherwise, feel free to use any SPICE-based simulation tool, such as LTspice or ngspice.