ELEC 395 - AI Applications Laboratory
Week 7

Sensor Interface and Data Acquisition

Working with GPIO, ADC, Cameras, and I²C Sensors

← Back to Course Home
📋

Laboratory Overview

↑ Go Up

This laboratory introduces students to practical sensor interfacing and data acquisition techniques on the Jetson Orin Nano platform. Building on the hardware familiarization from Week 1, you will now learn to programmatically interface with various types of sensors and input devices. Through hands-on exercises, you'll work with analog-to-digital conversion (ADC) for reading continuous sensor values, camera systems using the CSI interface for computer vision applications, and I²C communication for accessing digital environmental sensors. These fundamental skills form the foundation for collecting real-world data that will feed into the AI models you develop in later weeks.

What You'll Learn

  • GPIO Programming: Control and read digital signals using the Jetson's GPIO pins with Python libraries
  • Analog-to-Digital Conversion: Interface with ADC chips to read analog sensor values and convert them to digital data
  • Camera Interface: Access and capture images from CSI cameras connected to the Jetson's MIPI CSI-2 ports
  • I²C Communication: Use the I²C protocol to communicate with digital sensors via the QWIIC connector
  • Environmental Sensing: Read temperature, humidity, and pressure data from BME280 sensors
  • Data Acquisition Workflows: Implement complete sensor-to-algorithm pipelines for AI applications

💡 Why This Matters

Sensor interfacing is the critical first step in any edge AI application—without the ability to acquire data from the physical world, AI models have nothing to process. Understanding how to properly interface with different sensor types and communication protocols enables you to build complete AI systems that can perceive and respond to their environment. Whether you're building autonomous robots, smart environmental monitoring systems, or computer vision applications, the skills learned in this lab are fundamental. The combination of analog sensors, digital sensors, and cameras provides the multimodal sensing capabilities required for advanced AI applications, from simple classification tasks to complex autonomous navigation systems.

Lab Structure

This laboratory consists of three progressive parts, each introducing different sensor interface methods:

  • Part 1: Analog-to-Digital Conversion (ADC) - Learn to read analog sensor values using external ADC chips, understanding voltage dividers and analog signal processing
  • Part 2: CSI Camera Interface - Capture and process images from the MIPI CSI-2 camera, learning the foundations of computer vision data acquisition
  • Part 3: QWIIC BME280 Environmental Sensor - Use I²C communication to read temperature, humidity, and pressure data from a digital sensor module
🎯

Learning Objectives

↑ Go Up

By the end of this laboratory session, you will be able to:

  • Configure and use GPIO pins on the Jetson Orin Nano to control and read digital signals from external hardware components.
  • Interface with ADC chips to convert analog sensor readings into digital values that can be processed by the Jetson.
  • Capture images from CSI cameras using the MIPI CSI-2 interface and process them with Python libraries like OpenCV.
  • Implement I²C communication to read data from digital sensors using the QWIIC connector system.
  • Read environmental data from BME280 sensors including temperature, humidity, and atmospheric pressure measurements.
  • Understand different communication protocols and select appropriate interfaces for various sensor types and applications.
  • Implement error handling for sensor communication failures and validate sensor data quality.
  • Design sensor data pipelines that integrate with AI models and edge computing workflows.
📚

Background

↑ Go Up

GPIO (General Purpose Input/Output)

GPIO pins are the fundamental interface between a computer and the physical world. The Jetson Orin Nano features a 40-pin GPIO header compatible with Raspberry Pi HAT accessories, providing digital input/output capabilities, PWM (Pulse Width Modulation), and communication protocols like I²C, SPI, and UART. Each GPIO pin can be configured as either an input (to read signals from sensors or buttons) or an output (to control LEDs, relays, or other devices). Understanding GPIO programming is essential for any embedded system project.

The Jetson.GPIO library provides a Python interface similar to RPi.GPIO, making it easy to control pins with simple commands. Pin numbering can follow either BOARD mode (physical pin numbers 1-40) or BCM mode (Broadcom chip-specific GPIO numbers). Proper GPIO usage requires understanding voltage levels (3.3V logic on Jetson), current limitations (typically 50mA per pin), and proper grounding to avoid damaging the hardware.

