Arcade Stick

The arcade stick is done!!!!!

Basic Operations
1. Controller reads the inputs from the joystick and the push buttons
2. Controller sends this information to the PC via serial communication
(well... using ftdi so virtual serial communication...)
3. The PC-side receiver translates this information into other useful instructions for the PC

I am using PIC 16F876a microcontroller as the controller
and a software written in MATLAB as the receiver.

For More Information

Check out the following posts:


Using the stick as a mouse:
Using the stick as an arcade stick:

By Joe Kwuen


Arcade Stick: Receiver

This post contains extra details on the receiver of my arcade stick.
PC receives and translates serial data from the controller using MATLAB and JAVA robot class.
I have programmed to operate my stick normally as an arcade stick, and also as a mouse.
In this post I will provide enough hints for anyone to use MATLAB for such purpose.

MATLAB Serial Communication Problem

I noticed many people including me were having problem with MATLAB's serial communication module.


The following code most likely will fix whatever problem you are having.
priorPorts = instrfind

MATLAB's serial communication apparently does not work well when there are any... 
(even the closed ports) 
previously declared ports.
The above code just finds and deletes the memory previously allocated for them.

Some useful MATLAB functions are:

JAVA Robot

first import the class for simplifications later on
import java.awt.Robot;
import java.awt.event.*;
import java.awt.event.KeyEvent;

make a robot class
robot = Robot;

have fun :D

key simulation:
if (sw1 ~= sw10)
if(sw1 == 1)
sw10 = sw1;

The delay of 20 ms simulates how actual keyboard works. 
A keypress function must be released else it will be like a stuck key.

mouse simulation:
pos = get(0, 'PointerLocation');
x_pos = pos(1)+speed;
y_pos = 768-pos(2)+speed;
mouse.mouseMove(x_pos, y_pos);

Read pointer location and move the mouse. 
You can set sensitivity by changing the speed variable.
The first line is included such that you may use your real mouse as well as the joystick to simultaneously move the mouse cursor.

By Joe Kwuen

Arcade Stick - Controller

This post contains extra details on the controller of my arcade stick.
The controller side of the Arcade Stick is fairly simple.
It is just a microcontroller - PIC 16F876a programmed using MPLAB with CCS C compiler.

During the main loop the controller
1. Reads the status of input ports
2. Organizes the info
3. Decides whether to send the info to the PC or not

Checking for Updates
pretty straight forward - just digital reads...

Just two bytes of information sending to the PC:
1 byte of joystick info
1 byte of push button info

The first byte consists of
0 - 0 - 0 - 0 - LEFT? - RIGHT? - DOWN? - UP?
there are four bits of zeroes as fillers because I am using 8N1 serial communication.
The other four bits are assigned to each direction.
For example, 0x08 = left and 0x0A = Left-Down

The second byte consists of
SW7 - SW6 - SW5 - ...
I guess it's self-explanatary that I am using each bit to indicate each switch.

The following code is being used to decide whether to send the info or not:

if(old_dir != new_dir || old_sw != sw)
old_dir = new_dir;
old_sw = sw;

The controller sends info only when the inputs have changed.

This greatly simplifies the PC software and improves the operation of the arcade stick.

By Joe Kwuen