F13: Garage Parking Assistant

From Embedded Systems Learning Academy
Jump to: navigation, search

Garage Parking Assistant

Project by: Eric Maki & Kathryn Ng

Abstract

The purpose of this project is to build a multifunctional parking assistant. The parking assistant will simplify the driver’s task of parking a car in a garage. The parking assistant will automatically open the garage door as the vehicle approaches the garage. Once the vehicle is inside the garage, the parking assistant will notify the driver of the vehicle's position relative to a predetermined stop point. When the vehicle reaches the stop point, the parking assistant will alert the driver with audible and visual cues.

Objectives & Introduction

The project consists of two separate modules which communicate with each other wirelessly. One module is located in the garage while the other is located in the vehicle with the driver. Each module is designed around an SJOne board with ARM Cortex-M3 (LPC1758) microcontroller.

The garage module uses an ultrasonic rangefinder to measure the distance of an approaching vehicle. The distance will be displayed symbolically on an LED strip. The distance will be transmitted wireless using the onboard Nordic IC to the vehicle module. The vehicle module will receive the distance signal. It will open the garage door. It will display the distance on a 7-segment LED display and sound an alarm when the vehicle reaches it's stopping point.

Team Members & Responsibilities

  • Eric - Garage Module
    • Measure approaching distance
    • Transmit distance
    • Display closing distance
    • Display stop point
  • Kathryn - Vehicle Module
    • Receive approaching distance
    • Open garage door
    • Display closing distance
    • Sound alarm

Schedule

Week# Date Task Status
1 10/08/13 Proposal due. Order parts. Completed task on time.
2 10/15/13 All parts arrive. Write code to open garage door. Completed task on time.
3 10/22/13 Establish board-to-board wireless connection Completed task on time.
4 10/29/13 Start working on tasks listed on 11/5 and 11/12. Completed task on time.
5 11/05/13 Garage microcontroller: Range finder. Vehicle microcontroller: LED display Completed task on time.
6 11/12/13 Garage microcontroller: LED strip functional. Vehicle microcontroller: Piezo functional Completed task on time.
7 11/19/13 Complete garage/vehicle module integration. Start system testing. Completed task on time.
8 11/26/13 Complete system testing. Practice Demo. Completed task on time.
9 12/03/13 Complete demonstration. Completed task on time.
10 12/07/13 Complete report. Completed task on time.

Parts List & Cost

Item # Part Description Vendor Qty Unit Cost Total Cost
1 SJOne Board (LPC1758) SJSU CmpE 2 $75 $150
2 SMA Antennas Instructor 2 $0 ($2) $0 ($4)
3 Addressable RGB LED Light Strip Adafruit 1 $29.95 $29.95
4 Ultrasonic Rangefinder Sparkfun 1 $0 ($24.99) $0 ($24.99)
5 Garage Door Remote Home Depot 1 $34.97 $34.97
6 Piezo Buzzer Instructor 1 $0 ($2) $0 ($2)
7 Connectors for LED strip lights (JST plug and receptacle) Adafruit 2 $1.50 $3
8 Vehicle Module enclosure Daiso 1 $1.50 $1.50
9 Module enclosure Adafruit 1 $9.95 $9.95
10 4 x AA battery holder Adafruit 1 $2.95 $2.95
11 Female DC power adapter - 2.1mm Adafruit 1 $2.00 $2.00
12 5V 2A switching power supply Adafruit 1 $9.95 $9.95
13 Ribbon cable Anchor Electronics 1 $1.27 $1.27
14 Screws nuts and standoffs Digikey 2 $4.00 $8.00
15 Mini USB Type-B Male socket connectors (includes 10) Newegg 1 $4.34 $4.34
16 Batteries (4-pack) Target 1 $3.99 $3.99
Total $261.87

Design & Implementation

Hardware Design

The design consists of two separate hardware components that communicate with each other wirelessly. The components are labeled the Garage Module and Vehicle Module.

The Garage Module is designed to be mounted on the wall of the garage, facing the oncoming vehicle. The Vehicle Module is designed to be mounted on the dashboard of the vehicle within the driver's field of vision.

Garage Module

The SJOne board and ultrasonic rangefinder are mounted in a compact plastic enclosure. The top of the enclosure is transparent so that the electronics, including on-board LED display, are visible when the enclosure is sealed. The LED strip is connected to the enclosure with a 4-wire ribbon cable. All parts of the garage module are powered by a single 5V, 2A AC/DC power converter.

Rangefinder