Analog-to-Digital Conversion (ADC)

While the Jetson Orin Nano's GPIO pins can read digital signals (HIGH or LOW), many sensors produce analog signals that vary continuously over a range of voltages. To read these analog values, we need an Analog-to-Digital Converter (ADC). ADC chips convert continuous analog voltage signals into discrete digital numbers that a computer can process. The resolution of an ADC determines how precisely it can measure voltages—a 10-bit ADC divides the voltage range into 1024 steps (2^10), while a 12-bit ADC provides 4096 steps for more precise measurements.

Common ADC interfaces include I²C (for moderate-speed applications) and SPI (for higher speeds). Key specifications include resolution (bits), sample rate (samples per second), input voltage range, and reference voltage. In this lab, you'll use an I²C ADC to read analog sensor values such as potentiometers, light sensors, or analog temperature sensors. Understanding ADC characteristics helps you select appropriate sensors and interpret readings correctly.

CSI Camera Interface

The Camera Serial Interface (CSI) is a high-speed interface designed specifically for camera modules. The Jetson Orin Nano includes two MIPI CSI-2 connectors that support up to 8 lanes of high-bandwidth video data transfer. CSI cameras offer advantages over USB cameras including lower latency, higher bandwidth, and direct integration with the Jetson's Image Signal Processor (ISP) for hardware-accelerated image processing.

Common CSI cameras for Jetson include the IMX219 (8MP) and IMX477 (12MP) from Sony, which provide excellent image quality for computer vision applications. The GStreamer multimedia framework is typically used to capture and process CSI camera streams on Jetson, offering hardware-accelerated encoding/decoding. Understanding camera parameters like resolution, frame rate, exposure, and white balance is important for capturing high-quality images that feed into AI models for tasks like object detection, classification, and autonomous navigation.

I²C Communication Protocol

Inter-Integrated Circuit (I²C, pronounced "I-squared-C") is a two-wire serial communication protocol widely used for connecting low-speed peripherals to microcontrollers and embedded computers. I²C uses only two signals: SDA (Serial Data) for bidirectional data transfer and SCL (Serial Clock) for synchronization. Multiple devices can share the same I²C bus, each identified by a unique 7-bit or 10-bit address. This makes I²C ideal for systems with many sensors since it requires minimal wiring.

The QWIIC system from SparkFun standardizes I²C connections using 4-pin JST connectors (SDA, SCL, 3.3V, GND), allowing sensors to be daisy-chained without soldering. The Jetson Orin Nano's GPIO header includes I²C buses, and with a QWIIC pHAT adapter, you can easily connect QWIIC-compatible sensors. Understanding I²C addressing, clock speeds (typically 100kHz standard or 400kHz fast mode), and the master-slave architecture is essential for debugging communication issues and building reliable sensor networks.

BME280 Environmental Sensor

The BME280 is a highly accurate digital sensor from Bosch that measures three environmental parameters: temperature (±1°C accuracy), relative humidity (±3% accuracy), and barometric pressure (±1 hPa accuracy). It communicates via I²C or SPI and operates at 1.8-3.6V, making it perfect for embedded applications. The BME280's small size, low power consumption, and high precision make it popular for weather stations, indoor air quality monitors, altitude estimation, and environmental control systems.

The sensor includes built-in calibration data stored in non-volatile memory, which must be read and applied to raw measurements to obtain accurate results. Python libraries like Adafruit_BME280 and smbus2 simplify the process of reading sensor data by handling I²C communication and calibration calculations. Understanding how to interpret environmental sensor data is valuable for applications ranging from climate monitoring to UAV flight control (pressure-based altitude estimation).

Key Concepts Summary

