S17: Interactive Snake and ladder

From Embedded Systems Learning Academy
Jump to: navigation, search

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