The Garage module uses an ultrasonic rangefinder to detect the distance of the approaching vehicle. An ultrasonic rangefinder was chosen over other rangefinder types because it has the best balance of range (0 - 21ft) and resolution (1 inch) for our application. The ultrasonic rangefinder outputs an analog signal to represent the distance to the approaching vehicle. The analog signal is connected to an ADC input on the microcontroller which translates the signal to a data. The microcontroller uses this data to compute the distance in inches.

The photo below depicts a close-up of the ultrasonic rangefinder. The rangefinder is mounted pointing outwards to detect the approaching vehicle. The microcontroller processes the analog distance signal and outputs the distance on the onboard LED display.

Close-up of rangefinder
Close-up of rangefinder

LED Strip

The Garage module symbolically displays the distance of the approaching vehicle on an LED strip. The LED strip houses 32, individually addressable, tri-color LEDs. Each LED has a red, green, and blue component; which can be mixed to output any visible color. The LED strip contains built in LPD8806 LED drivers. The LED drivers are interfaced via a daisy-chain SPI bus. Note: This SPI bus uses only two signals: Clock and MOSI.

The Garage module toggles the color of the individual LEDs between green and red depending on the distance of the the approaching vehicle. As the vehicle approaches, the LED's will incrementally, turn from green to red. When the vehicle reaches its stop point, the entire LED strip will flash red on/off.

The photo below depicts the LED light strip and the garage module enclosure mounted on the garage wall. It is clear to see that the approaching vehicle is a little more than 1/2 the distance to the stop point. The ribbon cable to the left connects the LED strip to the enclosure. The cable to the right connects the enclosure to the 5V wall adapter.

LED strip and garage module
LED strip and garage module

Wireless

Garage module's microcontroller wirelessly transmits the distance to the Vehicle module's microcontroller. The garage microcontroller uses the onboard Nordic wireless radio in conjunction with an SMA antenna for maximum range.

Close-up of garage module with SMA antenna
Close-up of garage module with SMA antenna

Vehicle Module

The SJ One board, piezo buzzer, and garage door remote control are contained in a compact transparent plastic enclosure. The SJ One board is mounted on lid of the enclosure with the on-board LED display visible to the user using standoffs. The piezo and remote control are resting at the bottom of the enclosure facing the bottom. All parts of the Vehicle module are powered either by 4-battery pack modified to connect to mini USB or USB car charger and cable.

Garage Door Remote Control

The Vehicle module opens the garage door by sending GPIO signal from the microcontroller (pin P1.28) to the garage door remote control. The GPIO is signal is wired to the back of the pushbutton switch on the remote control. The garage door remote control is universal garage door remote and needs to be pre-programmed to communicate with the garage door prior to installation in the enclosure. In addition, a LED on the SJ OneBoard will be lit up for the time duration when GPIO signal is sent.

The photo of the Vehicle module back side shows a rectangular garage door opener with the pushbutton cover removed. The photo of the Vehicle module front side show the LED that will light up when GPIO signal is sent.

7-segment LED Display

The Vehicle module displays the distance (inches) of the approaching vehicle on a 2-digit, 7 segment LED display, which is on the microcontroller.

The photo of the Vehicle module front side shows the 2-digit LED display on the microcontroller.

Alarm (Piezo Buzzer) The vehicle module uses piezo buzzer to alert the driver to stop the car because it has exceeded it's stop distance from garage wall. The piezo buzzer is rated for 5V and max of 15mA at 4.5KHz frequency. In order to produce a sound, the piezo buzzer is sent PWM signal from the SJ OneBoard microcontroller pin P1.20 as shown in the schematic.

The photo of the Vehicle module back side shows the piezo buzzer.

Below are photos of the front and back side of the Vehicle Module Hardware.
GarageParkingAssistantCarFront.PNG

Vehicle Module Hardware - Front side

GarageParkingAssistantCarBack.PNG

Vehicle Module Hardware - Back side

Hardware Interface

The hardware interface consists of five interfaces. The garage module uses the microcontroller's ADC driver and SPI driver. The vehicle module use the microcontroller's GPIO and PWM drivers. Wireless communication uses a wireless mesh network and SPI driver. These drivers are already provided with the LPC1758 microcontroller.

The Hardware Interface schematic is shown on the right.

SPI Interface

The Garage module LPC1758 Micro-controller communicates with the Ultrasonic rangefinder through the SPI interface. The LED drivers are interfaced via a daisy-chain SPI bus. Note: This SPI bus uses only two signals: Clock and MOSI. The garage module toggles the color of the individual LEDs between green and red depending on the distance of the the approaching vehicle. As the vehicle approaches, the LED's will incrementally, turn from green to red. When the vehicle reaches its stop point, the entire LED strip will flash red on/off. Note: The SPI 1 driver was created by copying the existing SPI 0 driver.