Interface Type Signal Type Wires Required Typical Use Cases Speed
GPIO Digital Digital (0/1) 1 per signal Buttons, LEDs, simple sensors Instant
ADC Analog → Digital 2-4 (I²C/SPI) Potentiometers, analog sensors kHz range
I²C Digital (serial) 2 (SDA, SCL) Sensors, displays, low-speed 100-400 kHz
CSI-2 Digital (high-speed) Multiple lanes Cameras, video streaming 1-2 Gbps/lane
📖

Pre-lab Preparation

↑ Go Up

📚 Required Reading

Before coming to lab, please review the following resources:

  • Jetson GPIO Library Documentation: Understand how to configure and use GPIO pins on Jetson platforms
  • I²C Protocol Overview: Review the basics of I²C communication including addressing and data transfer
  • BME280 Datasheet: Familiarize yourself with the sensor's specifications and measurement ranges
  • GStreamer Basics: Learn the fundamentals of video pipeline construction for camera capture
  • OpenCV Camera Capture: Review how to read and display camera frames using Python and OpenCV
⚠️ Hardware Safety:

The Jetson Orin Nano uses 3.3V logic levels on its GPIO pins. Applying higher voltages (like 5V) directly to GPIO pins can permanently damage the board. Always verify voltage compatibility before connecting sensors or external circuits. Use level shifters when interfacing with 5V devices. Never connect or disconnect sensors while the Jetson is powered on, as this can cause voltage spikes that damage components.

📝 Pre-lab Quiz

Instructions: Complete this quiz to assess your readiness for the lab. Click on your answer choice to see if you're correct.

Question 1: What is the primary function of an Analog-to-Digital Converter (ADC)?

  • A) Amplify weak analog signals
  • B) Convert continuous analog voltages into discrete digital values
  • C) Filter noise from sensor signals
  • D) Generate reference voltages for sensors

Question 2: How many wires are required for I²C communication?

  • A) 1 (data only)
  • B) 2 (SDA and SCL)
  • C) 3 (MOSI, MISO, SCK)
  • D) 4 (TX, RX, CTS, RTS)

Question 3: What voltage level does the Jetson Orin Nano use for GPIO logic signals?

  • A) 5.0V
  • B) 3.3V
  • C) 1.8V
  • D) 12V

Question 4: What interface does the BME280 sensor use to communicate with the Jetson?

  • A) UART serial
  • B) I²C or SPI
  • C) USB
  • D) Ethernet

Question 5: Which environmental parameters does the BME280 sensor measure?

  • A) Only temperature
  • B) Temperature and light intensity
  • C) Temperature, humidity, and pressure
  • D) Temperature, humidity, and CO2

Question 6: What does CSI stand for in CSI camera interface?

  • A) Computer System Interface
  • B) Camera Serial Interface
  • C) Central Sensor Integration
  • D) Compressed Signal Input

Question 7: What is the main advantage of a 12-bit ADC compared to a 10-bit ADC?

  • A) It operates at higher speeds
  • B) It provides higher resolution with more discrete steps (4096 vs 1024)
  • C) It can handle higher input voltages
  • D) It consumes less power

Question 8: How many CSI camera connectors does the Jetson Orin Nano have?

  • A) 1
  • B) 2
  • C) 4
  • D) 0 (CSI not supported)

Question 9: What is the typical I²C clock speed in standard mode?

  • A) 10 kHz
  • B) 100 kHz
  • C) 1 MHz
  • D) 10 MHz

Question 10: What does the QWIIC connector system standardize?

  • A) USB connections
  • B) I²C connections with standardized 4-pin JST connectors
  • C) SPI connections
  • D) UART serial connections
🔬

Lab Procedure

↑ Go Up

This laboratory consists of three hands-on exercises that progressively build your sensor interfacing skills. Each part focuses on a different communication method and sensor type. Work through the exercises in order, as concepts build upon each other. Take time to understand the code and experiment with different parameter values to see how they affect sensor readings.

Part 1: Analog-to-Digital Conversion (ADC)

