Difference between revisions of "S13: Smart Cube"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Design & Implementation)
(Hardware Interface)
Line 285: Line 285:
 
'''PWM'''
 
'''PWM'''
 
[[File:CmpE146_S13_T2_HWDesign4.png|center|frame]]
 
[[File:CmpE146_S13_T2_HWDesign4.png|center|frame]]
 +
<div style="text-align: center;">'''Figure 0.0:''' LPC1758 SJSU Dev Board </div>
 +
 +
'''LED matrix Interface'''
 +
[[File:CmpE146_S13_T2_HWDesign5.png|center|frame]]
 
<div style="text-align: center;">'''Figure 0.0:''' LPC1758 SJSU Dev Board </div>
 
<div style="text-align: center;">'''Figure 0.0:''' LPC1758 SJSU Dev Board </div>
  

Revision as of 18:41, 18 May 2013

Grading Criteria

  • How well is Software & Hardware Design described?
  • How well can this report be used to reproduce this project?
  • Code Quality
  • Overall Report Quality:
    • Software Block Diagrams
    • Hardware Block Diagrams
      Schematic Quality
    • Quality of technical challenges and solutions adopted.

Smart CUBE

Abstract

This section should be a couple lines to describe what your project does.

Objectives & Introduction

Team Members & Responsibilities

  • Phuoc Tran
    • Interface LPC1758 with 8x8 RGB LED matrix using shift registers
  • Christopher Harris
    • Interface LPC1758 with WiFly module, server to WiFly communication and Website UI.


WeekPlanned TasksAchievement
1
  • Connect WiFly Module
  • Begin Communicating to WiFly via UART
  • Get familiar with the LED matrix and how to use shift registers 74HC595N
  • Successful
  • Successful
  • Successful
2
  • Begin Setting up Server for TCP/IP
  • Define Functions for Communication To and From Server
  • Design the circuit for RGB LED matrix
  • Successful
  • Successful
  • Successful
3
  • Implement and Test TCP/IP Communication Functions
    • Set Alarm
    • Send Weather (temp)
  • Interface LPC1758 board with the LED matrix
  • Successful
  • Successful
  • Successful
  • Successful
4
  • Implement the Functions on and off the board
    • Time
    • Alarm
    • Weather
  • Successful
  • Successful
  • Successful
5
  • Setup UI Interface
  • Connect UI to Functions
  • Successful
  • Successful
6
  • Polish and Test
  • Final Report

Parts List & Costs

ItemDetails Source Cost Ea. Qty. Total
MicroController LPC 1758 SJSU Dev Board Preet $60.00 x1 $60.00
Wifi Module RN-XV Wifly Sparkfun $37.99 x1 $37.99
RGB LED Display 8x8 RGB LED Matrix Ebay $5.99 x1 $5.99
Shift Register SN74HC595 Sparkfun $0.23 x3 $.69
Wire Female -> Female Jumper wire Sparkfun $0.28 x50 14.39
Wire 30 Gauge Wrapping wire Anchor $5.00 x1 $5.00
Prototyping board 6"x6" Perforated Prototyping board Anchor $6.99 x1 $6.99
IC Socket Socket IC 16 Pin Anchor $.37 x6 $2.25
Resistors 220 Ohm 1/4 Resistor Anchor $.06 x32 $1.92
Linux Server Raspberry Pi Ebay $35.00 x1 $35.00
Wireless Router Ti Link 703N Mini Router Frys $24.00 x1 $24.00

Design & Implementation

The main hardware components used in this project include:

  • LPC1758 Development Board
  • 8x8 RGB LED matrix
  • 74HC595 Shift Register
  • Buzzer
  • Wifly Module

LPC1758 Development Board

It is the CPU of the project. It communicates with devices or transfers communications between devices to perform tasks. The LPC1758 dev board is running under SJSU development package. The package contains most of drivers necessary for the CPU to communicate with devices such as SPI interface, PWM motor controller.

CmpE146 S13 T2 HWDesign0.0.png
Figure 0.0: LPC1758 SJSU Dev Board