ADC Interface

The Garage module LPC1758 Micro-controller communicates with LED Strip through ADC interface. The ultrasonic rangefinder outputs an analog signal to represent the distance to the approaching vehicle. The analog signal is connected to an ADC input on the microcontroller which translates the signal to a data. The microcontroller uses this data to compute the distance in inches.

PWM Interface

The Vehicle module LPC1758 Micro-controller communicates with piezo buzzer through PWM interface. In order to produce a sound, PWM signal is sent to the piezo buzzer at a human hearing frequency between 20Hz to 2000Hz and duty cycle greater than 0%.

GPIO Interface

The LPC1758 Micro-controller communicates with garage door remote through GPIO interface. In order to open the garage, GPIO signal is manipulated into 500 ms pulse signal to simulate the pressing of push button switch on the garage remote. In addition, GPIO signal will be sent to light up LED on-board the microcontroller to indicate the signal to open garage door is being sent.

Mesh Interface

The Vehicle module LPC1758 Micro-controller communicates with Garage module LPC1758 Micro-controller through low mesh interface. The vehicle module receives mesh packet from Garage Module that contains distance data.

GarageParkingAssistant HWSchematic.png

Hardware Interface schematic

Software Design

Each hardware component runs on it's own separate build file. Both software builds were designed using the polling method to obtain sensor and communication inputs. The polling method was chosen for it's simplicity of use.


Garage Module Pseudocode and Software Flow Diagram

Below is psuedocode for Garage Module software design.

main()

  • Initialize devices
    • Set up P0.26 as ADC0.3
    • Call adc0_init() to initialize ADC0
    • Call spi1_init() to initialize SPI1
    • Call spi1_set_max_clock() to initialize SPI1 clock to 1KHz
    • Call strip.show() to write to the LED strip (all LEDs off)
    • Call colorWipe(), a fancy way to set LEDs to green 1 by 1
      • Call setPixelColor() to write green to the array representing each LED in the strip
      • Call strip.show() to write to the strip
      • Wait a moment and repeat until all LEDs have been written green
  • while(1) //This is a continuous loop
    • Call sensor()
      • Call getdistance() 1000 times
        • Gets ADC0 value and converts it to inches
        • Returns distance in inches as float
      • Calculate average distance from the 1000 samples
      • Round distance to nearest inch
      • Transmit distance to vehicle module
      • Display distance on 7-segment LED
      • Returns the distance in inches as float
    • If distance > stop point
      • Call colorDistance(), to set the LEDs red/green based on distance
        • Determines what color each LED in the strip should be (red/green)
        • Calls setPixelColor() to write to an array representing the LED strip
        • Calls strip.show() to write to the LED strip
    • If distance <= stop point
      • Call colorFlash() to flash the LEDs red, all at once
        • Calls setPixelColor() and strip.show() to set all LEDs red
        • Waits a moment, and then turns them all off
Garage Module software flow diagram


Garage Module software flow diagram


Vehicle Module Pseudocode and Software Flow Diagram

Main() function
  • Clear LED display
  • while(1) //This is continuous loop
    • Call car() to perform Vehicle Module functions

Car() function

  • Set up P1.20 as GPIO output signal for Garage remote control
  • Set up P1.1 as GPIO output signal for garage LED2 indicator
  • Setup PWM4 signal for 4.5KHz frequency
  • Set distance to 0 inches and count to 0
  • Initialize garageIsOpen variable to false.

while(1) //This is continuous loop

  • If mesh packet is received from Garage module
    • If garage is not open
      • Send 500ms pulse to open garage door
      • Light up open garage door LED indicator for 500ms
      • Set GarageIsOpen variable to true
    • Deform mesh packet to get distance data in inches
    • If distance > 99
      • Display 99 inches on 2-digit LED display
    • If distance < 99
      • Display actual distance on 2-digit LED display
    • If distance > stop distance
      • Send PWM signal to sound piezo buzzer
    • If distance < stop distance
      • Stop sending PWM signal to piezo buzzer
  • Else no mesh packet is received from Garage module
    • Increment count by 1
    • If count > 1000
      • Clear LED display
      • Stop sending PWM signal to piezo buzzer
GarageParkingAssistantVehicleFlowDiagram.png

Software flow diagram - Vehicle Module

