F18: Catch me if you can

From Embedded Systems Learning Academy
Revision as of 04:18, 17 December 2018 by Proj user11 (talk | contribs) (Parts List & Cost)

Jump to: navigation, search

Grading Criteria

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

Project Title

Catch Me If You Can

Catch me if you can

Abstract

"Catch me if you can" is a fun game where the user must be attentive and agile enough to catch the randomly dropping eggs from above into a basket with increasing difficulty levels for an intriguing experience. This is all displayed in the LED matrix acting as the screen. The system will consist of two SJ1 boards, one used as a game console with which user will try to catch the eggs by moving it in the required orientation. The other board will control the display module that displays the graphics of eggs falling and also the basket movement. The display module shall communicate with the game console via RF Nordic transceiver. There will be game sounds produced by the display module board for various events during the game like entering a new level.

Objectives & Introduction

Objective

Here, we develop an Embedded system in the form of a 2D game involving a Matrix LED display acting as the Human Machine Interface to guide the player along the way while playing the game. This project aims at integrating micro-controller peripheral drivers and the application software in a meaningful way, where the accelerometer data is sent out from a node via wireless Nordic transceiver to control slider movement on the other node to control the game according to player's performance.

Introduction

The Project consists of three main modules:

Control Module: It consists of accelerometer on SJ one board. Calibrated board orientation is sent to the Display Module via Wireless Module.

Display Module: It is responsible for controlling 32*32 LED Matrix and Piezo buzzer interfaced to SJ One Board.

Wireless Module: It is used to establish communication between Display and Control module.

About the game

  • Player should collect the eggs into the basket which are shot from the canon.
  • Press switch on the console (SJOne board) to start the game.
  • Tilt the console left or right to move the basket.
  • Collect the eggs.
  • Avoid red objects, if caught Game Over, else continue to collect eggs till the end of level.

Team Members & Responsibilities

  • Aquib Abduljabbar Mulani
    • Wireless chip TX driver/application and calibrating accelerometer.
  • Kailash Kumar Chakravarty
    • RGB LED 32x32 matrix driver and game application code.
  • Nandini Mandya Shankaraiah
    • Audio output and Wireless chip RX driver/application.
  • Rishabh Sheth
    • PCB design.
  • Swanand Sapre
    • Console and Game design and application code.

Schedule

Week# Date Task Status Actual Completion Date
1 10/16/2018
  • Product Requirement Analysis & Order Required Parts.
  • Software Design and ownership of each module
Completed 10/25/2018
2 10/30/2018
  • Calibrating Accelerometer values for actual orientation
  • Project report update on the wiki.
Completed 11/05/2018
3 11/06/2018
  • Design schematics for console charging circuit & LED display circuit
  • Finalize parts and components for PCB design and develop footprints library for KiCAD (if not present)
  • Porting Adafruit LED driver into LPC
Completed 11/13/2018
4 11/13/2018
  • Develop algorithm for basket movement and dropping eggs using accelerometer values
  • Basic LED testing by activating individual and group of pixels
  • Develop game specific APIs to draw objects like basket on top of led driver
  • Project report update on the wiki.
Completed 11/16/2018
5 11/20/2018
  • Piezo Buzzer operation with different frequency
  • Order PCB for manufacturing and order missing components
  • Check Nordic Wireless Transmit part by sending accelerometer value
  • Project report update on the wiki.
Completed 11/22/2018
6 11/27/2018
  • Design PCB for Console & Display and generate Gerber files, finalize PCB manufacture
  • Start and Stop switch, which controls the power to the system and displays Welcome and Good Bye screen
  • Generating different tones using PWM on Piezo buzzer
  • Check Nordic wireless receive part
Completed 12/1/2018
7 11/30/2018
  • Integrating calibrated accelerometer, switch functionalities and wireless transfer on console board
  • Once Integrated check the LED display response to the varying inputs from the game console