8x8 RGB LED matrix

The figure below is the schematic of an 8x8 RGB LED matrix. It has the size of 60 mm square, and it contains 8 anode terminals and 24 cathode terminals in a total of 192 LEDs. 64 of the LEDs are red, 64 are Green, and the other 64 are Blue. The purpose and use of this LED matrix is very important in this cube because it is the main output of the project. It will display the real time time clock, alarm and email notifications, and temperature.

CmpE146 S13 T2 HWDesign0.1.png
Figure 0.1: LED schematic

74HC595 Shift Register

The purpose of the shift register in this project to take the serial inputs from the CPU and convert to both parallel outputs and serial outputs. Parallel outputs is use to turn on and off the LEDs. Serial outputs is used to feed into another shift register if applicable.

CmpE146 S13 T2 HWDesign0.2.png
Figure 0.2: Shift Register Logic Diagram

Buzzer

A buzzer is used to for alarm of email notifications. It will sound to notify that the alarm is on or someone just got a mail.

CmpE146 S13 T2 HWDesign0.3.png
Figure 0.3: Buzzer

Wifly Module (As discussed in the software implementation section)


CmpE146 S13 T2 HWDesign0.4.png
Figure 0.4: Wifly Module


Hardware Design

Figure 1 shows the block diagram of the whole circuit. It shows the basic idea of how all the devices or part are connected as well as their inputs and outputs.

CmpE146 S13 T2 HwDesign1.png
Figure 1: Block Diagram of system inputs and outputs


Figure 2 demonstrates more detail of circuit implementation. The circuit was built and tested on Logic Works. It shows the interface among the LPC board, LED matrix, and 3 shift registers. The red, green, and blue LEDs represents the corresponding ones of the RGB LED matrix. All Px.x pins (outputs), CLK, and MOSI are generated from the LPC 1758 board. The binary switches are used to test the behavior of the circuit when switching the output pins from high to low or vice versa.

CmpE146 S13 T2 HWDesign2.png
Figure 2: System schematic built and tested on Logic Works

Hardware Interface

In this section, you can describe how your hardware communicates, such as which BUSes used. You can discuss your driver implementation here, such that the Software Design section is isolated to talk about high level workings rather than inner working of your project.

SPI Interface

CmpE146 S13 T2 HWDesign3.png
Figure 0.0: LPC1758 SJSU Dev Board

PWM

CmpE146 S13 T2 HWDesign4.png
Figure 0.0: LPC1758 SJSU Dev Board

LED matrix Interface

CmpE146 S13 T2 HWDesign5.png
Figure 0.0: LPC1758 SJSU Dev Board

Software Design

CmpE146 S13 T2 SWDesign1.png
Figure 1: Data Task
CmpE146 S13 T2 SWDesign2.png
Figure 2: Service Task
CmpE146 S13 T2 SWDesign3.png
Figure 3: Terminal Task

Hardware Implementation

Software 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.

FreeRTOS

The basis for our software implementation required using FreeRTOS, a real-time operating system. FreeRTOS, which is provided in the SJSU Developer package for the LPC1758, utilizes C and C++. It allows for the implementation of task, semaphores and queues, all of which are managed by the operating system. The previous labs, as well as the tutorials available on the Social Ledge website served as a reference for our design and implementation.

WiFly

The management of the Wi-Fly and wifi connectivity was done in the services task. This task was responsible for initializing the Wi-Fly with the appropriate values and connecting to the defined SSID. With the Wi-Fly connected to a SSID it was the service task responsibility to ensure that a connection was established and maintained. With a connection obtained the Wi-fly module could access the smart cube website and receive data as a tcp client and server.

The pseudo code for connecting to a SSID and enabling the WiFly module as both a tcp client and server is as follows:

       //Set connection parameters
       Enable dhcp
       Define the ssid
       Define the protection type (wep, wpa, etc..)
       Define pw
       Define channel
       Define mask
       
       //Set communication parameters
       define close
       define open
       define remote
       
       //Set flush parameters
       set comm size
       set timeout length
       set idle time
       
       //Set TCP paramters
       set to client and server(variable “2”)
       define port number
       
       Save
       Reboot