In this exercise, you'll learn to read analog sensor values using an external ADC chip connected via I²C. You'll interface with an analog sensor (such as a potentiometer or analog temperature sensor) and convert its continuous voltage output into digital values that the Jetson can process. This exercise teaches you how to work with analog sensors and understand ADC resolution and reference voltages.

Key Topics Covered

  • Configuring I²C communication for ADC access
  • Understanding ADC resolution and conversion formulas
  • Reading analog voltage values and converting to physical units
  • Implementing voltage dividers for sensor interfacing
  • Handling ADC data sampling and averaging techniques

Part 2: CSI Camera Interface

This exercise introduces you to camera interfacing using the MIPI CSI-2 connector on the Jetson Orin Nano. You'll learn how to capture images from a CSI camera module, display them in real-time, and save frames for processing. Understanding camera interfaces is essential for computer vision and autonomous robotics applications that will be explored in later weeks.

Key Topics Covered

  • Detecting and initializing CSI camera modules
  • Constructing GStreamer pipelines for video capture
  • Using OpenCV to read and display camera frames
  • Adjusting camera parameters (resolution, framerate, exposure)
  • Saving images and video streams to files
  • Basic image processing and frame manipulation

Part 3: QWIIC BME280 Environmental Sensor

In the final exercise, you'll work with a digital environmental sensor that communicates via the I²C protocol. The BME280 provides accurate measurements of temperature, humidity, and atmospheric pressure—data that's valuable for environmental monitoring, weather prediction, and altitude estimation. You'll learn how to use I²C to read sensor registers and apply calibration data for accurate measurements.

Key Topics Covered

  • Scanning the I²C bus to detect sensor addresses
  • Reading sensor identification and configuration registers
  • Implementing I²C read/write operations with error handling
  • Applying calibration coefficients to raw sensor data
  • Reading temperature, humidity, and pressure simultaneously
  • Calculating derived values like altitude and dew point
  • Implementing sensor data logging and visualization
💡 Learning Tips:
  • Test each sensor independently before combining them in a single program
  • Use print statements to debug I²C communication and verify sensor addresses
  • Compare your sensor readings with known reference values to validate accuracy
  • Keep a log of any error messages and how you resolved them
  • Experiment with different sensor configurations to understand their effects
  • Consider what preprocessing might be needed before feeding sensor data to AI models
🔧

Lab Materials

↑ Go Up

Hardware Requirements

The following hardware components are required for this laboratory:

  • Jetson Orin Nano Developer Kit (assembled in Week 1 with JetPack SDK installed)
  • SparkFun QWIIC pHAT V2.0 (mounted on GPIO header)
  • IMX219 8MP CSI Camera Module (or compatible)
  • SparkFun BME280 Atmospheric Sensor (QWIIC)
  • ADC Module (I²C or SPI based, such as ADS1115 or MCP3008)
  • Analog Sensor (potentiometer, photoresistor, or analog temperature sensor)
  • QWIIC Cables (for connecting sensors)
  • Jumper Wires (male-to-female for analog sensor connections)
  • Breadboard (optional, for prototyping analog circuits)
  • Monitor, Keyboard, and Mouse (or SSH access for headless operation)

Software Requirements

The following software packages are pre-installed on your Jetson Orin Nano:

  • JetPack SDK 5.1+ with Ubuntu 20.04/22.04
  • Python 3.8+ with pip package manager
  • Jetson.GPIO library for GPIO control
  • smbus2 or python3-smbus for I²C communication
  • OpenCV (cv2) with GStreamer support for camera capture
  • Adafruit CircuitPython BME280 library (or similar)
  • NumPy for numerical operations
  • Matplotlib for data visualization
  • Jupyter Lab/Notebook for interactive development

Note: All required software has been pre-configured by your lab technician. If you encounter missing packages, please notify your instructor.

📦 Component Connections

Your JetBot system from Week 1 already has the QWIIC pHAT installed. For this lab:

  • CSI Camera: Connected to CSI-0 or CSI-1 connector with ribbon cable
  • QWIIC pHAT: Already mounted on GPIO pins (do not remove)
  • BME280 Sensor: Connect to QWIIC pHAT using QWIIC cable
  • ADC Module: Connect to QWIIC pHAT or GPIO pins as instructed
  • Analog Sensor: Connect to ADC module inputs