8 12/04/2018
  • Display the score of the user upon request
  • Final testing product with varying inputs of gaming console|
9 12/11/2018
  • Complete Wiki Report and Final Demo

Parts List & Cost

Sl No Parts Seller Quantity Price
1 SJOne LPC1758 Microcontroller Board Preetpal Kang 2 $160
2 RGB LED Matrix Panel - 32x32 Sparkfun 1 $55.6
3 Piezo Buzzer Amazon 2 $1.5
4 Accelerometer On board 1 NA
5 Switches On board 4 NA
6 Portable Power Supply Local seller 1 $5
7 RF Nordic On board 1 NA
8 BOM / PCB components Moser - $20

Design & Implementation

Hardware Design

Discuss your hardware design here. Show detailed schematics, and the interface here.

PCB Design

PCB is an important part of the embedded system, it is certainly true for this project as it reduced wire complexity and give independent power to our circuit. There are many software available for PCB design among them Eagle and KiCAD are more popular and both software are free for the student. We choose KiCAD (v5.10.0) for PCB design over Eagle because it is opensource so we don't have to worry about the license in case we want to use it after one year or for commercial purpose. The second big reason was all of our team members was new to PCB design so the learning curve was similar for both software and we found a good tutorial series of KiCAD on youtube ( KiCAD tutorials ). KiCAD has its own issues which are discussed issue section of this wiki.


The steps involved in the PCB design process are discussed below:

1. Schematic Design

Our project can be divided into two main circuits, first is game display and second is a wireless console. We decided to design separate PCB for both circuits as doing so can make wiring easy and improve the user experience.

a. Display PCB schematic

PCB Schematic 1 Game Display

b. Console PCB schematic

PCB Schematic 2 Game Console

2. PCB Layout

a. Display PCB layout

Dispay PCB layout without Copper layer
Display PCB layout
Display PCB front 3D view
Display PCB back 3D view


b. Console PCB layout

Console PCB layout without Copper layer
PCB Schematic 1 Game Display
PCB Schematic 1 Game Display
PCB Schematic 1 Game Display

3. PCB manufacturing and soldering

a. Display PCB

b. Console PCB layout

Hardware Interface

Hardware Design Diagram


Hardware design diagram above gives an overview of the entire system which consists of the two SJ-One controllers: one board is used as Control Module and other board is used as the Display Module.

  • The Control Module uses the onboard accelerometer on SJ-One which is interfaced via I2C protocol. The calibrated accelerometer values are then used to determine the basket position on the LED Matrix.
  • The Display Module SJ-One board is used to control a 32*32 RGB LED Matrix.This matrix displays the basket, eggs shot from the cannon.The movement of the basket is as per the orientation value received from the Control Module, through Wireless Module. It also consists of Peizo buzzer which is controlled via PWM pin.

Display Module

RGB LED Matrix:

RGB LED matrix display
RGB Display

The Human Machine Interface is a display which is composed of 6mm pitch 1024 RGB LEDs arranged in a 32x32 matrix. 32 rows of the matrix is divided into 16 interleaved sections. Here the first section is the 1st and 16th 'row' (32 x 2 = 64 RGB LEDs), the second section is 2nd and 17th 'row' and so on. On the PCB is 12 LED driver chips. These are like 74HC595s but they have 16 outputs and they are constant current. 16 outputs * 12 chips = 192 LEDs that can be controlled at once, and 64 * 3 (R G and B) = 192. So now the design comes together. We can have 192 outputs that can control one line at a time, with each of 192 R, G and B LEDs either on or off. The LPC1758 controller selects which section to currently draw (using A, B, C and D address pins - 4 bits can have 16 values). Once the address is set, the controller clocks out 192 bits of data (24 bytes) and latches it. Then it increments the address and clocks out another 192 bits, etc until it gets to address #15, then it sets the address back to #0. To light up an individual pixel, appropriate row value is loaded on to the address pins A,B,C & D, Clock is set out to traverse the row and when required pixel is reached, the latch is set high to turn ON the LED. The hardware interface to the LED Matrix uses GPIO for all data and control lines. A GPIO clock is toggled to shift in data sitting at the Matrix's 6 data ports.

SJ One Board Pin Name Description
P0.0 addrA Address Input A
P0.1 addrB Address Input B
P2.6 addrC Address Input C
P2.7 addrD Address Input D
P1.29 Latch Shift in row data/Active High
P1.28 Output Enable Turn on selected rows/Active Low
P1.19 Clock Shift clock
P1.22 R1 Top half red data
P0.26 G1 Top half green data
P1.23 B1 Top half blue data
P1.30 R2 Bottom half red data
P1.31 G2 Bottom half green data
P2.5 B2 Bottom half blue data

Piezo Buzzer:

Piezo Schematic Diagram
Piezo Physical Diagram

Piezo electric buzzer are high performance buzzer that employ piezoelectric elements and are designed for easy incorporation into various circuits. These buzzers are designed for external excitation, the same part can serve as both a musical tone oscillator and a buzzer. In our project we are using this device to create musical tones by varying the operating frequency.The different range of operating frequency are generated from PWM peripheral. Different range of frequencies are maintained as constants ,these constants are fed to PWM,which generates square wave. The output of the PWM is driving the Piezo buzzer.

Code snippet for creating musical tones by varying frequency:

int fire[]=
{
		550,/*twice the freq of this and use always tempo as 40 */
		404,
		315,
		494,
		182,
		260,
		455,
		387,
		340
};

void fire_sound_level(void){
	 for(int i = 0;i < 8;i++)
		 {
		 	 uint8_t tempo = 40;
		 	 	 while(tempo)
		 	 	 {
					pwm.SetFrequency(fire[i]*2);
					pwm.SetDutyCycle(pwm.k2_1,50);
					pwm.PwmEnableMode(true);
					tempo--;
		 	 	 }
		 }
		 pwm.PwmEnableMode(false);
	}

Control Module

Accelerometer:

Accelerometer Detection
The MMA8452Q which is a smart low-power, three-axis, capacitive micromachined accelerometer with 12 bits of resolution is used. Accelerometers are electromechanical devices that are used to sense acceleration that can be of various forms, for instance gravity.
In our project,we have calibrated the accelerometer based the values of X,Y and Z co-ordinates corresponding to different orientations of the accelerometer to control the horizontal movement of the Basket to catch the eggs on the screen. This has also helped us decide and control the speed of the basket.

Code snippet for Accelerometer Calibration:

if (((x_coordiante > px_coordiante + CONSOLE_SENSITIVITY) && (x_coordiante <= CONSOLE_TILT_RANGE) ))
{
        boardOrientation=left;
        bskObj.speed=BASKET_SPEED;
        px_coordiante=x_coordiante;
}
    //left
    else if((x_coordiante<px_coordiante-CONSOLE_SENSITIVITY && x_coordiante>=-CONSOLE_TILT_RANGE))
{
        boardOrientation=right;
        bskObj.speed=BASKET_SPEED;
        px_coordiante=x_coordiante;
}
else if(x_coordiante>CONSOLE_TILT_RANGE ){
        boardOrientation=left;
        bskObj.speed=BASKET_SPEED;
}
else if(x_coordiante<-CONSOLE_TILT_RANGE ){
        boardOrientation=right;
        bskObj.speed=BASKET_SPEED;
    }
else
{
        boardOrientation=invalid;
        py_coordiante=y_coordiante;
}

Wireless Module:

Nordic Wireless Block Diagram
The nRF24L01+ is a single chip 2.4GHz transceiver with an embedded baseband protocol engine, suitable for ultra low power wireless applications. The nRF24L01+ is designed for operation in the world wide ISM frequency band at 2.400 - 2.4835GHz.The nRF24L01+ supports an air data rate of 250 kbps, 1 Mbps and 2Mbps. The high air data rate combined with two power saving modes make the nRF24L01+ very suitable for ultra low power designs. The register map, which is accessible through the SPI, contains all configuration registers in the nRF24L01+ and is accessible in all operation modes of the chip. The embedded baseband protocol is based on packet communication and supports various modes from manual operation to advanced autonomous protocol operation. Internal FIFOs ensure a smooth data flow between the radio front end and the system’s MCU. Enhanced ShockBurst reduces system cost by handling all the high speed link layer operations.
Code snippet for Wireless Transmitter:
struct pckt
{
    int16_t x;
    int16_t y;
    int16_t z;
    int16_t buttonPressed=0;
};
void WirelessTx(void *p)
{
       while(1)
       {
           pckt var;
           var.x = AS.getX();/values from accelerometer*/
           var.y = AS.getY();
           var.z = AS.getZ();
           pckt var;
             while(1)
             {
                 if(SW.getSwitch(1))
                 {
                     var.buttonPressed=1;
                     vTaskDelay(300);
                 }
                 else if(SW.getSwitch(2))
                 {
                     var.buttonPressed=2;
                     vTaskDelay(300);
                 }
           wireless_send(REM, mesh_pkt_nack,(pckt*)&var, 8, 0);
           vTaskDelay(50);
             }
       }
}

Code snippet for Wireless Receiver:

void wirelessRx(void* p)
{
    while(1)
    {
        mesh_packet_t rcvPkt;
        int timeout_ms = 50;

        if(wireless_get_rx_pkt(&rcvPkt, timeout_ms)){

            iphObj.x_coordiante = (int16_t)(*((uint16_t*)(rcvPkt.data+0)));
            iphObj.y_coordiante = (int16_t)(*((uint16_t*)(rcvPkt.data+2)));
            iphObj.z_coordiante = (int16_t)(*((uint16_t*)(rcvPkt.data+4)));
            iphObj.buttonPressed= (int16_t)(*((uint16_t*)(rcvPkt.data+6)));
            if(iphObj.buttonPressed==1 )
            {
                xSemaphoreGive(playPauseHandler);
            }
            else if(iphObj.buttonPressed==2 )
            {
               xSemaphoreGive(resetGameHandler);
            }
        }
        vTaskDelay(50);
    }
}

Software Design

Tasks within LPC Board 1 (LED display):
Input_handler : This task takes the Accelerometer values as inputs from other LPC board and determines the exact corresponding position of the basket.
Display_handler: This task is responsible for displaying the contents into the LED matrix display at a certain rate. Note: Actual screen refreshing takes place at a much higher rate.
Tasks within LPC Board 2 (Console):
Data_sender : This task continuously sends the raw accelerometer values to LPC board 1.
Game_handler : This task is responsible for handling events like game start, game pause, game end via on board switches.

Implementation

Porting Adafruit driver into LPC :
1. LPC GPIOs were accordingly mapped and made as output for LED matrix connections.
2. Basic shapes, patterns and text were drawn.
3. Game specific APIs were developed for objects like basket, egg, cannon.

Testing & Technical Challenges

Issue #1

Porting Adafruit driver into LPC As we used the existing Adafruit library,we had to map the LPC GPIOs to LED matrix pins.

Issue #2

Piezo Buzzer sound frequency not varying at higher speed. A lot of trials and different frequency combinations were required to make the sound work properly.

Issue #3

In Nordic Wireless, the transmitted data was received only once despite the transmitter transmitting data continuously. This was because vTaskStartScheduler() API was used by us. The scheduler_start() API was required to be used for Nordic Wireless to function properly.

Conclusion

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

Project Video

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

Project Source Code

References

Acknowledgement

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

References Used

List any references used in project. [1] Nordic wireless datasheet

Appendix

You can list the references you used.