Forum >Replies by moisesduranparraga
userhead moisesduranparraga
Replies (2)
  • You Reply: Hi, I'm new in this forum and I would like you to help me.

    I recently bought the Wireless Gamepad Joystick control, and I started to build a miniature model of a Hovercraft.

    The objective of this project was to control the device with the gamepad, communicating with Xbee. Everything was ok until the program started giving me problems.
    My problem is this: What happens to me is that the controller sends me data of the analog button but the Arduino does not receive the same values I send, that is, my goal is to press (J1 or J2) buttons in order to control the speed of the BRUSSHLESS.
    engine.

    This is the programming of the receiver:
    Code: Select all
    #include <Servo.h>
    Servo servo;

    int value;
     
     
    void setup() {
      Serial.begin(9600);
      servo.attach(9);
     
     // pinMode(potenciometro, INPUT);
    arm();

      // put your setup code here, to run once:

    }

    void loop() {


     
      int val = Serial.read();
      //Serial.println(val, );
     
      val= map (val,507,1023,0,179);
     
      Serial.print(val);
      servo.write(val);
      delay(300);

      }

      void arm(){
        servo.write(0);
        delay(100);
        servo.write(30);
        delay(100);
     
      }


    Programming of the gamepad


    Code: Select all
    #include <SoftwareSerial.h>

    /*
    // #
    // # Editor     : Tong Hui from DFRobot, based on Lauren from DFRobot v1.0 code
    // # Date       : 18.01.2012

    // # Product name: Wireless Gamepad v2.2 for Arduino
    // # Product SKU : DFR0182
    // # Code Version: 2.1

    // # Description:
    // # The sketch for using the gamepad and print the button state and the analog values of the gamepad
    // # Enable the vibration function
    // #   Send 'v' via the Arduino Serial monitor to enable the vibration
    // #   Send 's' via the Arduino Serial monitor to stop it
     
    */

    int buttonState[13];
    int joystick[4];
    int AnalogButton[2];
    int inputCommand = 0;

    #define virbrationMotorPin 2

    void setup()
    {
      Serial.begin(57600);  //Init the Serial baudrate
      Serial1.begin(9600);  //Init the Serial1 port to enable the xbee wireless communication  stream.flush();
           //Initialize the inputs/outputs and the buffers
    }

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

    unsigned long timer = 0;

    void loop()
    {
      Serial.flush();
      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 'v':
            Serial.println("Vibration");
            inputCommand = input;
            digitalWrite(virbrationMotorPin,HIGH);
            break;
         
          case 's':
            Serial.println("Stop");
            inputCommand = input;
            digitalWrite(virbrationMotorPin,LOW);
            break;
           
          default:
            break;
        }
      }
    }

    void DataUpdate(){
     
      for(int i = 3; i < 13; 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[13] = {
      "J2","J1","NULL","S2","S1","UP","LEFT","DOWN","RIGHT","W","4","Z","J"};
      // Buttons Nmes

    void printData(){
    //  for(int i = 0; i < 13; i++)  Serial1.print(buttonState[i]),Serial1.print(" ");
     
        for(int i = 0; i < 4; i++)  Serial.print(joystick[i]),Serial.println(" ");
      for(int i = 0; i < 4; i++)  Serial1.print(joystick[i]),Serial1.println(" ");
     
        for(int i = 0; i < 2; i++)  Serial.print(AnalogButton[i]),Serial.println(" ");
      for(int i = 0; i < 2; i++)  Serial1.print(AnalogButton[i]),Serial1.println(" ");
      //Serial1.println("");
     // Serial.print("Button Pressed:");
      //for(int i = 0; i < 2; i++)  if(buttonState[i] < 100)  Serial.print(Buttons[i]),Serial.println("");
     //for(int i = 6; i < 13; i++)  if(buttonState[i] == 0)  Serial1.println(Buttons[i]);
      Serial1.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("");
      //Serial1.println("Buttons");
     // Serial1.println(inputCommand);
     
    }

    I will appreciate is somebody can help me ^^
  • You Reply: Hi, I'm new in this forum and I would like you to help me.

    I recently bought the Wireless Gamepad Joystick control, and I started to build a miniature model of a Hovercraft.

    The objective of this project was to control the device with the gamepad, communicating with Xbee. Everything was ok until the program started giving me problems.
    My problem is this: What happens to me is that the controller sends me data of the analog button but the Arduino does not receive the same values I send, that is, my goal is to press (J1 or J2) buttons in order to control the speed of the BRUSSHLESS.
    engine.

    This is the programming of the receiver:
    Code: Select all
    #include <Servo.h>
    Servo servo;

    int value;
     
     
    void setup() {
      Serial.begin(9600);
      servo.attach(9);
     
     // pinMode(potenciometro, INPUT);
    arm();

      // put your setup code here, to run once:

    }

    void loop() {


     
      int val = Serial.read();
      //Serial.println(val, );
     
      val= map (val,507,1023,0,179);
     
      Serial.print(val);
      servo.write(val);
      delay(300);

      }

      void arm(){
        servo.write(0);
        delay(100);
        servo.write(30);
        delay(100);
     
      }


    Programming of the gamepad


    Code: Select all
    #include <SoftwareSerial.h>

    /*
    // #
    // # Editor     : Tong Hui from DFRobot, based on Lauren from DFRobot v1.0 code
    // # Date       : 18.01.2012

    // # Product name: Wireless Gamepad v2.2 for Arduino
    // # Product SKU : DFR0182
    // # Code Version: 2.1

    // # Description:
    // # The sketch for using the gamepad and print the button state and the analog values of the gamepad
    // # Enable the vibration function
    // #   Send 'v' via the Arduino Serial monitor to enable the vibration
    // #   Send 's' via the Arduino Serial monitor to stop it
     
    */

    int buttonState[13];
    int joystick[4];
    int AnalogButton[2];
    int inputCommand = 0;

    #define virbrationMotorPin 2

    void setup()
    {
      Serial.begin(57600);  //Init the Serial baudrate
      Serial1.begin(9600);  //Init the Serial1 port to enable the xbee wireless communication  stream.flush();
           //Initialize the inputs/outputs and the buffers
    }

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

    unsigned long timer = 0;

    void loop()
    {
      Serial.flush();
      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 'v':
            Serial.println("Vibration");
            inputCommand = input;
            digitalWrite(virbrationMotorPin,HIGH);
            break;
         
          case 's':
            Serial.println("Stop");
            inputCommand = input;
            digitalWrite(virbrationMotorPin,LOW);
            break;
           
          default:
            break;
        }
      }
    }

    void DataUpdate(){
     
      for(int i = 3; i < 13; 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[13] = {
      "J2","J1","NULL","S2","S1","UP","LEFT","DOWN","RIGHT","W","4","Z","J"};
      // Buttons Nmes

    void printData(){
    //  for(int i = 0; i < 13; i++)  Serial1.print(buttonState[i]),Serial1.print(" ");
     
        for(int i = 0; i < 4; i++)  Serial.print(joystick[i]),Serial.println(" ");
      for(int i = 0; i < 4; i++)  Serial1.print(joystick[i]),Serial1.println(" ");
     
        for(int i = 0; i < 2; i++)  Serial.print(AnalogButton[i]),Serial.println(" ");
      for(int i = 0; i < 2; i++)  Serial1.print(AnalogButton[i]),Serial1.println(" ");
      //Serial1.println("");
     // Serial.print("Button Pressed:");
      //for(int i = 0; i < 2; i++)  if(buttonState[i] < 100)  Serial.print(Buttons[i]),Serial.println("");
     //for(int i = 6; i < 13; i++)  if(buttonState[i] == 0)  Serial1.println(Buttons[i]);
      Serial1.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("");
      //Serial1.println("Buttons");
     // Serial1.println(inputCommand);
     
    }

    I will appreciate is somebody can help me ^^