Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertisers
    • Advertise
    • PR Submissions
    • Eblast Submissions
  • Subscribe

Simple Raspberry Pi Game Pad for Ball Catching Game – (Part 36/38)

By Ajish Alfred November 8, 2013

The Raspberry pi is a mini computer which is designed in a single board with all the essential components required for running an operating system. The board is provided with a RCA connector which can be used to connect it directly to a TV screen which is based on PAL and NTSC standard. The board also has a HDMI connector output which can be used to connect the board to a HD TV. One can also use remote login to access the Raspberry pi and view the GUI (Text User Interface) on the PC screen. The Raspberry pi board is also very easy to interface with external devices or circuits through its pin outs. This makes the Raspberry pi a suitable platform for playing and developing interesting games.

This article discusses how to develop a simple graphical game using the HTML5 and JavaScript language and to interface it with an external custom made game pad hardware connected to the pins of Raspberry pi board.
[[wysiwyg_imageupload:11064:]]

 


 

There are eight general purpose IO pins on the 13*2 pin connectors of the Raspberrypi board and among them four pins has been selected as input and then remaining four pins as output. The input pins are connected to push button and are pulled down using 1K resistors. The output pins are connected to the LEDs through another set of 1K resistors. For this project the Raspberry pi board is loaded with Ubuntu and is remotely accessed using VNC. To access the pins that coming out of the Broadcom controller the C library “bcm2835” has been downloaded and installed.

This game contains four balls and the movement of which can be controlled with the help of the four keys in the gamepad. The game can be opened in a browser window and played with the help of four buttons connected to the pins of the Raspberry pi board. One has to install the browser “Iceweasel” which is the Debian version of the Firefox. The following commands can install the software on the Raspberry pi;
sudo apt-get update
sudo apt-get install iceweasel
The game runs in a browser window and it communicates with the game pad through a Named Pipe or FIFO. There are multiple processes running which can read from the game pad and write the required commands to the FIFO for controlling the game. The JavaScript written in the game code simply reads from the FIFO for the input control data.
The parent process here creates four child processes which are dedicated for each of the keys in the gamepad. Whenever a key is pressed or released, they will generate a signal and send it to the parent process with a value. This method of sending a signal with value  helps the parent process to identify which key has been pressed or released. 
Block Diagram of Raspberry pi gamepad
Fig. 2: Block Diagram Of Raspberry Pi Gamepad
The NAMED PIPE or FIFO needs to be created using the following command in the same directory where the executable for the gamepad code written in C and the HTML game files written in HTML5 and JavaScript exist.
mkfifo xyz
The FIFO can also be created using the code itself by adding the function mkfifo(), open() as explained in a previous documentation.
As soon as the parent process detects a key press from the value it received along with the signal, it simply writes a particular character corresponding to that key to the NAMED PIPE or FIFO. The HTML game will be reading continuously from the FIFO every 500ms to get the input. Hence both the C code and the HTML file needs to be in the state of execution. The gamepad hardware communicates with the C code only and the C code communicates with the JavaScript using the NAMED PIPE.
The user can write data into the temporary file from the terminal itself using the ‘echo’ command as shown in the following example.
echo abcdef >> /tmp/my_fifo
The FIFO writing parent process is written in such a way that it will write some particular characters to the FIFO in respond to the signals received from the child processes. The commands that will be written to the FIFO for controlling the movement of the balls in the game are listed below;
u -> catch the ball in the first column
r -> catch the ball in the second column
l -> catch the ball in the third column
d -> catch the ball in the fourth column
These commands can be written into the FIFO with the help of the system() function.

 

system ( “echo u >> xyz );

 

 

 

 

 

 

 

system ( “echo r >> xyz );

 

 

 

 

 

 

 

system ( “echo l >> xyz );

 

 

 

 

 

system ( “echo d >> xyz );
Even if there is any key press the Parent process writes a character ‘x’ every 500ms to keep the JavaScript running.

Score of Ball Catching Game on screen using Raspberry pi

Fig. 3: Score Of Ball Catching Game On Screen Using Raspberry Pi

Circuit Diagrams

Circuit-Diagram-Of-Simple-Raspberry-Pi-Game-Pad-For-Ball-Catching-Game

Project Video


Filed Under: Electronic Projects, Raspberry pi
Tagged With: game pad, Raspberry Pi
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

Log in to leave a comment:

Lost your password?

Don't have an account? Register here

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Wide Bandgap Semiconductors
Moving from silicon to GaN or SiC feels like a whole new ballgame, doesn’t it? It isn’t just about faster switching; it’s about managing the layout parasitics and thermal realities that come with that speed. This month’s Tech Toolbox features a curated eBook that tackles these design hurdles head-on.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS feed: EDABOARD.com Discussions. EDABOARD.com Discussions.

  • Odd shape board is expensive
  • Power Engineers - What ECAD software you use?
  • Linear regulator eLoad using wired FET
  • What do they connect Y capacitors to in ships?
  • Built an FPGA-based all-in-one bench instrument (scope, AWG, logic analyzer, PSU, VNA, DMM). Looking for feedback on the design

RSS feed: Electro-Tech-Online.com Discussions Electro-Tech-Online.com Discussions

  • Coin Battery Case 261104
  • How Can You Identify the Main Causes of Noise in an Analogue Circuit?
  • Best way to check charge and discharge many mixed batteries?
  • Heater Circuit
  • Microchip PICDEM Lab Development Board

Featured Tutorials

LoRa and LoRaWAN: A Complete Guide to Wireless Communication

  • Best practices for securing LoRa networks
    Best practices for securing LoRa networks
  • Understanding LoRa architecture: nodes, gateways, and servers
    Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
    Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
    How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
    How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices
    How communication works between two LoRa end-node devices
More Tutorials >

Recent Articles

  • Nuvoton and Qt Group add MCU HMI support
  • MicroStrain by HBK adds compact inertial sensors
  • Allegro MicroSystems expands 48V adas portfolio
  • SemiQ previews 1700 V SiC module
  • pSemi adds wideband RF switch

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2026 Arrowfly LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of Arrowfly
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertisers
    • Advertise
    • PR Submissions
    • Eblast Submissions
  • Subscribe