Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Final Project: Light Source & Object Proximity Detector System

DCS Course
A comprehensive embedded system and PC interface for detecting light sources and object proximity using an MSP430 MCU.


🛠 Hardware Architecture

  • Layering: BSP → HAL → API/APP → main (FSM, interrupt-driven)
  • I/O: UART 9600 bps
  • Display: LCD 16×2
  • Sensors: HC-SR04 (Ultrasonic) + two LDRs (Light Dependent Resistors)
  • Motor: SG90 servo motor

📍 Pin Out

Pin Function Description
P1.0 Analog Input (A0) LDR1 Signal
P1.1 UART RXD
P1.2 UART TXD
P1.3 Analog Input (A3) LDR2 Signal
P1.4 Digital Output LCD Data D4
P1.5 Digital Output LCD Data D5
P1.6 Digital Output LCD Data D6
P1.7 Digital Output LCD Data D7
P2.0 Digital Input PB0 (LDR Calibration Button)
P2.1 Digital Output LCD Control Signal (E)
P2.2 Timer A1 CCR1 Ultrasonic Sensor Output (ECHO)
P2.3 Digital Output LCD Control Signal (RS)
P2.4 Timer A1 CCR2 PWM Out (Servo Motor Control)
P2.5 Digital Output LCD Control Signal (RW)
P2.6 Timer A0 CCR1 Ultrasonic Sensor Input (TRIG)
P2.7 Digital Input PB1

📂 Source Index

MCU (C)

  • Headers: app.h, api.h, halGPIO.h, bsp_msp430x2xx.h
  • Sources: bsp.c, halGPIO.c, api.c, main.c

PC (Python)

  • Main Entry: main.py
  • Modules: comm/, gui/, processing/, visualization/

🧠 MCU Subsystem Details

1. Headers

  • app.h: Constants & memory map (Flash addresses, sizes), Enums (FSM states, ScanMode, FileType), FileEntry structure, extern shared states.
  • api.h: APP/API prototypes for detectors, measurements, file system operations, and calibration sequences.
  • halGPIO.h: HAL prototypes for LCD, UART, ADC, Timers, PWM, Ultrasonic, Flash, circular RX buffer, and LPM helpers.
  • bsp_msp430x2xx.h: BSP pin mapping, general macros, Timer/ADC/UART defines, and ISR vectors.

2. C Sources

bsp.c (Board Support Package)

Low-level board bring-up and system helpers:

  • GPIOconfig, Timers_Init, ADC_config, UART_init
  • LPM and global IRQ utilities (enterLPM, enable_interrupts)

halGPIO.c (Hardware Abstraction Layer)

Direct hardware layer and ISRs:

  • LCD: lcd_init, lcd_cmd, lcd_data, lcd_puts
  • UART: UART_send_char, UartBuffer_Init/Put/Get
  • Timers/Ultrasonic: Blocking delays, Ultrasonic_Start_Measurement
  • PWM/Servo: pwmOutServoConfig, Set_Angle_PWM
  • ADC: ADC_Enable, ADC_sample, channel configs
  • Flash: Timing, erase/write operations
  • ISRs: Buttons (PBs_handler), Timers (Timer_1_ISR, Timer0_A0_ISR_Handler), ADC (ADC_ISR)

api.c (APP/API Layer)

High-level logic, runtime FSMs, Flash filesystem, scripts, and scanning:

  • Scans & Sensing: servo_scan, object_detector, telemeter, light_detector, light_object_detector
  • LDR Calibration: run_calibration_sequence, write_all_calib_to_flash, send_calib_arr
  • Filesystem: FileSystem_Init, Handle_UploadFile_Start, Handle_Upload_Byte, script interpreters (parse_and_execute_line)

main.c (Entry Point)

Initialize layers, run RX loop, decode UART commands, and dispatch FSMs.


💻 PC Subsystem (Python)

The PC-side provides a PySimpleGUI desktop application to control all modes, run calibration, manage files, process sensor data, and plot polar maps.

Key Functionalities:

  • Serial Management: UART communication wrapped in serial_manager.py.
  • GUI Modules: Isolated event loops for Objects, Telemeter, Lights, Combined, and File modes.
  • Processing: Signal smoothing, valley/peak detection, filtering, and crosstalk cleaning (process_light_scan_data).
  • Data Visualization: Matplotlib polar plots for detected objects and light sources.
  • File Upload Protocol: Handles MCU handshake, checksum generation, and 64-byte chunked flashing.

Script Opcodes:

Command Hex Command Hex
inc_lcd 0x01 dec_lcd 0x02
rra_lcd 0x03 set_delay 0x04
clear_lcd 0x05 servo_deg 0x06
servo_scan 0x07 sleep 0x08

🔌 UART Protocol Quick Reference

Control Markers:

  • Start-of-Script = 0xCC
  • Telemetry Header = 0xFE
  • End/Sleep = 0x7F
  • End-of-Scan = FF FF FF

Handshakes & Commands:

  • Handshake: 'P' → MCU replies 'A'
  • Objects: 'S' → stream of (2B distance + 1B angle) per step; end marker FF FF FF
  • Lights: 'K' → stream of (LDR1_lo, LDR1_hi, LDR2_lo, LDR2_hi, angle)
  • Combined: 'X' → stream of (2B distance, 2B LDR1, 2B LDR2, 1B angle); end marker FF FF FF
  • Telemeter: 'T' + angle byte → MCU returns (2B distance + 1B angle)
  • Files:
    • 'L' (List), 'U' (Upload), 'R' (Run script), 'V' (LCD view mode), 'D' (Delete FS)
  • Calibration: 'J' (Guided LDR capture), 'Z' (Read back compressed array)

Note: Endianness is Little-Endian (first Low-Byte, second High-byte).


👥 Authors

  • Arkady Gerasimuk
  • Adi Shlomo

About

An embedded radar system using an MSP430 MCU to detect and map objects and light sources, featuring a custom flash file system and a Python desktop interface.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages