Wirless_GamePad_V2.0__SKU_DFR0182_-DFRobot

Introduction

The Wireless Joystick v2 for Arduino is the first gamepad based on Arduino from DFRobot. It support Xbee, Bluetooth, RF and Wifi via the Xbee socket. Makes it possible to custom your own wireless communication for controlling your robots, mobile platforms, UAVs, etc.

Improvements of v2.0:

  1. Wireless gamepad v2.0 is compatible with Arduino Leonardo. Comparing with v1.1, you don't need to purchase a FTDI programmer for it anymore. Just plugin the Micro USB adapter and program it directly.

  2. The v2.2 gamepad supports a new feature. It integrated two-way motor driver circuit and two vibration motors. Then it's available to program and enable the vibration function of your gamepad and get the feedback from your robots!

Specification

PinOut

Programming Connection

Pin mapping

Direction Buttons

Surface Buttons

Joystick Buttons

Joystick analog inputs

Z Buttons

Other functions

Sample code

NOTE: Please revise the Serial.****() to Serial1.****() when you use BLE link or Xbee module to communicate with other module wirelessly.
/*
// #
// # Editor     : Tong Hui from DFRobot, based on Lauren from DFRobot v1.0 code
// # Date       : 12.24.2012

// # Product name: Wireless Joystick v2.2 for Arduino
// # Product SKU : DFR0182
// # Code Version: 2.0

// # Description:
// # The sketch for using the gamepad and print the button state and the analog values of the gamepad
// # to computer screen using serial monitor

*/

int buttonState[17];
int joystick[4];
int AnalogButton[2];

int inputCommand = 0;

#define shackMotorPin 2

void setup()
{
  Serial.begin(57600);  //Init the Serial baudrate
  InitIO();             // Initialize the inputs/outputs and the buffers
}

void InitIO(){
  for(int i = 0; i < 17; i  )
  pinMode(i, INPUT);
  pinMode(shackMotorPin,OUTPUT);
  digitalWrite(shackMotorPin,LOW);  // Stop shacking of the gamepad
}

unsigned long timer = 0;

void loop()
{
  if(millis() - timer > 500){  // manage the updating freq of all the controlling information
    DataUpdate();  //read the buttons and the joysticks data
    printData();   //print the datas and states
    timer = millis();
  }

  if(Serial.available()){
    char input = Serial.read();

    switch(input){
      case 's':
        Serial.println("Shack");
        inputCommand = input;
        digitalWrite(shackMotorPin,HIGH);
        break;

      case 'x':
        Serial.println("Stop");
        inputCommand = input;
        digitalWrite(shackMotorPin,LOW);
        break;

      default:
        break;
    }
  }
}

void DataUpdate(){

  for(int i = 3; i < 17; i  )  buttonState[i] = digitalRead(i);
  buttonState[0] = analogRead(0);
  buttonState[1] = analogRead(1);
  for(int i = 0; i < 4; i  )  joystick[i] = analogRead(i);
  for(int i = 4; i < 6; i  )  AnalogButton[i-4] = analogRead(i);

}

String Buttons[17] = {
  "J2","J1","","S2","S1","UP","LEFT","DOWN","RIGHT","1","4","2","3","RZ1","RZ2","LZ1","LZ2"};
  // Buttons Nmes

void printData(){
//  for(int i = 0; i < 17; i  )  Serial.print(buttonState[i]),Serial.print(" ");
//  for(int i = 0; i < 4; i  )  Serial.print(joystick[i]),Serial.print(" ");
//  for(int i = 0; i < 2; i  )  Serial.print(AnalogButton[i]),Serial.print(" ");
//  Serial.println("");
  Serial.print("Button Pressed:");
  for(int i = 0; i < 2; i  )  if(buttonState[i] < 100)  Serial.print(Buttons[i]),Serial.print(",");
  for(int i = 3; i < 17; i  )  if(buttonState[i] == 0)  Serial.print(Buttons[i]),Serial.print(",");
  Serial.println("");
  Serial.print("Analog Sticks:");
  for(int i = 0; i < 4; i  )  Serial.print(joystick[i]),Serial.print(",");
  for(int i = 0; i < 2; i  )  Serial.print(AnalogButton[i]),Serial.print(",");
  Serial.println("");
  Serial.println(inputCommand);
}

FAQ

Q The joystick board does not respond and transmit properly. I have validated the XBee on another system and communication is no problem. I have also validated the code is working as expected.
A.1 The sample code is used to test the gamepad on your computer by a USB cable, but not to communicate wirelessly by Xbee, Bluetooth module, etc. If you want to use the code for the later purpose or write your own code, please change all serial.xxx() to serial1.xxx() since the board (leonardo) use its serial1 instead of serial to communicate with the wireless modules.
A.2 Please check if you have inserted the wireless module onto the Xbee socket inversely
A.3 For any questions/advice/cool ideas to share, please visit DFRobot Forum.

More

DFshopping_car1.png Get Wireless GamePad V2.0 for Arduino from DFRobot Store or DFRobot Distributor.

Turn to the Top