Difference between revisions of "S17: Interactive Snake and ladder"

From Embedded Systems Learning Academy
Jump to: navigation, search
(Objectives & Introduction)
(Project Title)
 
(332 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== Grading Criteria ===
+
== Project Title ==
<font color="green">
+
<b>Snake and Ladder</b>
*  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.
 
</font>
 
  
== Project Title ==
+
[[File:CMPE244_S17_SnL_Product.JPG|850px|centre|thumb|Complete Product]] <br>
'''Interactive Snake and Ladder
 
  
 
== Abstract ==
 
== Abstract ==
Interactive Snake and Ladder is a simulation of traditional snake and ladder game using SJONE board,LCD and 2 wireless remotes. LCD display is connected to the SJONE board will display the game board. 2 wireless remotes will be interfaced with SJONE board to simulate dice functionality for two users.
+
This project aims to bring the fun and simplicity of the classic board game snake and ladder to the digital world. The game console is implemented using a TFT LCD connected SJone board interacting with players holding wireless remotes implemented on SJone boards. The TFT display on the SJone board will show the game grid. A player can enroll in the game and roll dice using the remote SJone board. The device also supports dynamic multiplayer feature that will allow more than one players to play the game with wireless SJOne remotes simultaneously. Any SJone with nordic wireless can be programmed to function as a remote without any additional expensive hardware. All major game events are announced with audio prompts as well. This project explores a new dimension in the traditional snake game to make it more interesting and challenging.
  
 
== Objectives & Introduction ==
 
== Objectives & Introduction ==
Features:
 
  
1. Simulation of snake and ladder game.
+
This game aims to change the way people think of traditional snake game. It will offer the experience of multiplayer games to the player retaining the simplicity of traditional snake game.
2. 2 Wireless module to simulate dice functionality.
+
The major objectives of this project are:
3. Speech output for events
+
* To create a snake and ladder game that will have all the functionality of traditional snake and ladder games.
 +
* Introduce multiplayer functionality in the game that will allow several players to play a game simultaneously. It should be able to give the experience of a real-time multiplayer game to the players.
 +
*To introduce audio announcement of events.
  
Challenges:
+
===Roles & Responsibilities===
 +
* Hardware and PCB designing
 +
** [https://www.linkedin.com/in/bhupendran1 Bhupendra Naphade]
 +
* Speech Module Interface and Algorithm
 +
** [https://www.linkedin.com/in/aniket-bapat-0418a4a1 Aniket Bapat]
 +
* LCD Interface and Game board Algorithm
 +
** [https://www.linkedin.com/in/saurabh-deshmukh0911 Saurabh Deshmukh]
 +
** [https://www.linkedin.com/in/abhishek-singh21 Abhishek Singh]
 +
* Wireless Communication
 +
** [https://www.linkedin.com/in/jerry-john-92470425 Jerry John]
  
1. PCB designing to avoid electrical interference
+
== Schedule ==
2. Algorithm development for snake and ladder game.
 
3. Achieving high refresh rate on LCD to get real time display effect
 
4. Figuring out communication protocol for wireless
 
  
=== Team Members & Responsibilities ===
 
  '''
 
  Abhishek Singh
 
  Aniket Bapat
 
  Bhupendra Naphade
 
  Jerry John
 
  Saurabh Deshmukh
 
  
  '''
 
 
== Schedule ==
 
 
'''Team Schedule'''
 
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! scope="col"| SI No.
+
! scope="col"| <span style="color:#0000FF">Week </span>
! scope="col"| Start Date  
+
! scope="col"| <span style="color:#0000FF">Start Date</span>
! scope="col"| End Date
+
! scope="col"| <span style="color:#0000FF">End Date</span>
! scope="col"| Task  
+
! scope="col"| <span style="color:#0000FF">Task</span>
! scope="col"| Status
+
! scope="col"| <span style="color:#0000FF">Status</span>
! scope="col"| Actual Completion Date
+
! scope="col"| <span style="color:#0000FF">Actual Completion Date</span>
 
|-
 
|-
 
! scope="row"| 1
 
! scope="row"| 1
| 03/14/2017
+
| 3/21
| 03/21/2017
+
| 3/25
 
|  
 
|  
* Project proposal submission.
+
* Requirement analysis
* Dividing module ownership among the team members.
+
* Component identification and purchase.
* Decide on components required.
+
* Task allocation based on different modules in project
| Completed
+
| Complete
| 03/21/2017
+
| 3/25
 
|-
 
|-
 
! scope="row"| 2
 
! scope="row"| 2
| 03/21/2017
+
| 3/25
| 03/28/2017
+
| 3/29
|
 
* Brainstorm on the hardware and software design.
 
* List the interfaces and order the components.
 
| In Progress
 
 
|  
 
|  
 +
* Design Hardware schematic
 +
| Complete
 +
| 3/29
 
|-
 
|-
 
! scope="row"| 3
 
! scope="row"| 3
| 03/29/2017
+
| 3/29
| 04/04/2017
+
| 4/9
|
 
* Design the PCB and place order for fabrication.
 
* Start the software implementation of the interface for DC Motor, Stepper Motor and UART for Bluetooth communication with the Android application.
 
| Not Started
 
 
|  
 
|  
 +
* PCB design and placing order for fabrication
 +
|Complete
 +
| 4/10
 
|-
 
|-
 
! scope="row"| 4
 
! scope="row"| 4
| 04/05/2017
+
| 3/29
| 04/11/2017
+
| 4/8
 
|
 
|
* Implement a basic Android application.
+
* Interface LCD with the SJOne board
* Test all the modules stand-alone by integrating each of them with the SJOne Board.
+
* Project report update on wiki
| Not Started
+
| Complete
|  
+
| 4/8
 
|-
 
|-
 
! scope="row"| 5
 
! scope="row"| 5
| 04/12/2017
+
| 3/30
| 04/18/2017
+
| 4/14
|
 
* Implement the control of the camera via Bluetooth.
 
| Not Started
 
 
|  
 
|  
 +
* Establish wireless connection between boards using nordic wireless
 +
* Text to speech interface
 +
* Project report update on wiki
 +
| Complete
 +
|4/14
 
|-
 
|-
 
! scope="row"| 6
 
! scope="row"| 6
| 04/19/2017
+
| 4/11
| 04/25/2017
+
| 4/20
|
 
* Complete the development and testing of all modules stand-alone.
 
| Not Started
 
 
|  
 
|  
 +
* Algorithm design and implementation
 +
* Identify common data elements
 +
| Complete
 +
|4/20
 
|-
 
|-
 
! scope="row"| 7
 
! scope="row"| 7
| 04/26/2017
+
| 4/20
| 05/02/2017
+
| 4/22
|
 
* Integrate all the modules and test for functionality as a unit.
 
* Ensure that the motor responds to the commands provided by the application accurately.
 
| Not Started
 
 
|  
 
|  
 +
* Integration of modules and hardware package buildup
 +
| Complete
 +
|4/22
 
|-
 
|-
 
! scope="row"| 8
 
! scope="row"| 8
| 03/05/2017
+
| 4/23
| 10/05/2017
+
| 4/31
|
+
|
* Final testing and debugging phase.
+
* Integration testing and bug fix
* Update project report and prepare for demo.
+
* Project report update on wiki
| Not Started
+
| Complete
 +
|4/31
 +
|-
 +
! scope="row"| 9
 +
| 4/26
 +
| 5/5
 +
|  
 +
* Extra feature identification and implementation
 +
* Project report update on wiki
 +
| Complete
 +
|5/6
 +
|-
 +
! scope="row"| 10
 +
| 5/5
 +
| 5/21
 
|  
 
|  
 +
* Testing and Debugging
 +
* Project report update on wiki and final presentation
 +
| Complete
 +
|5/21
 
|-
 
|-
 +
! scope="row"| 11
 +
| 5/21
 +
| 5/25
 +
|
 +
* Wiki Report completion and Final Demonstration
 +
| Complete
 +
|5/25
 
|}
 
|}
  
 
== Parts List & Cost ==
 
== Parts List & Cost ==
Give a simple list of the cost of your project broken down by components. Do not write long stories here.
+
 
 +
 
 +
{| class="wikitable"
 +
! width="30" align="center"|Qty
 +
! width="350" align="center"|Description
 +
! width="110" align="center"|Manufacturer
 +
! width="130" align="center"|Part Number
 +
! width="60" align="center"|Total Cost
 +
|-
 +
| align="center"|1||RA8875 Driver Board||Adafruit||PRODUCT ID: 1590||align="right"|$34.95
 +
|-
 +
|align="center"|1||LCD Display||Adafruit||PRODUCT ID: 2353||align="right"|$47.50
 +
|-
 +
| align="center"|1||Emic 2 Text to speech module||Parallax.inc||PRODUCT ID: 30016||align="right"|$60.00
 +
|-
 +
| align="center"|1||PCB||PCBWay||Custom made||align="right"|$10
 +
|-
 +
| align="center"|1||Bergstrip male/female||Amazon.com||N/A||align="right"|$0.5
 +
|-
 +
| align="center"|1||5V voltage regulator ||On-semiconductor||LM-7805||align="right"|$0.43
 +
|-
 +
| align="center"|1||LED||Kingbright||N/A||align="right"|$0.19
 +
|-
 +
| align="center"|1||Resistor 100ohm||Excess Solution||N/A||align="right"|0.1$
 +
|-
 +
| ||'''Total Cost''' (excluding shipping and taxes)|| || ||align="right"|'''$153.67'''
 +
|-
 +
|}
  
 
== Design & Implementation ==
 
== Design & Implementation ==
The design section can go over your hardware and software designOrganize this section using sub-sections that go over your design and implementation.
+
=== Overall System ===
 +
*The overall system is divided into 3 functional parts:
 +
**'''Game board (TFT LCD) console and display:''' The snake and ladder board grid is displayed on the 7 inches LCD screen.   
 +
**'''Wireless SJone remote:''' The antenna connected SJone board functioning as the remote which receives commands from master and sends button press information back. The basic use of the SJone remote board is to enroll in a new game and throw dice.
 +
**'''Audio prompts:''' Based on the actions performed the audio file gets executed. To make a game more effective and attractive.
 +
All these functionalities work in parallel and have the same priorities. <br>
 +
<br>[[file: CMPE244_S17_SnL_System_Diagram.jpg|600px|centre|thumb|System Block Diagram]] <br>
 +
 
 +
[[File:CMPE244_S17_SnL_Project_flow.gif|900px|centre|thumb|Project Flow]] <br>
  
=== Hardware Design ===
+
=== Printed Circuit Board ===
Discuss your hardware design here.  Show detailed schematics, and the interface here.
 
  
=== Hardware Interface ===
+
To reduce the number of hanging wires used for connecting SJ one board to other modules, we have decided to design a PCB. This facilitated us to accommodate both the modules(Text to speech and LCD) on a single PCB with a single cable between PCB and SJ one board.This way we were able to accommodate all the modules using the single PCB.  
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.
 
  
=== Software Design ===
+
=====Schematic and PCB Layout=====
Show your software design. For example, if you are designing an MP3 Player, show the tasks that you are using, and what they are doing at a high level. Do not show the details of the code. For example, do not show exact code, but you may show psuedocode and fragments of code. Keep in mind that you are showing DESIGN of your software, not the inner workings of it.
+
Below is the schematic diagram created during PCB design. It includes the power supply, interfaces for LCD controller and text to speech module. The PCB layout developed using Eagle PCB and Altium designer. SJ one board, RA8875 controller and the Evic 2 module work on 5V power supply. RA8875 TFT controller communicates with SJ one over SPI bus while the Evic 2 module communicates on the UART of SJ one board.<br>
 +
[[File:CMPE244_S17_SnL_Schematic_Daigram.JPG|600px|centre|thumb|Schematic Design]]<br>
 +
[[File:CMPE244_S17_SnL_PCB_Layout_All_Layer.JPG|600px|centre|thumb|PCB Layout]]<br>
 +
[[File:CMPE244_S17_SnL_Final_PCB_Top_n_Bottom.jpeg|600px|center|thumb|Final PCB]]
 +
<br><br>
  
=== Implementation ===
+
=== TFT display and RA8875 Driver Board ===
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.
+
 
 +
'''TFT Display'''
 +
<br>This 7.0" TFT screen has resolution of 800x480 pixels and a LED backlight.The display is supposed to be constantly refreshed, at 60Hz, with a pixel clock, V-sync, H-sync, etc.This display is operated by RA8875 Driver board.A 40-pin connector has 8 red, 8 green, and 8 blue parallel pins, for 24 bit color capability.
 +
<br>[[File:CMPE244_S17_SnL_RA8875_and_TFT.jpg|centre|thumb|600px|left|TFT LCD display and RA8875 driver]] <br>
 +
 
 +
'''RA8875 Driver Board'''
 +
 
 +
RA8875 is a text/graphic mixed TFT display controller with 2 layer support which is a powerful yet cheap choice for the color display application. It is designed to meet the requirement of middle size TFT module up to 800x480 pixels with characters or 2D graphic application. Embedded 768KB display RAM provides the user a flexible solution for display buffer of most applications. RA8875 supports a 2D Block Transfer Engine(BTE) that is compatible with 2D BitBLT function for processing mass data transfer.
 +
 
 +
<b>Features:</b>
 +
*Support Text/Graphic Mixed Display Mode.
 +
*Embedded 768KB DDRAM.
 +
*Color Depth TFT: 256/65K Colors.
 +
*Supporting TFT 8/16 bpp Generic RGB Interface.
 +
*Powerful Block Scrolling Function for Vertical or Horizontal Direction.
 +
 
 +
<b>Hardware Design</b><br>
 +
The RA8875 driver is interfaced with SJ one board using SPI bus. Below is the interface diagram. <br>
 +
[[File:CMPE244_S17_SnL_SJOne_LCD_Interface.jpeg|centre|750px|thumb|TFT display Inteface]]<br><br>
 +
 
 +
=== Text to Speech Module ===
 +
 
 +
In Emic 2 Text-to-Speech(TTS) module we use UART protocol for communication with microcontroller. In this project, UART3 of the Sjone board is used for interface. This module has own commands for the text to speech conversion, voice selection, volume change.
 +
*The pin configuration for Emic 2 TTS module is:
 +
**SOUT – UART (RxD3)
 +
**SIN – UART (TxD3)
 +
**5V – 3.3V (on board)
 +
**GND - GND
 +
 
 +
*It's key features of Emic2 text-to-speech are as follows:
 +
**High-quality speech synthesis for English and Spanish languages.
 +
**Nine pre-defined voice styles comprising male, female, and child.
 +
**Dynamic control of speech and voice characteristics, including pitch, speaking rate, and word emphasis.
 +
**Industry-standard DEC talk text-to-speech synthesizer engine (5.0.E1).
 +
**on board 3.5mm audio jack
 +
[[File:text to speech.png|left|220px|thumb|Text to speech]]
 +
[[File:text to speech pinout.png|300px|thumb|Text to speech pinout]]
 +
[[File:text to speech pin connection.png|center|300px|thumb|Text to speech pin connection]]
 +
<br>
 +
 
 +
<br>[[File:text to speech commands.png|450px|thumb|centre|Text to speech commands]]<br>
 +
 
 +
=== Nordic wireless ===
 +
SJone board is equipped with a Nordic wireless chip nRF24L01+ manufactured by the Nordic Semiconductors which can be configured and used through SPI interface. The air data rate, operating modes, and RF channel frequency need to be set by configuring the registers in the nRF24L01+. The nRF24L01 is a highly integrated, ultra low power (ULP) 2Mbps RF transceiver IC for the 2.4GHz ISM (Industrial, Scientific, and Medical) band. With peak RX/TX currents lower than 14mA, a sub μA power down mode, advanced power management, and a 1.9 to 3.6V supply range. The nRF24L01 integrates a complete 2.4GHz RF transceiver, RF synthesizer, and baseband logic including the Enhanced ShockBurst™ hardware protocol accelerator supporting a high-speed SPI interface for the application controller. No external loop filter, resonators, or VCO varactor diodes are required, only a low-cost ±60ppm crystal, matching circuitry, and antenna.
 +
 
 +
=== Master SJone console ===
 +
<br>
 +
[[File:CMPE244_S17_SnL_Master_Module.jpeg|centre|500px|thumb|Integrated Hardware]]<br>
 +
==== Functional Description ====
 +
The master module has the wireless address 100. When the device is powered on, all the modules are initialized. The operational flow of the console can be broadly divided into two phases
 +
*'''Player enrollment:''' “enroll” command is broadcasted to addresses 101 to 120. All the SJone boards that are configured as a remote have the option to enroll in a new game by responding to this message in the next 5 seconds. If at least a single remote (player) is enrolled the console will move to the next phase. Addresses of the enrolled remotes are recorded and maintained by the console for subsequent communications. If no one is enrolled the process is repeated.
 +
*'''Game Running phase:''' The master resets all the enrolled players to IDLE state by sending a “stop” command. Then randomly selects the first player. That player will be sent a “go” command to initiate dice roll. When the master receives a “pushed” info from that player, it will generate a random dice roll between 1-6 and will increment the game board position of that player. The rolled dice count is sent to the player as well. The process is repeated with the next player in the line and continues till one of the player reaches a game board position of 100. The player reached 100th position first is announced and board resets to the Player enrollment section.
 +
 
 +
==== Software Design ====
 +
[[File: CMPE244_S17_SnL_Space_Time_diagram.jpg|centre|8700px|thumb|space Time diagram]] <br>
 +
There is only one task in the master software. It initiates the Game Matrix, UART connected audio Device and TFT display. The game matrix is an array of Structure of size 100 as below:
 +
 
 +
        typedef struct
 +
        {
 +
        int Number;
 +
        int nextLocation;
 +
        int X;
 +
        int Y;
 +
        }Cell;
 +
        Cell Game[100]={0};
 +
 
 +
This array maintains the x, y coordinates of the snake and ladder on the board which is accessed by the game algorithm to manipulate how each player advances on the board.
 +
Once the Initialization procedure is complete the task will go through the below states as described in the previous section:
 +
        typedef enum
 +
        {
 +
        enRoll,
 +
        gameRunning,
 +
        gameOver
 +
        }State_t;
 +
 
 +
Below is the Master_task class handling the operations.
 +
        class Master_Task : public scheduler_task
 +
        {
 +
            public:
 +
              Master_Task(uint8_t priority) : scheduler_task("Master", 2048, priority);
 +
                bool init(void);
 +
                void makeGame();
 +
                void display_image();
 +
                void audioAlert(const char* message);
 +
                void showTextMessage(const char* message);
 +
                void pingAll();
 +
                bool getEnrollment();
 +
                bool getNextLocation(uint8_t diceRollOut,uint8_t playerId);
 +
                void drawCircle();
 +
                void sendDataToPlayers(str message,uint8_t addr);
 +
                bool buttonPressed(uint8_t address);
 +
                int rollDice();
 +
                bool run(void *p);
 +
       
 +
            private:
 +
                State_t current_State;
 +
                uint8_t playerCount;
 +
                player_list players[100];
 +
                uint8_t winnerPlayerId;
 +
        };
 +
 
 +
In Run function we used State Machine model to make transition in Game logic  by declaring States which can be seen in the Master Software Flow below
 +
<br><br>
 +
<b>Flow Chart</b>
 +
[[File: CMPE244_S17_SnL_Master_Flow.jpg|centre|1000px|thumb|Master Software Flow]] <br><br>
 +
 
 +
=== Wireless SJOne remote ===
 +
 
 +
==== Functional Description ====
 +
 
 +
[[File:CMPE244_S17_SnL_Remote_Module.jpeg|200px|thumb|SJone wireless remote]]
 +
 
 +
The wireless remote of the Snake and Ladder project is a slave device which always listens to commands send by the master node (console with fixed address of 100). It has one push
 +
button to control its operation and one LED to indicate the button presses. Any SJ one board with nordic wireless enabled with a unique address and the remote code flashed on it
 +
can join the game. All communication between master and remote are acknowledged.
 +
 
 +
*Operation of the remote can be abstracted to the below states:
 +
**'''IDLE:''' When powered up, the resilient state of the remote is listening to instructions from a hard coded address 100. The pushbutton is inactive and just glows the LED when pressed. It is controlled via a semaphore given from the wireless command interpreter. The 7segment displays “0”.
 +
**'''ENROLL:''' When an ‘enroll’ command broadcasted by the master console is received, the remote activates the pushbutton, giving the player the option to enroll in the game. If pushed, it will send a “enrollMe” information to the master. Note, that the remote does not keep track of the game start window and its upto the user to push the button to enrol in the game. If the user does not push the button, it will continue to stay in this same condition.
 +
**'''STOP:''' The master sends the STOP command to indicate the end of a sequence of operation and to reset the remote to IDLE state. For example, after remotes are enrolled, the enrolment process is finished and remotes can go back to idle state till further instructions are given.
 +
**'''PUSHED:''' The remote sends “pushed” information to the master when the button was activated by the master with a previous command (ie. a semaphore was given to the button task) and the user of the remote pressed the button. Note, its upto the master to interpret the meaning of this push in the context of previous command send.
 +
**'''GO:''' The master sends ‘go’ command to a remote when it is that remotes turn to play. The command interpreter task would release a semaphore to the button task. As in the ENROLL state, its upto the user to press the button, if not pressed it will continue in the state. The 7segment will display “60” in this state.
 +
**'''DICE:''' This is when a player pressed the button on his turn and received a dice roll count from the master. The value received is displayed on the 7segment. Note that to stay fair and impartial, the dice rolling is done at the console and not at the remote.
 +
 
 +
==== Software Design ====
 +
 
 +
'''FreeRTOS tasks handling the above operations:'''
 +
 
 +
The remote software has 3 tasks as below. The wireless command interpreter and game remote tasks communicate via FreeRTOS queues and the pushbutton task releases a semaphore to the game remote task based on the state of the remote.
 +
 
 +
*'''Wireless command interpreter:''' This task handles the wireless communication, interprets the commands received from master and passes stripped down messages to game remote task. This task is vaguely synonymous to a data link layer in OSI model.
 +
*'''Game remote task:''' Handles all the remote states based on the queue messages received from wireless command interpreter task. It also waits for a semaphore from push button task if the remote state is either ENROLL or GO. This task is synonymous the application layer in OSI model.
 +
*'''Push button task:''' This is a free running task that monitor button presses and drives LED. If the remote is in either ENROLL or GO state, it releases a semaphore to the game remote task when a button is pressed.
 +
 
 +
Remote status commands are implemented as below code snippet
 +
        typedef enum{
 +
        // Remote status commands
 +
                pushedBton,
 +
                enrollMe,
 +
                understood,
 +
        // Master commands
 +
                enroll,
 +
                go,
 +
                diceroll,
 +
                stop,
 +
        }gConsol_command_t;
 +
 
 +
Below is the structure for message transferred over nordic wireless
 +
        // Message type struct
 +
        typedef struct {
 +
                gConsol_command_t command;
 +
                uint8_t diceCount;
 +
        } gConsole_message_t;
 +
 
 +
 
 +
 
 +
'''Flowchart'''<br>
 +
[[File: CMPE244_S17_SnL_Remote_Module_SW.jpg|600px|centre|thumb|Remote Module Software flow]]<br>
  
 
== Testing & Technical Challenges ==
 
== 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?
+
This project was a challenging one due to the varied components involved: from choosing the correct TFT, designing the base board image, synchronizing devices over nordic wireless. There were a lot of difficult areas in this project. The most significant being the entire housing for all the components into a proper product package.
Make a smooth transition to testing section and described what it took to test your project.
+
 
 +
=== PCB ===
 +
*Below is a list of challenges we faced during PCB designing:
 +
**For designing the PCB, we use EAGLE software. Which is new for us and that was a challenging task to draw layout.
 +
**We faced Assembly issues like dry solder on pins. So, we re-soldered the component pins.
 +
**There was an insufficient bypassing on PCB hence we added required value of bypass capacitor on board.
 +
**While testing PCB, we find a problem of shorting of a track so we use a multi meter to perform a continuity test and verification on the pins and fixed that.
 +
 
 +
=== LCD display ===
 +
*The LCD we used have 2 layers of display. We ported code from adafruit library, which only supports 1 layer display. During development, we figured out, rendering board image on each dice movement will be too time-consuming. In order to fix that we added support for 2 layer display, which was not present in the default library. The downside of 2 layer display is that it only support 8-bit image instead of 24-bit image.
 +
*Performed lot of mathematical computation to calculate marker coordinate for each box.
 +
*Board image rendering logic was optimized, so that it takes less time. By doing so, the image which took 3 minutes approx. now takes 30 seconds only.
 +
*We also tried to draw our own board from scratch at runtime, so that rendering speed can be further optimized. But even after doing a lot of mathematical computation, with given set of API's we were not able to draw a snake-like image, so we reverted back to old logic.
  
Include sub-sections that list out a problem and solution, such as:
+
=== Text to Speech Module ===
 +
*Text to speech module was relatively simple to interface.
 +
*We started with demonstration message playback. Based on this, we picked a voice, suitable for our project.
 +
*Once this module receives some audio message from the master for playback, it will work independently, till the whole message is not played. So in order to synchronize both modules, we had to add delay at master side.
  
=== My Issue #1 ===
+
=== Wireless Communication ===
Discuss the issue and resolution.
+
*We Defined a wireless communication protocol utilizing the existing API framework
 +
*We faced an issue in synchronizing the wireless communication between master and slave, aligning each one’s receive timeout windows.
 +
*This was resolved later by giving a fixed window of 8 seconds to the master side for all the remote devices to respond.
  
 
== Conclusion ==
 
== 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?
+
 
 +
We successfully completed our project of interactive snake and ladder by writing various modules and our mentioned overall objectives of it. We learned a lot about Sjone board and LPC1758 micro controller. we have added extra function in project so that multiple players (more than 2) can play the game simultaneously by just connecting antenna and flashing the code on SJone board. In conclusion, it can be said that the project was a success and it has been successful in making us understand Embedded Software better.  
  
 
=== Project Video ===
 
=== Project Video ===
Upload a video of your project and post the link here.
+
*[https://youtu.be/S-3Jy_XpI2g  Project Before Packaging]
 +
*[https://www.youtube.com/watch?v=Focj5K7QKf0&feature=youtu.be Final Demonstration]
  
 
=== Project Source Code ===
 
=== Project Source Code ===
*  [https://sourceforge.net/projects/sjsu/files/CmpE_S2016/ Sourceforge Source Code Link]
+
*  [https://github.com/singhabhishek/Snake_and_Ladder  Github Source Code Link]
 +
 
 +
=== Project Presentation ===
 +
*[[File:CMPE244_S17_SnL_Project_Presentation.pptx|thumb|Presentation]]<br>
  
== References ==
 
 
=== Acknowledgement ===
 
=== Acknowledgement ===
Any acknowledgement that you may wish to provide can be included here.
+
We would like to Thank Preetpal Kang. We used his API's of free RTOS which help us a lot to write a code for each module. The knowledge he has given us about all the interfacing buses like SPI, UART helped us in using that in our project and will help in near future.
  
 
=== References Used ===
 
=== References Used ===
List any references used in project.
+
*[https://cdn-shop.adafruit.com/datasheets/RA8875_DS_V19_Eng.pdf RA8875 driver datasheet]
 +
*[https://cdn-shop.adafruit.com/datasheets/ra8875+app+note.pdf RA8875 driver APP note]
 +
*[http://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01 Nordic Wireless]]
 +
*[https://www.youtube.com/watch?v=9iXo3P6JX0s Wireless Mesh Network API]
 +
*[http://www.socialledge.com/sjsu/index.php?title=S15:_Wireless_Mesh_Network Wireless Mesh Network project]
  
 
=== Appendix ===
 
=== Appendix ===
You can list the references you used.
+
*[https://learn.sparkfun.com/tutorials/using-eagle-schematic Eagle PCB Tutorial]

Latest revision as of 09:07, 26 May 2017

Project Title

Snake and Ladder

Complete Product

Abstract

This project aims to bring the fun and simplicity of the classic board game snake and ladder to the digital world. The game console is implemented using a TFT LCD connected SJone board interacting with players holding wireless remotes implemented on SJone boards. The TFT display on the SJone board will show the game grid. A player can enroll in the game and roll dice using the remote SJone board. The device also supports dynamic multiplayer feature that will allow more than one players to play the game with wireless SJOne remotes simultaneously. Any SJone with nordic wireless can be programmed to function as a remote without any additional expensive hardware. All major game events are announced with audio prompts as well. This project explores a new dimension in the traditional snake game to make it more interesting and challenging.

Objectives & Introduction

This game aims to change the way people think of traditional snake game. It will offer the experience of multiplayer games to the player retaining the simplicity of traditional snake game. The major objectives of this project are:

  • To create a snake and ladder game that will have all the functionality of traditional snake and ladder games.
  • Introduce multiplayer functionality in the game that will allow several players to play a game simultaneously. It should be able to give the experience of a real-time multiplayer game to the players.
  • To introduce audio announcement of events.

Roles & Responsibilities

Schedule

Week Start Date End Date Task Status Actual Completion Date
1 3/21 3/25
  • Requirement analysis
  • Component identification and purchase.
  • Task allocation based on different modules in project
Complete 3/25
2 3/25 3/29
  • Design Hardware schematic
Complete 3/29
3 3/29 4/9
  • PCB design and placing order for fabrication
Complete 4/10
4 3/29 4/8
  • Interface LCD with the SJOne board
  • Project report update on wiki
Complete 4/8
5 3/30 4/14
  • Establish wireless connection between boards using nordic wireless
  • Text to speech interface
  • Project report update on wiki
Complete 4/14
6 4/11 4/20
  • Algorithm design and implementation
  • Identify common data elements
Complete 4/20
7 4/20 4/22
  • Integration of modules and hardware package buildup
Complete 4/22
8 4/23 4/31
  • Integration testing and bug fix
  • Project report update on wiki
Complete 4/31
9 4/26 5/5
  • Extra feature identification and implementation
  • Project report update on wiki
Complete 5/6
10 5/5 5/21
  • Testing and Debugging
  • Project report update on wiki and final presentation
Complete 5/21
11 5/21 5/25
  • Wiki Report completion and Final Demonstration
Complete 5/25

Parts List & Cost

Qty Description Manufacturer Part Number Total Cost
1 RA8875 Driver Board Adafruit PRODUCT ID: 1590 $34.95
1 LCD Display Adafruit PRODUCT ID: 2353 $47.50
1 Emic 2 Text to speech module Parallax.inc PRODUCT ID: 30016 $60.00
1 PCB PCBWay Custom made $10
1 Bergstrip male/female Amazon.com N/A $0.5
1 5V voltage regulator On-semiconductor LM-7805 $0.43
1 LED Kingbright N/A $0.19
1 Resistor 100ohm Excess Solution N/A 0.1$
Total Cost (excluding shipping and taxes) $153.67

Design & Implementation

Overall System

  • The overall system is divided into 3 functional parts:
    • Game board (TFT LCD) console and display: The snake and ladder board grid is displayed on the 7 inches LCD screen.
    • Wireless SJone remote: The antenna connected SJone board functioning as the remote which receives commands from master and sends button press information back. The basic use of the SJone remote board is to enroll in a new game and throw dice.
    • Audio prompts: Based on the actions performed the audio file gets executed. To make a game more effective and attractive.

All these functionalities work in parallel and have the same priorities.


System Block Diagram

Project Flow

Printed Circuit Board

To reduce the number of hanging wires used for connecting SJ one board to other modules, we have decided to design a PCB. This facilitated us to accommodate both the modules(Text to speech and LCD) on a single PCB with a single cable between PCB and SJ one board.This way we were able to accommodate all the modules using the single PCB.

Schematic and PCB Layout

Below is the schematic diagram created during PCB design. It includes the power supply, interfaces for LCD controller and text to speech module. The PCB layout developed using Eagle PCB and Altium designer. SJ one board, RA8875 controller and the Evic 2 module work on 5V power supply. RA8875 TFT controller communicates with SJ one over SPI bus while the Evic 2 module communicates on the UART of SJ one board.

Schematic Design

PCB Layout

Final PCB



TFT display and RA8875 Driver Board

TFT Display
This 7.0" TFT screen has resolution of 800x480 pixels and a LED backlight.The display is supposed to be constantly refreshed, at 60Hz, with a pixel clock, V-sync, H-sync, etc.This display is operated by RA8875 Driver board.A 40-pin connector has 8 red, 8 green, and 8 blue parallel pins, for 24 bit color capability.


TFT LCD display and RA8875 driver

RA8875 Driver Board

RA8875 is a text/graphic mixed TFT display controller with 2 layer support which is a powerful yet cheap choice for the color display application. It is designed to meet the requirement of middle size TFT module up to 800x480 pixels with characters or 2D graphic application. Embedded 768KB display RAM provides the user a flexible solution for display buffer of most applications. RA8875 supports a 2D Block Transfer Engine(BTE) that is compatible with 2D BitBLT function for processing mass data transfer.

Features:

  • Support Text/Graphic Mixed Display Mode.
  • Embedded 768KB DDRAM.
  • Color Depth TFT: 256/65K Colors.
  • Supporting TFT 8/16 bpp Generic RGB Interface.
  • Powerful Block Scrolling Function for Vertical or Horizontal Direction.

Hardware Design
The RA8875 driver is interfaced with SJ one board using SPI bus. Below is the interface diagram.

TFT display Inteface


Text to Speech Module

In Emic 2 Text-to-Speech(TTS) module we use UART protocol for communication with microcontroller. In this project, UART3 of the Sjone board is used for interface. This module has own commands for the text to speech conversion, voice selection, volume change.

  • The pin configuration for Emic 2 TTS module is:
    • SOUT – UART (RxD3)
    • SIN – UART (TxD3)
    • 5V – 3.3V (on board)
    • GND - GND
  • It's key features of Emic2 text-to-speech are as follows:
    • High-quality speech synthesis for English and Spanish languages.
    • Nine pre-defined voice styles comprising male, female, and child.
    • Dynamic control of speech and voice characteristics, including pitch, speaking rate, and word emphasis.
    • Industry-standard DEC talk text-to-speech synthesizer engine (5.0.E1).
    • on board 3.5mm audio jack
Text to speech
Text to speech pinout
Text to speech pin connection



Text to speech commands

Nordic wireless

SJone board is equipped with a Nordic wireless chip nRF24L01+ manufactured by the Nordic Semiconductors which can be configured and used through SPI interface. The air data rate, operating modes, and RF channel frequency need to be set by configuring the registers in the nRF24L01+. The nRF24L01 is a highly integrated, ultra low power (ULP) 2Mbps RF transceiver IC for the 2.4GHz ISM (Industrial, Scientific, and Medical) band. With peak RX/TX currents lower than 14mA, a sub μA power down mode, advanced power management, and a 1.9 to 3.6V supply range. The nRF24L01 integrates a complete 2.4GHz RF transceiver, RF synthesizer, and baseband logic including the Enhanced ShockBurst™ hardware protocol accelerator supporting a high-speed SPI interface for the application controller. No external loop filter, resonators, or VCO varactor diodes are required, only a low-cost ±60ppm crystal, matching circuitry, and antenna.

Master SJone console


Integrated Hardware

Functional Description

The master module has the wireless address 100. When the device is powered on, all the modules are initialized. The operational flow of the console can be broadly divided into two phases

  • Player enrollment: “enroll” command is broadcasted to addresses 101 to 120. All the SJone boards that are configured as a remote have the option to enroll in a new game by responding to this message in the next 5 seconds. If at least a single remote (player) is enrolled the console will move to the next phase. Addresses of the enrolled remotes are recorded and maintained by the console for subsequent communications. If no one is enrolled the process is repeated.
  • Game Running phase: The master resets all the enrolled players to IDLE state by sending a “stop” command. Then randomly selects the first player. That player will be sent a “go” command to initiate dice roll. When the master receives a “pushed” info from that player, it will generate a random dice roll between 1-6 and will increment the game board position of that player. The rolled dice count is sent to the player as well. The process is repeated with the next player in the line and continues till one of the player reaches a game board position of 100. The player reached 100th position first is announced and board resets to the Player enrollment section.

Software Design

space Time diagram

There is only one task in the master software. It initiates the Game Matrix, UART connected audio Device and TFT display. The game matrix is an array of Structure of size 100 as below:

       typedef struct
       {
       	int Number;
       	int nextLocation;
       	int X;
       	int Y;
       }Cell;
       Cell Game[100]={0};

This array maintains the x, y coordinates of the snake and ladder on the board which is accessed by the game algorithm to manipulate how each player advances on the board. Once the Initialization procedure is complete the task will go through the below states as described in the previous section:

       typedef enum
       {
       	enRoll,
       	gameRunning,
       	gameOver
       }State_t;

Below is the Master_task class handling the operations.

       class Master_Task : public scheduler_task
       {
           public:
              Master_Task(uint8_t priority) : scheduler_task("Master", 2048, priority);
               bool init(void);
               void makeGame();
               void display_image();
               void audioAlert(const char* message);
               void showTextMessage(const char* message);
               void pingAll();
               bool getEnrollment();
               bool getNextLocation(uint8_t diceRollOut,uint8_t playerId);
               void drawCircle();
               void sendDataToPlayers(str message,uint8_t addr);
               bool buttonPressed(uint8_t address);
               int rollDice();
               bool run(void *p);
       
           private:
               State_t current_State;
               uint8_t playerCount;
               player_list players[100];
               uint8_t winnerPlayerId;
       };

In Run function we used State Machine model to make transition in Game logic by declaring States which can be seen in the Master Software Flow below

Flow Chart

Master Software Flow


Wireless SJOne remote

Functional Description

SJone wireless remote

The wireless remote of the Snake and Ladder project is a slave device which always listens to commands send by the master node (console with fixed address of 100). It has one push button to control its operation and one LED to indicate the button presses. Any SJ one board with nordic wireless enabled with a unique address and the remote code flashed on it can join the game. All communication between master and remote are acknowledged.

  • Operation of the remote can be abstracted to the below states:
    • IDLE: When powered up, the resilient state of the remote is listening to instructions from a hard coded address 100. The pushbutton is inactive and just glows the LED when pressed. It is controlled via a semaphore given from the wireless command interpreter. The 7segment displays “0”.
    • ENROLL: When an ‘enroll’ command broadcasted by the master console is received, the remote activates the pushbutton, giving the player the option to enroll in the game. If pushed, it will send a “enrollMe” information to the master. Note, that the remote does not keep track of the game start window and its upto the user to push the button to enrol in the game. If the user does not push the button, it will continue to stay in this same condition.
    • STOP: The master sends the STOP command to indicate the end of a sequence of operation and to reset the remote to IDLE state. For example, after remotes are enrolled, the enrolment process is finished and remotes can go back to idle state till further instructions are given.
    • PUSHED: The remote sends “pushed” information to the master when the button was activated by the master with a previous command (ie. a semaphore was given to the button task) and the user of the remote pressed the button. Note, its upto the master to interpret the meaning of this push in the context of previous command send.
    • GO: The master sends ‘go’ command to a remote when it is that remotes turn to play. The command interpreter task would release a semaphore to the button task. As in the ENROLL state, its upto the user to press the button, if not pressed it will continue in the state. The 7segment will display “60” in this state.
    • DICE: This is when a player pressed the button on his turn and received a dice roll count from the master. The value received is displayed on the 7segment. Note that to stay fair and impartial, the dice rolling is done at the console and not at the remote.

Software Design

FreeRTOS tasks handling the above operations:

The remote software has 3 tasks as below. The wireless command interpreter and game remote tasks communicate via FreeRTOS queues and the pushbutton task releases a semaphore to the game remote task based on the state of the remote.

  • Wireless command interpreter: This task handles the wireless communication, interprets the commands received from master and passes stripped down messages to game remote task. This task is vaguely synonymous to a data link layer in OSI model.
  • Game remote task: Handles all the remote states based on the queue messages received from wireless command interpreter task. It also waits for a semaphore from push button task if the remote state is either ENROLL or GO. This task is synonymous the application layer in OSI model.
  • Push button task: This is a free running task that monitor button presses and drives LED. If the remote is in either ENROLL or GO state, it releases a semaphore to the game remote task when a button is pressed.

Remote status commands are implemented as below code snippet

       typedef enum{
       // Remote status commands
               pushedBton,
               enrollMe,
               understood,
       // Master commands
               enroll,
               go,
               diceroll,
               stop,
       }gConsol_command_t;

Below is the structure for message transferred over nordic wireless

       // Message type struct
       typedef struct {
               gConsol_command_t command;
               uint8_t diceCount;
       } gConsole_message_t;


Flowchart

Remote Module Software flow

Testing & Technical Challenges

This project was a challenging one due to the varied components involved: from choosing the correct TFT, designing the base board image, synchronizing devices over nordic wireless. There were a lot of difficult areas in this project. The most significant being the entire housing for all the components into a proper product package.

PCB

  • Below is a list of challenges we faced during PCB designing:
    • For designing the PCB, we use EAGLE software. Which is new for us and that was a challenging task to draw layout.
    • We faced Assembly issues like dry solder on pins. So, we re-soldered the component pins.
    • There was an insufficient bypassing on PCB hence we added required value of bypass capacitor on board.
    • While testing PCB, we find a problem of shorting of a track so we use a multi meter to perform a continuity test and verification on the pins and fixed that.

LCD display

  • The LCD we used have 2 layers of display. We ported code from adafruit library, which only supports 1 layer display. During development, we figured out, rendering board image on each dice movement will be too time-consuming. In order to fix that we added support for 2 layer display, which was not present in the default library. The downside of 2 layer display is that it only support 8-bit image instead of 24-bit image.
  • Performed lot of mathematical computation to calculate marker coordinate for each box.
  • Board image rendering logic was optimized, so that it takes less time. By doing so, the image which took 3 minutes approx. now takes 30 seconds only.
  • We also tried to draw our own board from scratch at runtime, so that rendering speed can be further optimized. But even after doing a lot of mathematical computation, with given set of API's we were not able to draw a snake-like image, so we reverted back to old logic.

Text to Speech Module

  • Text to speech module was relatively simple to interface.
  • We started with demonstration message playback. Based on this, we picked a voice, suitable for our project.
  • Once this module receives some audio message from the master for playback, it will work independently, till the whole message is not played. So in order to synchronize both modules, we had to add delay at master side.

Wireless Communication

  • We Defined a wireless communication protocol utilizing the existing API framework
  • We faced an issue in synchronizing the wireless communication between master and slave, aligning each one’s receive timeout windows.
  • This was resolved later by giving a fixed window of 8 seconds to the master side for all the remote devices to respond.

Conclusion

We successfully completed our project of interactive snake and ladder by writing various modules and our mentioned overall objectives of it. We learned a lot about Sjone board and LPC1758 micro controller. we have added extra function in project so that multiple players (more than 2) can play the game simultaneously by just connecting antenna and flashing the code on SJone board. In conclusion, it can be said that the project was a success and it has been successful in making us understand Embedded Software better.

Project Video

Project Source Code

Project Presentation

Acknowledgement

We would like to Thank Preetpal Kang. We used his API's of free RTOS which help us a lot to write a code for each module. The knowledge he has given us about all the interfacing buses like SPI, UART helped us in using that in our project and will help in near future.

References Used

Appendix