Get Weather

In order to obtain the weather the smart cube acted as a tcp client utilizing the World Weather Online api at (api.worldweatheronline.com). Using this api we were able to configure the wi-fly module to request the weather in a http 1.0 format. In order to do so the Wi-Fly must act in TCP Client mode, connect to the source ip, and perform a “get” to retrieve the data desired. An example of getting the weather from the api is shown below:

       wifiSendCmd("open api.worldweatheronline.com 80");
       
       mWifi.put("GET http://api.worldweatheronline.com/free/v1/weather.ashx?q=CITYformat=csv&num_of_days=1&key=API-KEY HTTP/1.1");


From this http response we were able to parse the data looking for the temperature. The example format of the http response not including the header is as shown below:

       #The CSV format is in following way:-
       #First row will always contain the current weather condition. if for any reason we do not have current condition it will have 
               'Not Available'.
       #The current weather condition data is laid in the following way:-
       #observation_time,temp_C,weatherCode,weatherIconUrl,weatherDesc,windspeedMiles,windspeedKmph,winddirDegree,winddir16Point,
               precipMM,humidity,visibility,pressure,cloudcover
       #
       #The weather information is available in following format:
       #date,tempMaxC,tempMaxF,tempMinC,tempMinF,windspeedMiles,windspeedKmph,winddirDegree,winddir16Point,weatherCode,weatherIconUrl,
       weatherDesc,precipMM
       #
       05:04 AM,15,113,http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0008_clear_sky_night.png,Clear,11,17,320,NW,0.0
       ,63,16,1018,0,2013-05-15,21,70,11,52,13,21,320,NW,113,
       http://www.worldweatheronline.com/images/wsymbols01_png_64/wsymbol_0001_sunny.png,Sunny,0.0

The data can be obtained in various formats, including CSV, JSON, and XML. In our usage we found CSV the easiest format to parse, as we could easily traverse through the response using the “,” as our delimiter.

Get Email Count

8x8 Matrix

Web Interface

In order to send commands to the smart cube in an efficient and intuitive way a user interface was needed. Ideally an interface or solution that did not require installing a program or additional software on the users end. For this reason we utilized the already existing wireless features of our system to send commands from a website. The website functions included:

  • Setting the Alarm Time
  • Setting the City of the Weather
  • Defining the GMAIL Credentials
  • Setting the Time Interval
  • Future Features
Front End

The Front End of Web interface involved utilizing HTML, in conjunction with JavaScript to display and send data using JQUERY and AJAX to the back end. In designing the front end of the website our goal was simplicity and ease of navigation. In order to do so we utilized large interactive, self-intuitive buttons, and an IFrame to focus on pertinent information. Our implementation was all done by hand, using notepad++ and Filezilla as our ftp client. The buttons on our layout were obtained from http://dabuttonfactory.com, a neat tool that allows for the creation of custom buttons.

In order to send data to the back end of the server for processing, we utilized the JQUERY JavaScript plugin to post data to a PHP file. The PHP file could then analyze the data and perform the necessary functions as discussed in the next section. It is important to note, unlike other coding languages, Javascript is event driven. That is functions and operations are performed and when a specific event is triggered, such as a button click. One such example of an event driven function in javascript is the showing and removing of a button shadow when a cursor hovers over a button. Some sample code for this is shown below:

       $(".Shadow").hover(
           function() {
               $(this).attr("style", "box-shadow: none;");
            },
            function() {
               $(this).attr("style", "box-shadow: 0px 2px 22px #4B91A5;");
            }
       );

Note: this utilizes JQUERY which is denoted by the “$” identifier before the event function. This code is typically placed in the “OnLoad” portion of the javascript file.


Back End

The back end of the web interface implemented using PHP on a Linux Apache Server. We chose Linux because it was readily available on our development computers and we could deploy a mobile server using a raspberry pi. The back end PHP functions of our server consisted of:

  • Sending commands to the Wi-fly module via a TCP Connection
    • Set Alarm
    • Set City for Weather
    • Send Email Count
    • Setting the Time Interval for Weather and Email Notifications
  • Retrieving the email count from a RSS Gmail feed
