Mohammad

Robotics Blog

RECENT POSTS

TWITTER UPDATES

No public Twitter messages.

Arduino Based Wireless Joypad

Posted by Mohammad On January - 15 - 2009 5 COMMENTS

I was thinking about designing a Wireless Joypad to control my Robot, and finally came up with an idea to make it out of a cheap Gigaware PS2 Joypad found at Radioshack, which was only $9.99. It has:

  • 2 Joysticks
  • 1 8-way D-Pad (Direction Pad)
  • 8 Action Buttons, and
  • 4 Extra Buttons (Select, Start, Macro, Mode)

So, I was searching on web, how to interface this PS2 Controller with Arduino, and finally found an Arduino compatible library called PSX Library. I used it with my Arduino and it didn’t work. I guess, it didn’t work because this library was for PlayStation 1, but my controller was PS2 compatible. So, I gave up this idea of using any library. It’s the time for me to come up with my own library.

Thereafter, I cut off the PS2 connector along with the long cable. This will be wireless, so why bother with this annoying cable/connector? This time I am not using any circuitry inside the Joypad. The only things I need are the Push Buttons, LEDs and the Joystick Potentiometer. Then I figured out the schematic of the two joysticks:

The approximate value for each Potentiometer is 5.2K. So, those 4 points will be used as Arduino Analog Input ( Pin 1 to 4 respectively). There was not really enough space inside the joypad, that’s why I had to use wire wrap wires to solder the connectors of buttons, potentiometers and LEDs. I was able to solder only 8 buttons, out of all 16; because the other 8 were so compact that they were almost impossible to solder. This 8 buttons and 2 LEDs will be connected to 10 Digital I/O pins on Arduino.

Here’re some pictures of the Modified Joypad, the Arduino board, and the Transmitter and Receiver modules:

I found some reference article on how to interface these RF Modules with Microcontroller. Here they are:

Running TX433 and RX433 RF modules with AVR microcontrollers
KLP/KLPA Module Walkthrough by Sparkfun
Implementing RF Modules

So, I followed the first reference (Running TX433 … …), and it worked without any problem. By the way, that example module was using 4-Bytes Packet Transmission Protocol at 1200 bps. I modified the code for Arduino, and as it worked with 2400 bps (because my RF Modules were little faster, 4800 bps).

My joypad has 2 joysticks and each of them has 2-axis (X and Y). So, it gives 4 analog inputs to the microcontroller and each input has a resolution of 1024 (0 to 1023), which requires 2 byes (integer) for each. And 2 joysticks needs 8 bytes (4 x 2 bytes). The 8 push buttons can be represented as 1 byte (1 bit for each button). The data transmission packet itself has 1 Synchronization byte, 1 address byte, and 1 Checksum word (2 bytes). So the length of the complete packet is 13 (8+1+1+1+2) bytes.

This time my code went real crazy. I tried to keep it clean and well-commented almost everything I could. As there are two separate circuits: the transmitter (joypad itself) and the receiver (Arduino Duemilanove); so there will be two separate scripts. But, I made the WirelessDataPacket class common for both. Here are both sketch source files:

Transmitter Sketch Source

Receiver Sketch Source

Everything was working cool when I was using 4-Bytes Transmission Protocol (as mentioned in the example reference). But when I am using 13-Bytes Packet, it became a lot slower and more than 50% (approximate) data is losing at the time of transmission.

I calculate the speed this way,

2400 bps = (2400/8) bytes per second = 300 Bps

300 Bps = (300/13) packets per second = 23 pps

Arduino uses 16.0000 MHz crystal (instead of 9.216 or 11.0592 or 18.432 MHz etc.) which can produce 0.1% error (ref: AVR BAUD Rate Calculator). And including some other circumstances (hardware+software) 5% error is acceptable. But for my case, the error rate is so huge that the transmission is breaking up and becomes too much slow. I guess, this can improve if the BAUD Rate of the RF Modules can be improvised and some other programming technique (which I don’t know yet) can me implemented.

VN:F [1.8.4_1055]
Rating: 10.0/10 (1 vote cast)
VN:F [1.8.4_1055]
Rating: 0 (from 0 votes)
Arduino Based Wireless Joypad10.0101

5 Responses

  1. Eric says:

    Very nice work Mohammad! Detailed and clear , and full of diagrams and pictures.

    A+

    UN:F [1.8.4_1055]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.4_1055]
    Rating: 0 (from 0 votes)
  2. Prof Saadawi says:

    Excellent project….You have shown skills in various technologies; microcontroller, wireless/RF, data transmission protocols, error detecting codes……Keep up the creativity………

    UN:F [1.8.4_1055]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.4_1055]
    Rating: 0 (from 0 votes)
  3. Binu says:

    Nice project.
    Most of the RF modules work efficiently at lower baud rates less than 500.

    UN:F [1.8.4_1055]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.4_1055]
    Rating: 0 (from 0 votes)
  4. Jung says:

    Great!!! I was looking for something like this.

    UN:F [1.8.4_1055]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.4_1055]
    Rating: 0 (from 0 votes)
  5. Alan says:

    Just curious, what was the problem you were having with the PSX lib, is it before or after compile?
    I am having trouble using the PSX with Arduino 0016 IDE, but the error is during the compile.

    UN:F [1.8.4_1055]
    Rating: 0.0/5 (0 votes cast)
    UN:F [1.8.4_1055]
    Rating: 0 (from 0 votes)

Leave a Reply