Implementation

Rangefinder to microcontroller
The rangefinder to microcontroller communication was implemented using an ADC. The rangefinder outputs an analog voltage between 0-3.3V. This voltage corresponds to the distance of the approaching vehicle between 0-254 inches. In order to obtain more stable readings we sample the ADC 1000 times and use the average for each reading. Additionally, we opted to only process the data when the distance was less than 99 inches. We did this for two reasons. First, output of the rangefinder becomes very jittery at distances greater than ~10ft, so we chose to ignore those distances. Second, the on-board LED display on the board only has two digits, so 99 is the greatest distance (in inches) that we could display.

Microcontroller to LED strip
The microcontroller to LED strip communication was implemented using SPI. Each LED on the strip is powered by a driver IC (LPD8806). The driver IC's on the strip are daisy-chained together. Only two data pins from the microcontroller are used: MOSI and CLK. All driver IC's are inherently enabled. The MOSI pin from the microcontroller only connects to the first driver IC, to start the daisy chain. Because the drivers are daisy-chained, any time one driver gets updated, they all get updated.

Garage Module to Vehicle Module
The garage module to vehicle module communication was implemented using the Nordic wireless IC on each board. The mesh network drivers were used to interface with the Nordic IC. The garage module tranmits the distance and the vehicle module receives it. Acknowledgement was not used to improve throughput.

Microcontroller to Piezo Buzzer
The microcontroller to piezo buzzer communication was implemented using PWM. The microcontroller outputs PWM signal of approximately 3.3V. The piezo buzzer operates nominally at 5V. The volume of the alarm can be adjusted by the duty cycle and different sounds can be produced based upon different frequencies. In the alarm application, the frequency was set to within the human hearing frequency range and duty cycle is set at 50% for maximum volume. The software initializes the PWM output and the frequency. Using set(duty cycle) function from the PWM class, 50% is used to turn on alarm and 0% is used to turn OFF alarm.

Microcontroller to Garage Door Remote Control
The microcontroller to garage door remote control communication was implemented using GPIO. To open the garage door, a pulse equivalent to pushing down on a push button switch is sent. First, the GPIO pin is initialized by setting the pin corresponding to FIODIR to output. In order to simulate 500 millisecond pulse, microcontroller sends high (3.3V) GPIO signal for 500 milliseconds and then sets it low using FIOSET and FIOCLR.

Microcontroller to 7-segment LED display
The microcontroller to 7-segment LED display communication was implemented using I2C. However, LED class and its functions have already been created to display digits to LED display so LED display code development was not needed. The set(char num) function was called to display distance on LED. If the distance exceeds 99 inches, the LED display will be set to 99. After not receiving data from Garage module for 1000 mesh packets, the clear() function was used to clear LED display.

Testing & Technical Challenges

Garage Module Testing

The garage module functions were first tested separately and then combined to verify they worked together.

1. The first garage module function tested was the ADC. To test the ADC we programmed the garage module to output the distance on the on-board 7-segment display. We then practiced moving the rangefinder around and pointing at various objects to get a feel for its capabilities.

Early stage testing of ultrasonic rangefinder and ADC
Early stage testing of ultrasonic rangefinder and ADC

Below is a close-up of the microcontroller. The LED display indicates the distance to the wall: 7 feet.

Display indicates a range of 7 feet
Display indicates a range of 7 feet

2. The second garage module function tested was the LED strip. We ran a demo loop with only the LED strip connected to verify that it functioned properly.

Below is an animated picture demonstrating the capabilities of the LED Strip.

Testing the RGB LED Strip
Testing the RGB LED Strip

3. Final test step of the garage module was to integrate the input from the rangefinder with the output on the LED strip. We mounted the LED strip and rangefinder on the wall of the garage and moved objects across the beam of the rangefinder. We verified that the LED strip updated accordingly.

Below is an animated picture demonstrating the capabilities of the LED Strip. The strip is programmed with a stopping point of 32 inches.
Testing complete garage module‎
Testing the complete garage module

Vehicle Module Testing

The Vehicle Module individual testing consisted of:

1. GPIO was initially placed into a separate function, in which a pushbutton on the SJ OneBoard sends GPIO signal to the garage remote control. The garage remote control LED light was monitored to ensure it lit up when GPIO signal was sent.

2. Piezo Buzzer was tested for different frequencies to determine the frequency with the loudest noise. The piezo buzzer was tested at the following frequencies: 2kHz, 4kHz, 4.5kHz, 6kHz, and 10kHz. It was determined the loudest sound was from the piezo buzzer's datasheet resonant frequency of 4.5kHz at 85dB.