Sending Commands to the Wi-Fly Module

In order to communicate to the board the server needed to send commands regarding the users action on the webpage. These commands included:

  • Alarm set HH MM
  • Alarm clear
  • Weather set CITYNAME
  • Email set USERNAME PASSWORD
  • Fetch set HOUR

The triggering of these commands is done when a user navigates to the various pages and submits data. When data is submitted on the webpage a jquery event is triggered and data is posted to the appropriate php file using ajax. The post contains the “action” or function to be called, and the various parameters needed in the command. When sending a command to the Wi-Fly module the server acts as a tcp client and connects to the wi-fly module at the designated ip and port 5555. Once connected the tcp client can send its desired information and the smart-cube will treat the information just as it would a command given over Uart-0.

Getting Email Count

The first set in attempting to obtain the email count on our server was creating a PHP file that would be called from the Wi-Fly board every time the Smart Cube requested the email count. This PHP’s file’s purpose was, with the given parameters, call its internal “get email” function. The parameters are passed to the PHP function in the url in the following format:

       www.smartcube.com/getemail.php?param1=value1&param2=value2

The parameters used in our case were just the email id and the email password. With this information PHP’s cURL utility in conjunction with Google’s atom feed would be able to retrieve the desired information.

In order to obtain the email count from google’s “atom” feed, the cURL library was used. cURL on in a primitive description is like a internet browser without the UI. It allows for a PHP to create a session and access webpages data in html format. For the purpose of collecting the email count of a Gmail account curl was used to create a secure connection to https://mail.google.com/mail/feed/atom. Once a oAuth connection was made data would be retrieved in a xml format similar to this:

       "<?xml version="1.0" encoding="UTF-8"?>
       <feed version="0.3" xmlns="http://purl.org/atom/ns#">
       <title>Gmail - Inbox for BLAHH@gmail.com</title>
       <tagline>New messages in your Gmail Inbox</tagline>
       <fullcount>100</fullcount>
       <link rel="alternate" href="http://mail.google.com/mail" type="text/html" />
       <modified>2013-5-12T12:33:48Z</modified>
       <entry>
       <title>Blahhh EMAIL</title>
       <summary>This is some sample summary text!!</summary>
       <link rel="alternate" href="http://mail.google.com/mail 
       account_id=BLAHH@gmail.com&message_id=123456&view=conv&extsrc=atom" type="text/html" />
       <modified>2012-5-12T12:12:44Z</modified>
       <issued>2012-5-12T12:12:44Z</issued>
       <id>tag:gmail.google.com,2004:1234567890</id>
       <author>
       <name>BLAHH Author</name>
       <email>FROM_EMAIL@Blahh.com</email>
       </author>
       </entry>
       <entry>"

The next part would be to parse the xml data looking only for the email count in our case. By accessing the xml tag “fullcount”, as a SimpleXMLElement, we were able to parse the response for the current unread email count.

More information regarding cURL and its used in PHP can be found here: http://php.net/manual/en/book.curl.php

Testing & Technical Challenges

Describe the challenges of your project. What advise would you give yourself or someone else if your project can be started from scratch again? Make a smooth transition to testing section and described what it took to test your project.

Include sub-sections that list out a problem and solution, such as:

Wifi Connection Issues

Many wifi connection issues were encountered. To solve this problem, a dedicated task was created to re-connect to wifi if the connection was ever lost.

Conclusion

Conclude your project here. You can recap your testing and problems. You should address the "so what" part here to indicate what you ultimately learnt from this project. How has this project increased your knowledge?

Project Video

Upload a video of your project and post the link here.

Project Source Code

Send me your zipped source code and I will upload this to SourceForge and link it for you.

References

Acknowledgement

Any acknowledgement that you may wish to provide can be included here.

References Used

List any references used in project.

Appendix

You can list the references you used.