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

From Embedded Systems Learning Academy
Jump to: navigation, search
(Overall System Flow Chart)
(Project Title)
 
(216 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Project Title ==
 
== Project Title ==
'''Snake and Ladder
+
<b>Snake and Ladder</b>
 +
 
 +
[[File:CMPE244_S17_SnL_Product.JPG|850px|centre|thumb|Complete Product]] <br>
  
 
== Abstract ==
 
== Abstract ==
This project aims to bring the fun and simplicity of snake and ladder game with some new features. It is a snake and ladder game using SJONE board, LCD and 2 wireless remotes. LCD display is connected to the SJONE board will display the game grid. It will also have the multiplayer feature that will allow more than one players to play the game using wireless remotes simultaneously. This project explores a new dimension in the traditional snake game to make it more interesting and challenging.
+
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 ==
  
This game aims to change the way people think of traditional snake game. It will offer the experience of commercial multilayer games to the player retaining the simplicity of traditional snake 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.
*The major objectives of this project are:
+
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.
+
* 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.
+
* 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 Speech output for events.
+
*To introduce audio announcement of events.
 
 
  
 
===Roles & Responsibilities===
 
===Roles & Responsibilities===
Line 115: Line 116:
 
* Project report update on wiki
 
* Project report update on wiki
 
| Complete
 
| Complete
|5/5
+
|5/6
 
|-
 
|-
 
! scope="row"| 10
 
! scope="row"| 10
 
| 5/5
 
| 5/5
| 5/14
+
| 5/21
 
|  
 
|  
 
* Testing and Debugging
 
* Testing and Debugging
 
* Project report update on wiki and final presentation  
 
* Project report update on wiki and final presentation  
| In Progress
+
| Complete
|
+
|5/21
 
|-
 
|-
 
! scope="row"| 11
 
! scope="row"| 11
| 5/15
+
| 5/21
| 5/23
+
| 5/25
 
|  
 
|  
 
* Wiki Report completion and Final Demonstration  
 
* Wiki Report completion and Final Demonstration  
| Plan
+
| 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 ==
 
=== Overall System ===
 
=== Overall System ===
*The overall system is divided into 3 parts:  
+
*The overall system is divided into 3 functional parts:  
**game image display(LCD): the snake and ladder image grid is mounted on the 7 inches LCD screen.   
+
**'''Game board (TFT LCD) console and display:''' The snake and ladder board grid is displayed on the 7 inches LCD screen.   
**wireless SJONE board: the antenna is connected to SJONE board to transmit and receive signal from master. The basic use of the SJONE board with antenna is to through dice.  
+
**'''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.  
**text to speech module: based on the actions performed the audio file gets executed. To make a game more effective and attractive.
+
**'''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>
  
All these functionalities work in parallel and have the same priorities.
+
[[File:CMPE244_S17_SnL_Project_flow.gif|900px|centre|thumb|Project Flow]] <br>
  
==== Overall System Flow Chart ====
+
=== Printed Circuit Board ===
[[File:snake and ladder-remote.png|300px|thumb|Remote side system flow]]
 
[[File:snake and ladder-master 1.png|left|300px|thumb|master side system flow]]
 
[[File:snake and ladder-master 2.png|center|410px|thumb|master side system flow]]
 
[[File:snake and ladder-master 3.png|right|300px|thumb|master side system flow]]
 
  
=== Hardware Design ===
+
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.  
=== Printed Circuit Board ===
 
=====Schematic Diagram=====
 
Below is the schematic diagram for the project. It includes the power supply, interface for LCD controller and text to speech module.
 
[[File:CMPE244_S17_SnL_Schematic_Daigram.JPG]]
 
  
=====PCB Layout=====
+
=====Schematic and PCB Layout=====
Below is the PCB layout developed using Eagle PCB and Altium designer.
+
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>
  
[[File:CMPE244_S17_SnL_PCB_Layout.JPG |400x500px]]
+
=== TFT display and RA8875 Driver Board ===
  
=== LCD display and RA8875 Driver Board ===
+
'''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>
  
==== Hardware Interface ====
+
'''RA8875 Driver Board'''
[[File:LCD Screen.jpg|left|250px|thumb|LCD Display]]
 
[[File:RA8875 driver Pinout.png|350px|thumb|RA8875 driver Pinout ]]
 
[[File:LCD, RA8875 and SJone connection.png|center|600px|thumb|LCD, RA8875 and SJone connection]]
 
  
 +
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.
  
'''LCD Display'''
+
<b>Features:</b>
*This 7.0" TFT screen has 800x480 pixels, and an LED backlight.
+
*Support Text/Graphic Mixed Display Mode.
*The display is supposed to be constantly refreshed, at 60Hz, with a pixel clock, V sync, H sync, etc.
+
*Embedded 768KB DDRAM.
*This display is operated by RA8875 Driver board.
+
*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>
  
'''RA8875 Driver Board'''
+
=== 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>
  
RA8875 is a text/graphic mixed display with 2 layers TFT LCD controller which is a powerful and cheap choice for 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 user a flexible solution for display buffer of almost application. RA8875 supports a 2D Block Transfer Engine(BTE) that is compatible with 2D BitBLT function for processing the mass data transfer.
+
=== 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.
  
*Features:
+
=== Master SJone console ===
**Support Text/Graphic Mixed Display Mode.
+
<br>
**Embedded 768KB DDRAM.
+
[[File:CMPE244_S17_SnL_Master_Module.jpeg|centre|500px|thumb|Integrated Hardware]]<br>
**Color Depth TFT: 256/65K Colors.
+
==== Functional Description ====
**Supporting TFT 8/16 bpp Generic RGB Interface.
+
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
**Powerful Block Scrolling Function for Vertical or Horizontal Direction.
+
*'''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 ====
 
==== 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};
  
'''Flowchart'''
+
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;
  
'''Code snippet'''
+
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;
 +
        };
  
=== Wireless SJONE remote ===
+
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>
  
==== Hardware Interface ====
+
=== Wireless SJOne remote ===
  
[[File:SJone wireless remote.png|200px|thumb|SJone wireless remote]]
+
==== Functional Description ====
  
Here, in this project we have connected antenna to SJONE board for wireless functionality. Initially all the devices are in OFF state. Hence seven segment display of on the board will show “0” as master sends a command to any of the board, the seven-segment display will show “G0” then we can start to play the game.
+
[[File:CMPE244_S17_SnL_Remote_Module.jpeg|200px|thumb|SJone wireless remote]]
  
This wireless remote functionality is introduced in our project is to roll a dice. Hence for this we have assigned an on-board switch. As soon a switch gets pressed a dice get  rolled and random number gets displayed on the display. As Per that the player will move that many positions further.
+
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.  
  
Here, we have added a “enroll” function. In this, master will broadcast a packet to every user who wants to enter in game. Then user will press a switch and acknowledge master.  
+
*Operation of the remote can be abstracted to the below states:
Hence master will get to know the address of the user and now every user who gets enroll can play the game.
+
**'''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 ====
 
==== Software Design ====
  
'''Flowchart'''
+
'''FreeRTOS tasks handling the above operations:'''
  
'''Code snippet'''
+
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.
  
=== Text to Speech Module ===
+
*'''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.
  
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.
+
Remote status commands are implemented as below code snippet
*The pin configuration for Emic 2 TTS module is:
+
        typedef enum{
**SOUT – UART (RxD3)
+
        // Remote status commands
**SIN – UART (TxD3)
+
                pushedBton,
**5V – 3.3V (on board)
+
                enrollMe,
**GND - GND
+
                understood,
 
+
        // Master commands
*Its key features of Emic2 text-to-speech are as follows:
+
                enroll,
**High-quality speech synthesis for English and Spanish languages.
+
                go,
**Nine pre-defined voice styles comprising male, female, and child.
+
                diceroll,
**Dynamic control of speech and voice characteristics, including pitch, speaking rate, and word emphasis.
+
                stop,
**Industry-standard DEC talk text-to-speech synthesizer engine (5.0.E1).
+
        }gConsol_command_t;
**on board 3.5mm audio jack
 
==== Hardware Interface ====
 
[[File:text to speech.png|left|250px|thumb|Text to speech]]
 
[[File:text to speech pinout.png|250px|thumb|Text to speech pinout]]
 
[[File:text to speech pin connection.png|center|500px|thumb|Text to speech pin connection]]
 
<br><br><br><br>
 
  
==== Software Design ====
+
Below is the structure for message transferred over nordic wireless
[[File:text to speech commands.png|450px|thumb|Text to speech commands]]
+
        // Message type struct
'''Algorithm:'''
+
        typedef struct {
*Initialize the emic2 TTS module to UART3.
+
                gConsol_command_t command;
*check function call for TTS module.
+
                uint8_t diceCount;
*Select text as per function call and play it on buzzer.
+
        } gConsole_message_t;
  
'''Flowchart'''
 
  
'''Code Snippet'''
 
  
=== Implementation ===
+
'''Flowchart'''<br>
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.
+
[[File: CMPE244_S17_SnL_Remote_Module_SW.jpg|600px|centre|thumb|Remote Module Software flow]]<br>
  
 
== Testing & Technical Challenges ==
 
== 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 ===
 
=== PCB ===
 
 
*Below is a list of challenges we faced during PCB designing:  
 
*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.  
 
**For designing the PCB, we use EAGLE software. Which is new for us and that was a challenging task to draw layout.  
Line 260: Line 359:
  
 
=== LCD display ===
 
=== LCD display ===
*The main challenged faced related to display is to print a snake and ladder picture grid. Also, to determine exact coordinates of snake and ladder on grid is one of the challenges. this a tough job but we manage to do that. Tried to achieved high refresh rate on LCD to get real time display effect.
+
*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 ==
 
== 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 LPC1768 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. Hence this project increased our knowledge of software and hardware.  
+
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 ===
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, I2C helped us in using that in our project and will help in near future.
+
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