The Vehicle Module integration testing consisted of:

1. Initial test to ensure the Vehicle and Garage module can perform wireless communication by following the commander and light node example.

2. Tested the distance data is being sent from Garage module to Vehicle module. We used printfs and displayed on the 7 segment LED on both modules.

3. Tested the garage remote control will activate only on the first package received from garage microcontroller

4. Tested piezo buzzer will turn off at less than per-determined stop distance. However, we also discovered piezo buzzer needs to stop when it stops receiving wireless signal from Garage Module.

System Integration Testing

1. Board to board communication: The first step to integrating our system was to establish wireless communication between the two boards. For this task, the garage module read the distance from the rangefinder and displayed it on the LED. At the same time it also transmitted the value to the vehicle module, which also displayed the value on the LED. Verifying good communication was as simple as comparing the two LED's side by side and verifying that they were in sync.

2. Complete system: The complete system test was performed exactly as the product is designed to work during actual use. We mounted the garage module on the wall of the garage. We mounted the vehicle module in the car. We started with the car out-of-range from the garage module. We drove the vehicle towards the garage and verified that the vehicle module flashed it's lights and opened the garage door when it received a signal from the garage module. We continued driving the vehicle into the garage towards the garage module, verifying that the distance displayed on the vehicle module and the lights on the LED strip decremented properly. Finally, as the vehicle reached its stop point, we verified that the vehicle module sounded the audible alarm and the garage module flashed the red LEDs on the strip.

My Issue #1: RS232 and UART

The Ultrasonic Rangefinder (LV-EZ1) outputs data as an RS232 signal. The intent was to read this signal using the SJOne's UART connection along with the provided drivers. The problem was that we were reading garbage data. The cause was an incompatibility between the RS232 signal and the provided drivers. The provided UART drivers expect 0V = Logic LOW, and 3.3V (Vcc) = Logic HIGH. The the rangefinder outputs a modfied RS232 signal. The modified RS232 is defined as 0V = Logic HIGH, and 3.3V (Vcc) = Logic LOW. Data was becoming corrupted due to being inverted. Our solution was not to use the serial output of the rangefinder. Instead we used the alternate analog output of the rangefinder in conjunction with the ADC on the SJOne. Other possible solutions include: Updating the micro-controller software to accept the inverted signal, or use the PWM output of the rangefinder.

My Issue #2: PWM and Piezo buzzer

The SJ One Board has capability to output PWM signal to create a sound from the piezo buzzer. However, there was an issue with my computer in which no sound was produced after the initial click. Once the new SourceForge was used, the PWM signal worked. However, during the time I was troubleshooting to ensure the piezo buzzer was not damaged, GPIO output was used to generate PWM. A PWM signal was generated when implementing delays, a for loop and setting GPIO signal high or low.

My Issue #3: Daisy-chain SPI and Nordic wireless

We were having an issue with the LED strip displaying properly. It was functioning perfectly until we started transmitting using the Nordic IC. The strip would output the wrong colors and the LED patterns became garbled. The issue was that we were using SPI0 to communicate with both the LED strip and the Nordic IC. Normally having multiple devices on an SPI bus is not an issue, but we were the exception. We were using a daisy-chained LED strip, which means that all of the chips are inherently enabled. So every time we communicated with the Nordic chip we were also sending data to the LED strip. The fix was simple: We moved the LED strip over to SPI1.

Conclusion

At the start of this class, neither of us had very much previous experience with microcontrollers. But we gained a lot of new knowledge in this class through lectures and hands-on exercises. We were able to learn how to communicate using GPIO, ADC, PWM, and SPI interfaces. We were able to use the knowledge that we gained in this class to design, build, troubleshoot, test and deliver a fully functional product that met all of our specifications. The Garage Parking Assistant was an immense success.

If there was more time, we would have liked to implemented the following additions:

  • Vehicle module will determine whether to open/close garage door based distance data transmitted by Garage module
  • Allow user to program stopping point through push buttons on vehicle module

Project Video

Garage Parking Assistant Demonstration Video

Garage Parking Assistant Video Link.png

Project Source Code

References

Acknowledgement

We would like to thank Preet for teaching a successfully interesting and fun class.

References

List any references used in project.

LPC1758 Datasheet
LPC1758 User Manual
LPD8806 LED Driver IC Datasheet
LPD8806 LED Driver Library
LV-EZ Ultrasonic Rangefinder Datasheet
AVS Video Editor