Difference between revisions of "S15: Alarm Based Coffee Maker"
(→Parts List & Cost) |
(→Grading Criteria) |
||
(43 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Alarm Based Coffee Maker == | == Alarm Based Coffee Maker == | ||
== Abstract == | == Abstract == | ||
− | The purpose of this project is to help make mornings easier. The goal is to upgrade an existing coffee maker to allow it to be programmed via smartphone application | + | The purpose of this project is to help make mornings easier. The goal is to upgrade an existing coffee maker to allow it to be programmed via smartphone application using an alarm application on a user's smartphone. The user syncs their alarm clock settings through a Bluetooth connection with the coffee maker to automatically start brewing coffee as soon as the preset time is reached. In addition to brewing coffee the SJSU One board will also be able to play music until the user stops it by stepping in front of the coffee maker. |
== Objectives & Introduction == | == Objectives & Introduction == | ||
Line 33: | Line 21: | ||
== Schedule == | == Schedule == | ||
− | |||
{| class="wikitable" | {| class="wikitable" | ||
Line 75: | Line 62: | ||
| 5/25 | | 5/25 | ||
| Fix Bugs | | Fix Bugs | ||
− | | | + | | Half complete. |
|- | |- | ||
|} | |} | ||
== Parts List & Cost == | == Parts List & Cost == | ||
− | *Bluetooth Module:SiLabs HC-06 | + | *Bluetooth Module:SiLabs HC-06 $7 |
− | *Coffee Maker | + | *Coffee Maker $20 |
− | *Motion Sensor | + | *Motion Sensor $ 5 |
− | *Speakers | + | *Speakers $6 |
− | *Mp3 Module: WIG-11029 ROHS | + | *Mp3 Module: WIG-11029 ROHS - $50 |
− | *Android Phone: LG L15G | + | *Android Phone: LG L15G $40 |
+ | Total Cost : $128 | ||
== Design & Implementation == | == Design & Implementation == | ||
− | + | ||
=== Hardware Design === | === Hardware Design === | ||
− | + | All the pins were connected from the SJSU One Board to the other modules as shown in the figure below. The BT module and motion sensor required a Vcc of 3.3V, and were connected to the microcontroller, while the MP3 player required a Vcc of 5v and was connected to the USB. | |
+ | |||
+ | |||
+ | |||
+ | [[File:S15_Cmpe146_Coffee_Alarm_HardwareSchematic.png|200px|thumb|schematic]] | ||
=== Hardware Interface === | === Hardware Interface === | ||
− | In this | + | In this project the microcontroller communicates with its' peripheral devieces through a UART connection and GPIO pins. The Bluetooth module communicates through UART, it strips the bluetooth packets of all the wrappers and delivers a UART frame to the SJSU One Board. The smartphone sends a packet of data to the bluetooth module and the the bluetooth module relays it to the SJSU One Board. All other modules communicate through GPIO Pins, although the MP3 player needed to be initialized using UART. The uart frame sends 8 bits of data. The start is indicated by a high-to-low transition, and a stop is indicated by a low to high transition. When a frame is not being sent, the line is held HIGH as shown in the image below. |
+ | [[File:S15_Cmpe146_Coffee_Alarm_UartFrame.png]] | ||
=== Software Design === | === Software Design === | ||
− | + | The coffee maker alarm has software for two systems, the embedded system and the Android App. The embedded system is a collection of tasks that execute without user input, while the Android App gathers input from the user. | |
+ | |||
+ | == Android App == | ||
+ | *1. A User selects the bluetooth device connected to their coffee maker. (Screen 1) | ||
+ | - We decided to allow the user to select the device instead of hardcoding a MAC address so that we could use different bluetooth modules, and allow future users to easily use our app with their own bluetooth module. | ||
+ | - The precondition is that the BT module has been paired with the Android phone using the phones bluetooth settings. | ||
+ | - If the BT device establishes a connection with the phone, this screen will disappear and allow the user to enter a time. A connection is also indicated by a green LED light on the bluetooth module. | ||
+ | '''Pseudo code:''' | ||
+ | list_BT_devices(); | ||
+ | get_pairedDevice(); | ||
+ | create_BT_socket(); | ||
+ | create_connecting_Thread() | ||
+ | [[File:S15_Cmpe146_Coffee_Alarm_Menu.png|200px|thumb|left|app screenshot]] | ||
+ | |||
+ | |||
+ | [[File:S15_CmpE146_Coffee_Alarm_Screen1.jpg|200px|thumb|left|app screenshot]] | ||
+ | *2. Entering the time (Screen 2) | ||
+ | - A user selects the time at which they would like their coffee maker to wake them up. | ||
+ | - A user must touch the time picker at least once for the time to be registered by the device. | ||
+ | - Once the correct time is chosen the user clicks the button that says "send hour". This button sends 2 bytes, one representing the hour and one representing the minute.The hour is sent in 24 hr format. | ||
+ | '''Pseudeo code''': | ||
+ | gethour(); | ||
+ | getmin(); | ||
+ | sendhour(); | ||
+ | sendmin(); | ||
+ | |||
+ | == Free RTOS Tasks == | ||
+ | There are a total of seven tasks that were implemented using wrapper functions. They are meant to run the smart coffee maker with only the alarm time as a manual input. | ||
+ | * Task 1. Bluetooth task | ||
+ | -In this task all shared objects are initialized along with UART2. Along with initialization, in its run function , this task receives two inputs from an Android phone via Bluetooth module. The two inputs serve as the desired hour and minute for the coffee maker alarm. They are received as characters but are then converted into unsigned long integers and sent to the next task. | ||
+ | |||
+ | *Task 2. myClock task | ||
+ | -This task uses the data captured by the Bluetooth task and compares the hour and minute to the current time. If the time does not match, the task is put to sleep for thirty second increments until compared again. Once the desired time is reached, an integer type flag labeled 'value' is sent to the next task. | ||
+ | |||
+ | *Task 3. relay_control task | ||
+ | -This is the main task that has control over all other tasks. The main purpose of this task is to either open or close the relay attached to the coffee maker to turn it on or off. It is set up so that when it receives the 'value' flag to turn on the coffee maker, it will disable the Bluetooth task and myClock task to reduce CPU usage and prevent any more interrupts. Along with terminating those two tasks, it is also responsible for controlling the music_player, music_player_stop, myCoffeeTimer and motion_detector tasks. | ||
+ | |||
+ | *Task 4. myCoffeeTimer task | ||
+ | -This task is started once the relay control task has turned on the coffee maker. Its' purpose is to keep count for thirty minutes. Once that time has been reached it sends a flag back to the relay_control task to turn off the coffee maker and resume the Bluetooth and myClock tasks. | ||
+ | |||
+ | *Task 5. motion_detector task | ||
+ | -This task is initiated once the coffee maker is turned on. It monitors a GPIO pin connected to the output pin of a PIR motion detector. Its purpose is to toggle the music player on and off. Once coffee maker is turned off, this task is once again disabled. | ||
+ | |||
+ | *Task 6. music_player task | ||
+ | -This task controls two GPIO pins. One pin will always be set to a logic 1, which is connected to a pin to stop the music player, the other pin will always be set to a logic 0. The second pin is connected to a pin that will trigger a song to be played. Since the music player has active low pins. this task will initiate a song to be played. | ||
+ | |||
+ | *Task 7. music_player_stop task | ||
+ | -This task also controls the same two GPIO pins and is never active at the same time as the music_player task. Its functions are similar but the logic levels of both pins are reversed, stopping music playback. | ||
=== Implementation === | === Implementation === | ||
Line 103: | Line 143: | ||
== Testing & Technical Challenges == | == Testing & Technical Challenges == | ||
− | + | This project brought together various modules into one system. Each unit needed specialized code to function correctly, and each module except for the relay needed troubleshooting. We had issues with the mp3 player, the motion sensor, the bluetooth module, and the Android device. | |
− | |||
− | |||
− | === | + | === The mp3 player #1 === |
− | + | The mp3 player that was originally chosen was the Adafruit VS1053. This module was simply a decoder and transferred data back to a microcontroller board. We attempted for 3 days to understand how to handle this data, however the transfer format was something that we were not familiar with (dual mode spi). We did not have sufficient time in this class learn about how to implement music playback from the decoded data or how to implement dual mode spi. We decided to select another module which was easier to use and communicated via UART and had an easy to read datasheet with clear instructions. The mp3 player selected was the WIG-11029 ROHS, as listed in the parts section above. | |
+ | === The motion sensor #2 === | ||
+ | The motion sensor gave us difficulty because it was not very sensitive at first, but became more sensitive later in the project. We had to go back and change the sensitivity of the motion sensor to get accurate data. The sensitivity was changed using a knob on the back of the motion-sensor module. | ||
+ | === The bluetooth module and Android Device #3 === | ||
+ | We spent many weeks trying to get the bluetooth to connect with our Android phone. At first, we connected the bluetooth module with a 3rd party App, Blue SPP, from the google play store to verify that it would connect to our phone. We were able to send and receive data. After a few weeks, the module stopped establishing a connection with any bluetooth app. It would pair but not connect. We tried 3 different bluetooth modules with the same results. We also did a factory reset on the cellphone. We then came across a developer's forum stating that HTC brand phones were know to have inconsistency with bluetooth connections. They would work fine under some circumstances than the fail. We purchased a new cellphone and the bluetooth connected successfully again. We then continued to develop our own bluetooth app. | ||
+ | === The Android Studio IDE #4 === | ||
+ | Android Studio IDE is the official IDE for developing android Apps. It intuitive to use, and look similar to Visual Basic. It also comes with a large variety of examples of different functionality. We were confident that developing an app would be simple because Android studio had a sample bluetooth chat App that worked with the bluetooth serial port profile (SPP). However, the sample app did not work. When loaded on multiple devices, it would fail to connect to our bluetooth device. We had to develop our App from scratch using the Android Developers reference pages and understand how everything worked in detail. We made multiple apps with varying degrees of functionality. It was extremely difficult to work with Android Apps because we did not have knowledge of the architecture or about creating multiple threads. We had to read a lot of forums, and debug almost every section of code. The last App that we made was stable, although by this time we were unable to make the app as visually appealing as we had hoped. | ||
== Conclusion == | == Conclusion == | ||
− | + | Overall, the project was more difficult that we could have imagined but we did learn a lot. We familiarized ourselves with developing android applications both on Android Studio and on Eclipse. We learned about interfacing bluetooth connections, including sockets and wrappers. The most significant thing that we learned was about the complexity of Android Apps. Because Android Apps work on a system that executes multiple things in the background, we need to use multiple threads to avoid blocking. We have never programmed with threads before and it was a difficult concept to grasp. It was also difficult to work with multiple classes to establish something as simple as establishing a bluetooth connection. We had difficulty working with the different classes because we only had a short time to familiarize ourselves with the IDE, and the Android architecture. | |
=== Project Video === | === Project Video === | ||
− | + | ||
=== Project Source Code === | === Project Source Code === | ||
Line 122: | Line 166: | ||
== References == | == References == | ||
=== Acknowledgement === | === Acknowledgement === | ||
− | + | We would like to thank all the people that contribute to stackoverflow.com. They were our best resource for answering questions. | |
=== References Used === | === References Used === | ||
− | + | http://developer.android.com/index.html | |
=== Appendix === | === Appendix === | ||
− |
Latest revision as of 04:51, 26 May 2015
Contents
Alarm Based Coffee Maker
Abstract
The purpose of this project is to help make mornings easier. The goal is to upgrade an existing coffee maker to allow it to be programmed via smartphone application using an alarm application on a user's smartphone. The user syncs their alarm clock settings through a Bluetooth connection with the coffee maker to automatically start brewing coffee as soon as the preset time is reached. In addition to brewing coffee the SJSU One board will also be able to play music until the user stops it by stepping in front of the coffee maker.
Objectives & Introduction
Show list of your objectives. This section includes the high level details of your project. You can write about the various sensors or peripherals you used to get your project completed.
Team Members & Responsibilities
- Patricia Mejia
- Android App Development
- Bluetooth Module & Task
- Bring up MP3 Module
- SJSU One Board Real Time Clock Setup;
- Alberto Reyes
- Relay Setup
- Alarm Task
- Mp3 Player Task
- Motion Sensor Task
- Interfacing All Tasks Together
Schedule
Week# | Date | Task | Actual |
---|---|---|---|
1 | 4/13 | Set up bluetooth connection between board and smartphone. | Complete |
2 | 4/20 | Complete bluetooth app and motion sensor on phone. | Complete |
3 | 4/27 | Setup mp3 player on SJSU One board. | Complete |
4 | 5/4 | Interface coffee maker and SJSU One board. | Complete |
5 | 5/11 | Interface coffee maker and SJSU One board. | Complete |
6 | 5/18 | Testeing | Complete |
7 | 5/25 | Fix Bugs | Half complete. |
Parts List & Cost
- Bluetooth Module:SiLabs HC-06 $7
- Coffee Maker $20
- Motion Sensor $ 5
- Speakers $6
- Mp3 Module: WIG-11029 ROHS - $50
- Android Phone: LG L15G $40
Total Cost : $128
Design & Implementation
Hardware Design
All the pins were connected from the SJSU One Board to the other modules as shown in the figure below. The BT module and motion sensor required a Vcc of 3.3V, and were connected to the microcontroller, while the MP3 player required a Vcc of 5v and was connected to the USB.
Hardware Interface
In this project the microcontroller communicates with its' peripheral devieces through a UART connection and GPIO pins. The Bluetooth module communicates through UART, it strips the bluetooth packets of all the wrappers and delivers a UART frame to the SJSU One Board. The smartphone sends a packet of data to the bluetooth module and the the bluetooth module relays it to the SJSU One Board. All other modules communicate through GPIO Pins, although the MP3 player needed to be initialized using UART. The uart frame sends 8 bits of data. The start is indicated by a high-to-low transition, and a stop is indicated by a low to high transition. When a frame is not being sent, the line is held HIGH as shown in the image below.
Software Design
The coffee maker alarm has software for two systems, the embedded system and the Android App. The embedded system is a collection of tasks that execute without user input, while the Android App gathers input from the user.
Android App
- 1. A User selects the bluetooth device connected to their coffee maker. (Screen 1)
- We decided to allow the user to select the device instead of hardcoding a MAC address so that we could use different bluetooth modules, and allow future users to easily use our app with their own bluetooth module. - The precondition is that the BT module has been paired with the Android phone using the phones bluetooth settings. - If the BT device establishes a connection with the phone, this screen will disappear and allow the user to enter a time. A connection is also indicated by a green LED light on the bluetooth module.
Pseudo code: list_BT_devices(); get_pairedDevice(); create_BT_socket(); create_connecting_Thread()
- 2. Entering the time (Screen 2)
- A user selects the time at which they would like their coffee maker to wake them up. - A user must touch the time picker at least once for the time to be registered by the device. - Once the correct time is chosen the user clicks the button that says "send hour". This button sends 2 bytes, one representing the hour and one representing the minute.The hour is sent in 24 hr format.
Pseudeo code: gethour(); getmin(); sendhour(); sendmin();
Free RTOS Tasks
There are a total of seven tasks that were implemented using wrapper functions. They are meant to run the smart coffee maker with only the alarm time as a manual input.
- Task 1. Bluetooth task
-In this task all shared objects are initialized along with UART2. Along with initialization, in its run function , this task receives two inputs from an Android phone via Bluetooth module. The two inputs serve as the desired hour and minute for the coffee maker alarm. They are received as characters but are then converted into unsigned long integers and sent to the next task.
- Task 2. myClock task
-This task uses the data captured by the Bluetooth task and compares the hour and minute to the current time. If the time does not match, the task is put to sleep for thirty second increments until compared again. Once the desired time is reached, an integer type flag labeled 'value' is sent to the next task.
- Task 3. relay_control task
-This is the main task that has control over all other tasks. The main purpose of this task is to either open or close the relay attached to the coffee maker to turn it on or off. It is set up so that when it receives the 'value' flag to turn on the coffee maker, it will disable the Bluetooth task and myClock task to reduce CPU usage and prevent any more interrupts. Along with terminating those two tasks, it is also responsible for controlling the music_player, music_player_stop, myCoffeeTimer and motion_detector tasks.
- Task 4. myCoffeeTimer task
-This task is started once the relay control task has turned on the coffee maker. Its' purpose is to keep count for thirty minutes. Once that time has been reached it sends a flag back to the relay_control task to turn off the coffee maker and resume the Bluetooth and myClock tasks.
- Task 5. motion_detector task
-This task is initiated once the coffee maker is turned on. It monitors a GPIO pin connected to the output pin of a PIR motion detector. Its purpose is to toggle the music player on and off. Once coffee maker is turned off, this task is once again disabled.
- Task 6. music_player task
-This task controls two GPIO pins. One pin will always be set to a logic 1, which is connected to a pin to stop the music player, the other pin will always be set to a logic 0. The second pin is connected to a pin that will trigger a song to be played. Since the music player has active low pins. this task will initiate a song to be played.
- Task 7. music_player_stop task
-This task also controls the same two GPIO pins and is never active at the same time as the music_player task. Its functions are similar but the logic levels of both pins are reversed, stopping music playback.
Implementation
This section includes implementation, but again, not the details, just the high level. For example, you can list the steps it takes to communicate over a sensor, or the steps needed to write a page of memory onto SPI Flash. You can include sub-sections for each of your component implementation.
Testing & Technical Challenges
This project brought together various modules into one system. Each unit needed specialized code to function correctly, and each module except for the relay needed troubleshooting. We had issues with the mp3 player, the motion sensor, the bluetooth module, and the Android device.
The mp3 player #1
The mp3 player that was originally chosen was the Adafruit VS1053. This module was simply a decoder and transferred data back to a microcontroller board. We attempted for 3 days to understand how to handle this data, however the transfer format was something that we were not familiar with (dual mode spi). We did not have sufficient time in this class learn about how to implement music playback from the decoded data or how to implement dual mode spi. We decided to select another module which was easier to use and communicated via UART and had an easy to read datasheet with clear instructions. The mp3 player selected was the WIG-11029 ROHS, as listed in the parts section above.
The motion sensor #2
The motion sensor gave us difficulty because it was not very sensitive at first, but became more sensitive later in the project. We had to go back and change the sensitivity of the motion sensor to get accurate data. The sensitivity was changed using a knob on the back of the motion-sensor module.
The bluetooth module and Android Device #3
We spent many weeks trying to get the bluetooth to connect with our Android phone. At first, we connected the bluetooth module with a 3rd party App, Blue SPP, from the google play store to verify that it would connect to our phone. We were able to send and receive data. After a few weeks, the module stopped establishing a connection with any bluetooth app. It would pair but not connect. We tried 3 different bluetooth modules with the same results. We also did a factory reset on the cellphone. We then came across a developer's forum stating that HTC brand phones were know to have inconsistency with bluetooth connections. They would work fine under some circumstances than the fail. We purchased a new cellphone and the bluetooth connected successfully again. We then continued to develop our own bluetooth app.
The Android Studio IDE #4
Android Studio IDE is the official IDE for developing android Apps. It intuitive to use, and look similar to Visual Basic. It also comes with a large variety of examples of different functionality. We were confident that developing an app would be simple because Android studio had a sample bluetooth chat App that worked with the bluetooth serial port profile (SPP). However, the sample app did not work. When loaded on multiple devices, it would fail to connect to our bluetooth device. We had to develop our App from scratch using the Android Developers reference pages and understand how everything worked in detail. We made multiple apps with varying degrees of functionality. It was extremely difficult to work with Android Apps because we did not have knowledge of the architecture or about creating multiple threads. We had to read a lot of forums, and debug almost every section of code. The last App that we made was stable, although by this time we were unable to make the app as visually appealing as we had hoped.
Conclusion
Overall, the project was more difficult that we could have imagined but we did learn a lot. We familiarized ourselves with developing android applications both on Android Studio and on Eclipse. We learned about interfacing bluetooth connections, including sockets and wrappers. The most significant thing that we learned was about the complexity of Android Apps. Because Android Apps work on a system that executes multiple things in the background, we need to use multiple threads to avoid blocking. We have never programmed with threads before and it was a difficult concept to grasp. It was also difficult to work with multiple classes to establish something as simple as establishing a bluetooth connection. We had difficulty working with the different classes because we only had a short time to familiarize ourselves with the IDE, and the Android architecture.
Project Video
Project Source Code
References
Acknowledgement
We would like to thank all the people that contribute to stackoverflow.com. They were our best resource for answering questions.
References Used
http://developer.android.com/index.html