go away spammer

Author Topic: Arduino Based Wireless Joypad  (Read 6883 times)

0 Members and 1 Guest are viewing this topic.

Offline reefatTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
    • Reefat's Robotics Blog
Arduino Based Wireless Joypad
« on: January 15, 2009, 11:19:50 PM »
For everyone's convenience, note that, previously I've posted this article on my blog at Arduino Based Wireless Joypad.

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 (click to enlarge):


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


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:


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.
« Last Edit: January 17, 2009, 12:18:12 AM by reefat »

 


Get Your Ad Here