⚠️ Always power off the Jetson before connecting or disconnecting hardware!

📚

References

↑ Go Up

Official Documentation

Technical Resources

Python Libraries Documentation

Additional Learning Resources

📝

Lab Report

↑ Go Up

Prepare a comprehensive lab report documenting your work on all three sensor interface exercises. Your report should demonstrate understanding of the communication protocols, proper implementation of sensor reading code, and analysis of the acquired data. Include code snippets, sensor readings, and visualizations where appropriate.

⚠️ Submission Deadline:

Submit your completed lab report by [Insert Deadline - Typically 1 week after lab session]. Late submissions will be penalized according to course policy (10% per day, maximum 3 days).

Report Structure

Your lab report must include the following sections:

1. Title Page & Formatting (5 points)

  • Lab title, your name, student ID, date, course name, and instructor name
  • Professional formatting with clear headers and page numbers

2. Objectives (10 points)

  • List all learning objectives from the lab
  • Briefly explain why each objective is important (1-2 sentences each)

3. Procedure & Results (50 points)

For each of the 3 parts (ADC, CSI Camera, BME280):

  • Include key code snippets with explanations of how they work
  • Provide screenshots showing successful sensor readings or camera captures
  • Include tables or graphs of collected sensor data
  • Show example outputs (terminal outputs, saved images, data logs)
  • Explain what each exercise demonstrates about the communication protocol

4. Discussion (20 points)

  • Compare the three different sensor interface methods (ADC, CSI, I²C)
  • Discuss when you would choose each interface type for a project
  • Analyze the accuracy and reliability of your sensor measurements
  • Explain how sensor data preprocessing affects AI model performance
  • Describe potential sources of error in sensor readings
  • Support all statements with evidence from your experiments

5. Challenges & Solutions (10 points)

  • Describe any problems encountered (sensor not detected, incorrect readings, etc.)
  • Explain your debugging process and how you identified issues
  • Document the solutions you implemented
  • Reflect on what you learned from troubleshooting

6. Conclusion (5 points)

  • Summarize key learnings about sensor interfacing
  • Reflect on which interface method you found most useful
  • Discuss how these skills apply to future AI projects
  • Suggest improvements or extensions to the lab exercises

📋 Submission Checklist

  • ✓ Completed all 3 lab parts with working code
  • ✓ Included clear screenshots of sensor outputs
  • ✓ Documented code with proper comments
  • ✓ Analyzed and visualized collected data
  • ✓ Compared different sensor interface methods
  • ✓ Explained communication protocols used
  • ✓ Discussed practical applications
  • ✓ Proper citations and references
  • ✓ Professional formatting throughout

📤 Submission Format

  • File Format: PDF (required)
  • Code Files: Include Jupyter notebooks or Python scripts in a ZIP file
  • File Naming: Week7_[LastName]_[StudentID].pdf
  • Code Archive: Week7_[LastName]_[StudentID]_code.zip
  • Submission Method: Upload to Learning Management System (LMS)
  • Maximum Size: 50MB total (compress images if needed)

📊 Grading Rubric

Component Points Criteria
Title Page & Formatting 5 Complete information, professional appearance
Objectives 10 Clear understanding of learning goals
Procedure & Results 50 All parts complete, correct implementation, clear documentation
Discussion 20 Thoughtful analysis, proper comparisons, evidence-based
Challenges & Solutions 10 Detailed problem-solving documentation
Conclusion 5 Reflective summary with future applications
Total 100

Grading Notes:

  • All code must execute without errors
  • Screenshots must be clear, properly labeled, and demonstrate functionality
  • Sensor data must be analyzed, not just presented
  • Late penalty: 10% per day (maximum 3 days)
  • Plagiarism or code copying: zero credit for entire lab
  • Bonus points available for creative extensions or improvements