Forum >Replies by faweiz
userhead faweiz
Replies (20)
  • You Reply: [quote="Grey"]
    Both shields could work with the Romeo.
    I agree with DebianAddict, Wifi shield is more convenient for robot.

    Grey
    [/quote]


    Hi, Grey,


    Ethernet Shield for Arduino - W5200

    Product Code: DFR0272

    https://www.dfrobot.com/index.php?route= ... xfpnfmwLGE


    I just received my ethernet shield today,  However, i don't know how to use it.

    how can I get the MAC address for the "Ethernet Shield for Arduino - W5200 (DFR0272)"?


    also, I tried to use the sample sketch Mac address: 

    byte mac[] = {
      0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

    It doesn't help as well.

    Please reply me how to find the mac address for this Ethernet shield.

    Thank you!
    Tony
  • You Reply: thanks for reply.

    I want to build a robot which can connect to the internet. http://axemblo.net/


    Does "Ethernet Shield for Arduino - W5200 https://www.dfrobot.com/index.php?route= ... xPwAPldVSV" work for romeo V2?

    And what is "DFRobot Ethernet Shield W5200"  different with "arduino official ethernet shield"?

    Tony
  • You Reply: [quote="Grey"]
    Hi Tony,
    Could you provide your xbee link?Because different type of xbee has different setting.
    Whether it is TEL0014?
    If it was, that will be very easy.
    Do you have a xbee usb adapter? And a software named"X-CTU" to set the parameter.[url=http://www.digi.com/support/productdetail?pid=3352]http://www.digi.com/support/productdetail?pid=3352[/url]
    Here is a wiki about how to do.
    [url=https://www.dfrobot.com/wiki/index.php/Xbee#Connecting_your_robot]https://www.dfrobot.com/wiki/index.php/Xbee#Connecting_your_robot[/url]
    [/quote]


    Hi, grey,

    I'm a afraid to say that I'm not using TEL0014, instead I'm using " XBee 1mW Chip Antenna (TEL0060 )". And I'm using "XBee USB Adapter V2" to connect two xbee to pc by using X-CTU software.

  • You Reply: [quote="Grey"]
    Hi Tony,
    Could you provide your xbee link?Because different type of xbee has different setting.
    Whether it is TEL0014?
    If it was, that will be very easy.
    Do you have a xbee usb adapter? And a software named"X-CTU" to set the parameter.[url=http://www.digi.com/support/productdetail?pid=3352]http://www.digi.com/support/productdetail?pid=3352[/url]
    Here is a wiki about how to do.
    [url=https://www.dfrobot.com/wiki/index.php/Xbee#Connecting_your_robot]https://www.dfrobot.com/wiki/index.php/Xbee#Connecting_your_robot[/url]
    [/quote]


    Hi, grey,

    I'm a afraid to say that I'm not using TEL0014, instead I'm using " XBee 1mW Chip Antenna (TEL0060 )". And I'm using "XBee USB Adapter V2" to connect two xbee to pc by using X-CTU software.

  • You Reply: [quote="Grey"]
    Hi Tony,
    Could you provide your xbee link?Because different type of xbee has different setting.
    Whether it is TEL0014?
    If it was, that will be very easy.
    Do you have a xbee usb adapter? And a software named"X-CTU" to set the parameter.[url=http://www.digi.com/support/productdetail?pid=3352]http://www.digi.com/support/productdetail?pid=3352[/url]
    Here is a wiki about how to do.
    [url=https://www.dfrobot.com/wiki/index.php/Xbee#Connecting_your_robot]https://www.dfrobot.com/wiki/index.php/Xbee#Connecting_your_robot[/url]
    [/quote]


    Hi, grey,

    I'm a afraid to say that I'm not using TEL0014, instead I'm using " XBee 1mW Chip Antenna (TEL0060 )". And I'm using "XBee USB Adapter V2" to connect two xbee to pc by using X-CTU software.

  • You Reply: [quote="Grey"]
    Hi Tony,
    Could you provide your xbee link?Because different type of xbee has different setting.
    Whether it is TEL0014?
    If it was, that will be very easy.
    Do you have a xbee usb adapter? And a software named"X-CTU" to set the parameter.[url=http://www.digi.com/support/productdetail?pid=3352]http://www.digi.com/support/productdetail?pid=3352[/url]
    Here is a wiki about how to do.
    [url=https://www.dfrobot.com/wiki/index.php/Xbee#Connecting_your_robot]https://www.dfrobot.com/wiki/index.php/Xbee#Connecting_your_robot[/url]
    [/quote]


    Hi, grey,

    I'm a afraid to say that I'm not using TEL0014, instead I'm using " XBee 1mW Chip Antenna (TEL0060 )". And I'm using "XBee USB Adapter V2" to connect two xbee to pc by using X-CTU software.

  • You Reply: [quote="Grey"]
    Hi Tony,
    Could you provide your xbee link?Because different type of xbee has different setting.
    Whether it is TEL0014?
    If it was, that will be very easy.
    Do you have a xbee usb adapter? And a software named"X-CTU" to set the parameter.[url=http://www.digi.com/support/productdetail?pid=3352]http://www.digi.com/support/productdetail?pid=3352[/url]
    Here is a wiki about how to do.
    [url=https://www.dfrobot.com/wiki/index.php/Xbee#Connecting_your_robot]https://www.dfrobot.com/wiki/index.php/Xbee#Connecting_your_robot[/url]
    [/quote]


    Hi, grey,

    I'm a afraid to say that I'm not using TEL0014, instead I'm using " XBee 1mW Chip Antenna (TEL0060 )". And I'm using "XBee USB Adapter V2" to connect two xbee to pc by using X-CTU software.

  • You Reply: [quote="Grey"]
    Hi Tony
    I think the receiver code has a little problem. It is no necessary to define the buttons for cherokey.
    You know when you press buttons on gamepad, it will display the command in the Serial port.
    And cherokey just receive the command,

    For example , you define "up" as "6". When you press "up" , in the Serial port it shows "6".Then your cherokey receive "6" as command
    Using "switch" command, when it receives "6" it will be set to move upward.
    [code]int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control

    void stop(void)                    //Stop
    {
      digitalWrite(E1,0);
      digitalWrite(M1,LOW);   
      digitalWrite(E2,0); 
      digitalWrite(M2,LOW);   

    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);

    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }
    void turn_L (char a,char b)            //Turn Left
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);
    }
    void turn_R (char a,char b)            //Turn Right
    {
      analogWrite (E1,a);
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }

    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT); 
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }

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

    void loop(void)
    {
      if(Serial.available()){
        //    String n = Buttons();
        char n=Serial.read();
          if(n != -1)
        {
          switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;

          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }

    }
    [/code]

    I just delete the "butten" it isn't a big issue.
    but I think a good idea would be to start debugging the xbee configuration first.
    What kind of xbee you are using now?
    xbee S1/S2 ? or xbee for wifi? even bluetooth bee?
    By the way whether you have an adapter to set xbee?


    [/quote]


    Hello! Grey,

    I'm using the "1mW XBee Transceiver Module (Trace Antenna)" and yes, I've already set the rate of xbees to 9600.

    Please inform me if there is something I'm missing and I need to add.

    Thank you!
    Tony
  • You Reply: [quote="Grey"]
    Hi Tony
    I think the receiver code has a little problem. It is no necessary to define the buttons for cherokey.
    You know when you press buttons on gamepad, it will display the command in the Serial port.
    And cherokey just receive the command,

    For example , you define "up" as "6". When you press "up" , in the Serial port it shows "6".Then your cherokey receive "6" as command
    Using "switch" command, when it receives "6" it will be set to move upward.
    [code]int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control

    void stop(void)                    //Stop
    {
      digitalWrite(E1,0);
      digitalWrite(M1,LOW);   
      digitalWrite(E2,0); 
      digitalWrite(M2,LOW);   

    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);

    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }
    void turn_L (char a,char b)            //Turn Left
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);
    }
    void turn_R (char a,char b)            //Turn Right
    {
      analogWrite (E1,a);
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }

    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT); 
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }

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

    void loop(void)
    {
      if(Serial.available()){
        //    String n = Buttons();
        char n=Serial.read();
          if(n != -1)
        {
          switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;

          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }

    }
    [/code]

    I just delete the "butten" it isn't a big issue.
    but I think a good idea would be to start debugging the xbee configuration first.
    What kind of xbee you are using now?
    xbee S1/S2 ? or xbee for wifi? even bluetooth bee?
    By the way whether you have an adapter to set xbee?


    [/quote]


    Hello! Grey,

    I'm using the "1mW XBee Transceiver Module (Trace Antenna)" and yes, I've already set the rate of xbees to 9600.

    Please inform me if there is something I'm missing and I need to add.

    Thank you!
    Tony
  • You Reply: [quote="Grey"]
    Hi Tony
    I think the receiver code has a little problem. It is no necessary to define the buttons for cherokey.
    You know when you press buttons on gamepad, it will display the command in the Serial port.
    And cherokey just receive the command,

    For example , you define "up" as "6". When you press "up" , in the Serial port it shows "6".Then your cherokey receive "6" as command
    Using "switch" command, when it receives "6" it will be set to move upward.
    [code]int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control

    void stop(void)                    //Stop
    {
      digitalWrite(E1,0);
      digitalWrite(M1,LOW);   
      digitalWrite(E2,0); 
      digitalWrite(M2,LOW);   

    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);

    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }
    void turn_L (char a,char b)            //Turn Left
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);
    }
    void turn_R (char a,char b)            //Turn Right
    {
      analogWrite (E1,a);
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }

    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT); 
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }

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

    void loop(void)
    {
      if(Serial.available()){
        //    String n = Buttons();
        char n=Serial.read();
          if(n != -1)
        {
          switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;

          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }

    }
    [/code]

    I just delete the "butten" it isn't a big issue.
    but I think a good idea would be to start debugging the xbee configuration first.
    What kind of xbee you are using now?
    xbee S1/S2 ? or xbee for wifi? even bluetooth bee?
    By the way whether you have an adapter to set xbee?


    [/quote]


    Hello! Grey,

    I'm using the "1mW XBee Transceiver Module (Trace Antenna)" and yes, I've already set the rate of xbees to 9600.

    Please inform me if there is something I'm missing and I need to add.

    Thank you!
    Tony
  • You Reply: [quote="Grey"]
    Hi Tony
    I think the receiver code has a little problem. It is no necessary to define the buttons for cherokey.
    You know when you press buttons on gamepad, it will display the command in the Serial port.
    And cherokey just receive the command,

    For example , you define "up" as "6". When you press "up" , in the Serial port it shows "6".Then your cherokey receive "6" as command
    Using "switch" command, when it receives "6" it will be set to move upward.
    [code]int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control

    void stop(void)                    //Stop
    {
      digitalWrite(E1,0);
      digitalWrite(M1,LOW);   
      digitalWrite(E2,0); 
      digitalWrite(M2,LOW);   

    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);

    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }
    void turn_L (char a,char b)            //Turn Left
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);
    }
    void turn_R (char a,char b)            //Turn Right
    {
      analogWrite (E1,a);
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }

    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT); 
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }

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

    void loop(void)
    {
      if(Serial.available()){
        //    String n = Buttons();
        char n=Serial.read();
          if(n != -1)
        {
          switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;

          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }

    }
    [/code]

    I just delete the "butten" it isn't a big issue.
    but I think a good idea would be to start debugging the xbee configuration first.
    What kind of xbee you are using now?
    xbee S1/S2 ? or xbee for wifi? even bluetooth bee?
    By the way whether you have an adapter to set xbee?


    [/quote]


    Hello! Grey,

    I'm using the "1mW XBee Transceiver Module (Trace Antenna)" and yes, I've already set the rate of xbees to 9600.

    Please inform me if there is something I'm missing and I need to add.

    Thank you!
    Tony
  • You Reply: [quote="Grey"]
    Hi Tony
    I think the receiver code has a little problem. It is no necessary to define the buttons for cherokey.
    You know when you press buttons on gamepad, it will display the command in the Serial port.
    And cherokey just receive the command,

    For example , you define "up" as "6". When you press "up" , in the Serial port it shows "6".Then your cherokey receive "6" as command
    Using "switch" command, when it receives "6" it will be set to move upward.
    [code]int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control

    void stop(void)                    //Stop
    {
      digitalWrite(E1,0);
      digitalWrite(M1,LOW);   
      digitalWrite(E2,0); 
      digitalWrite(M2,LOW);   

    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);

    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }
    void turn_L (char a,char b)            //Turn Left
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);
    }
    void turn_R (char a,char b)            //Turn Right
    {
      analogWrite (E1,a);
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }

    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT); 
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }

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

    void loop(void)
    {
      if(Serial.available()){
        //    String n = Buttons();
        char n=Serial.read();
          if(n != -1)
        {
          switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;

          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }

    }
    [/code]

    I just delete the "butten" it isn't a big issue.
    but I think a good idea would be to start debugging the xbee configuration first.
    What kind of xbee you are using now?
    xbee S1/S2 ? or xbee for wifi? even bluetooth bee?
    By the way whether you have an adapter to set xbee?


    [/quote]


    Hello! Grey,

    I'm using the "1mW XBee Transceiver Module (Trace Antenna)" and yes, I've already set the rate of xbees to 9600.

    Please inform me if there is something I'm missing and I need to add.

    Thank you!
    Tony
  • You Reply: [quote="Jose"]
    [quote="faweiz"]
    ... 
    char val = Serial.read();

        if(val != -1)
        {
          switch(val)
          {
          case 'UP'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case 'Down'://Move Backward
            back_off (255,255);  //move back in max spe
    ...
    [/quote]

    char val = Serial.read();  goes char by char, so it will never be UP or DOWN, it will be U, P. or D,O,W,N.
    you might want todo a loop that reads the whole thing and store it in a string, then do the switch? or rather, just use some numbers, like up is 1, and down is 2..

    As for the gamepad, completely agree with grey. I'd take that and just parse it on the Cherokey

    Cheers^^
    [/quote]



    Hello! Jose and Grey,

    Thank you for your guys quick response.

    I tried to add and modify the code, As suggest from Grey which I just keep the 'wireless game-pad' code unchanged and modified the following code to the 'Cherokey 4WD' of  the 'void loop' :



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


    void loop(void)
    {
    if(Serial.available()){
        String n = Buttons();
        if(n != -1)
        {
      switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;
         
          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }
     
    }[/code]"








    [b]
    Could you please help me check if these two codes work for the 'Cherokey 4WD' and 'Wirless GamePad V2.0' with using Xbee? If not, could you please teach me how can I modify the code to make them work with xbee?[/b]








    [u]Code for Sender (Wireless Game-pad V2.0 with Xbee) [i]remain the same[/i][/u]


    [code]/*
    // #
    // # 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
    // #
     
    */

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

    int inputCommand = 0;

    #define shackMotorPin 2

    void setup()
    {
      Serial.begin(57600);  //Init the Serial baudrate

      Serial1.begin(9600);  //Init the Serial1 port to enable the xbee wireless communication

      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",NULL,"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);
    }[/code]











    [u]Code for Receiver (Cherokey 4WD with Xbee): [/u]


    [code]
    int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control

    void stop(void)                    //Stop
    {
      digitalWrite(E1,0);
      digitalWrite(M1,LOW);   
      digitalWrite(E2,0); 
      digitalWrite(M2,LOW);   

    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);

    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }
    void turn_L (char a,char b)            //Turn Left
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);
    }
    void turn_R (char a,char b)            //Turn Right
    {
      analogWrite (E1,a);
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }

    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT); 
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }

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


    void loop(void)
    {
    if(Serial.available()){
        String n = Buttons();
        if(n != -1)
        {
      switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;
         
          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }
     
    }[/code]








    [b]
    Could you please help me check if these two codes work for the 'Cherokey 4WD' and 'Wirless GamePad V2.0' with using Xbee? If not, could you please teach me how can I modify the code to make them work with xbee?[/b]

    Any help would be greatly appreciated!

    Tony
  • You Reply: [quote="Jose"]
    [quote="faweiz"]
    ... 
    char val = Serial.read();

        if(val != -1)
        {
          switch(val)
          {
          case 'UP'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case 'Down'://Move Backward
            back_off (255,255);  //move back in max spe
    ...
    [/quote]

    char val = Serial.read();  goes char by char, so it will never be UP or DOWN, it will be U, P. or D,O,W,N.
    you might want todo a loop that reads the whole thing and store it in a string, then do the switch? or rather, just use some numbers, like up is 1, and down is 2..

    As for the gamepad, completely agree with grey. I'd take that and just parse it on the Cherokey

    Cheers^^
    [/quote]



    Hello! Jose and Grey,

    Thank you for your guys quick response.

    I tried to add and modify the code, As suggest from Grey which I just keep the 'wireless game-pad' code unchanged and modified the following code to the 'Cherokey 4WD' of  the 'void loop' :



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


    void loop(void)
    {
    if(Serial.available()){
        String n = Buttons();
        if(n != -1)
        {
      switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;
         
          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }
     
    }[/code]"








    [b]
    Could you please help me check if these two codes work for the 'Cherokey 4WD' and 'Wirless GamePad V2.0' with using Xbee? If not, could you please teach me how can I modify the code to make them work with xbee?[/b]








    [u]Code for Sender (Wireless Game-pad V2.0 with Xbee) [i]remain the same[/i][/u]


    [code]/*
    // #
    // # 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
    // #
     
    */

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

    int inputCommand = 0;

    #define shackMotorPin 2

    void setup()
    {
      Serial.begin(57600);  //Init the Serial baudrate

      Serial1.begin(9600);  //Init the Serial1 port to enable the xbee wireless communication

      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",NULL,"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);
    }[/code]











    [u]Code for Receiver (Cherokey 4WD with Xbee): [/u]


    [code]
    int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control

    void stop(void)                    //Stop
    {
      digitalWrite(E1,0);
      digitalWrite(M1,LOW);   
      digitalWrite(E2,0); 
      digitalWrite(M2,LOW);   

    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);

    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }
    void turn_L (char a,char b)            //Turn Left
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);
    }
    void turn_R (char a,char b)            //Turn Right
    {
      analogWrite (E1,a);
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }

    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT); 
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }

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


    void loop(void)
    {
    if(Serial.available()){
        String n = Buttons();
        if(n != -1)
        {
      switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;
         
          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }
     
    }[/code]








    [b]
    Could you please help me check if these two codes work for the 'Cherokey 4WD' and 'Wirless GamePad V2.0' with using Xbee? If not, could you please teach me how can I modify the code to make them work with xbee?[/b]

    Any help would be greatly appreciated!

    Tony
  • You Reply: [quote="Jose"]
    [quote="faweiz"]
    ... 
    char val = Serial.read();

        if(val != -1)
        {
          switch(val)
          {
          case 'UP'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case 'Down'://Move Backward
            back_off (255,255);  //move back in max spe
    ...
    [/quote]

    char val = Serial.read();  goes char by char, so it will never be UP or DOWN, it will be U, P. or D,O,W,N.
    you might want todo a loop that reads the whole thing and store it in a string, then do the switch? or rather, just use some numbers, like up is 1, and down is 2..

    As for the gamepad, completely agree with grey. I'd take that and just parse it on the Cherokey

    Cheers^^
    [/quote]



    Hello! Jose and Grey,

    Thank you for your guys quick response.

    I tried to add and modify the code, As suggest from Grey which I just keep the 'wireless game-pad' code unchanged and modified the following code to the 'Cherokey 4WD' of  the 'void loop' :



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


    void loop(void)
    {
    if(Serial.available()){
        String n = Buttons();
        if(n != -1)
        {
      switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;
         
          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }
     
    }[/code]"








    [b]
    Could you please help me check if these two codes work for the 'Cherokey 4WD' and 'Wirless GamePad V2.0' with using Xbee? If not, could you please teach me how can I modify the code to make them work with xbee?[/b]








    [u]Code for Sender (Wireless Game-pad V2.0 with Xbee) [i]remain the same[/i][/u]


    [code]/*
    // #
    // # 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
    // #
     
    */

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

    int inputCommand = 0;

    #define shackMotorPin 2

    void setup()
    {
      Serial.begin(57600);  //Init the Serial baudrate

      Serial1.begin(9600);  //Init the Serial1 port to enable the xbee wireless communication

      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",NULL,"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);
    }[/code]











    [u]Code for Receiver (Cherokey 4WD with Xbee): [/u]


    [code]
    int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control

    void stop(void)                    //Stop
    {
      digitalWrite(E1,0);
      digitalWrite(M1,LOW);   
      digitalWrite(E2,0); 
      digitalWrite(M2,LOW);   

    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);

    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }
    void turn_L (char a,char b)            //Turn Left
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);
    }
    void turn_R (char a,char b)            //Turn Right
    {
      analogWrite (E1,a);
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }

    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT); 
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }

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


    void loop(void)
    {
    if(Serial.available()){
        String n = Buttons();
        if(n != -1)
        {
      switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;
         
          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }
     
    }[/code]








    [b]
    Could you please help me check if these two codes work for the 'Cherokey 4WD' and 'Wirless GamePad V2.0' with using Xbee? If not, could you please teach me how can I modify the code to make them work with xbee?[/b]

    Any help would be greatly appreciated!

    Tony
  • You Reply: [quote="Jose"]
    [quote="faweiz"]
    ... 
    char val = Serial.read();

        if(val != -1)
        {
          switch(val)
          {
          case 'UP'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case 'Down'://Move Backward
            back_off (255,255);  //move back in max spe
    ...
    [/quote]

    char val = Serial.read();  goes char by char, so it will never be UP or DOWN, it will be U, P. or D,O,W,N.
    you might want todo a loop that reads the whole thing and store it in a string, then do the switch? or rather, just use some numbers, like up is 1, and down is 2..

    As for the gamepad, completely agree with grey. I'd take that and just parse it on the Cherokey

    Cheers^^
    [/quote]



    Hello! Jose and Grey,

    Thank you for your guys quick response.

    I tried to add and modify the code, As suggest from Grey which I just keep the 'wireless game-pad' code unchanged and modified the following code to the 'Cherokey 4WD' of  the 'void loop' :



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


    void loop(void)
    {
    if(Serial.available()){
        String n = Buttons();
        if(n != -1)
        {
      switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;
         
          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }
     
    }[/code]"








    [b]
    Could you please help me check if these two codes work for the 'Cherokey 4WD' and 'Wirless GamePad V2.0' with using Xbee? If not, could you please teach me how can I modify the code to make them work with xbee?[/b]








    [u]Code for Sender (Wireless Game-pad V2.0 with Xbee) [i]remain the same[/i][/u]


    [code]/*
    // #
    // # 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
    // #
     
    */

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

    int inputCommand = 0;

    #define shackMotorPin 2

    void setup()
    {
      Serial.begin(57600);  //Init the Serial baudrate

      Serial1.begin(9600);  //Init the Serial1 port to enable the xbee wireless communication

      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",NULL,"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);
    }[/code]











    [u]Code for Receiver (Cherokey 4WD with Xbee): [/u]


    [code]
    int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control

    void stop(void)                    //Stop
    {
      digitalWrite(E1,0);
      digitalWrite(M1,LOW);   
      digitalWrite(E2,0); 
      digitalWrite(M2,LOW);   

    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);

    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }
    void turn_L (char a,char b)            //Turn Left
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);
    }
    void turn_R (char a,char b)            //Turn Right
    {
      analogWrite (E1,a);
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }

    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT); 
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }

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


    void loop(void)
    {
    if(Serial.available()){
        String n = Buttons();
        if(n != -1)
        {
      switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;
         
          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }
     
    }[/code]








    [b]
    Could you please help me check if these two codes work for the 'Cherokey 4WD' and 'Wirless GamePad V2.0' with using Xbee? If not, could you please teach me how can I modify the code to make them work with xbee?[/b]

    Any help would be greatly appreciated!

    Tony
  • You Reply: [quote="Jose"]
    [quote="faweiz"]
    ... 
    char val = Serial.read();

        if(val != -1)
        {
          switch(val)
          {
          case 'UP'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case 'Down'://Move Backward
            back_off (255,255);  //move back in max spe
    ...
    [/quote]

    char val = Serial.read();  goes char by char, so it will never be UP or DOWN, it will be U, P. or D,O,W,N.
    you might want todo a loop that reads the whole thing and store it in a string, then do the switch? or rather, just use some numbers, like up is 1, and down is 2..

    As for the gamepad, completely agree with grey. I'd take that and just parse it on the Cherokey

    Cheers^^
    [/quote]



    Hello! Jose and Grey,

    Thank you for your guys quick response.

    I tried to add and modify the code, As suggest from Grey which I just keep the 'wireless game-pad' code unchanged and modified the following code to the 'Cherokey 4WD' of  the 'void loop' :



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


    void loop(void)
    {
    if(Serial.available()){
        String n = Buttons();
        if(n != -1)
        {
      switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;
         
          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }
     
    }[/code]"








    [b]
    Could you please help me check if these two codes work for the 'Cherokey 4WD' and 'Wirless GamePad V2.0' with using Xbee? If not, could you please teach me how can I modify the code to make them work with xbee?[/b]








    [u]Code for Sender (Wireless Game-pad V2.0 with Xbee) [i]remain the same[/i][/u]


    [code]/*
    // #
    // # 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
    // #
     
    */

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

    int inputCommand = 0;

    #define shackMotorPin 2

    void setup()
    {
      Serial.begin(57600);  //Init the Serial baudrate

      Serial1.begin(9600);  //Init the Serial1 port to enable the xbee wireless communication

      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",NULL,"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);
    }[/code]











    [u]Code for Receiver (Cherokey 4WD with Xbee): [/u]


    [code]
    int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control

    void stop(void)                    //Stop
    {
      digitalWrite(E1,0);
      digitalWrite(M1,LOW);   
      digitalWrite(E2,0); 
      digitalWrite(M2,LOW);   

    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);

    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }
    void turn_L (char a,char b)            //Turn Left
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW);   
      analogWrite (E2,b);   
      digitalWrite(M2,HIGH);
    }
    void turn_R (char a,char b)            //Turn Right
    {
      analogWrite (E1,a);
      digitalWrite(M1,HIGH);   
      analogWrite (E2,b);   
      digitalWrite(M2,LOW);
    }

    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT); 
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }

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


    void loop(void)
    {
    if(Serial.available()){
        String n = Buttons();
        if(n != -1)
        {
      switch(n)
          {
          case '6'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case '8'://Move Backward
            back_off (255,255);  //move back in max speed
            break;
          case '7'://Turn Left
            turn_L (100,100);       
            break;     
          case '9'://Turn Right
            turn_R (100,100);
            break;
         
          case '1':
            stop();
            break;
          }
        }
        else stop(); 
      }
     
    }[/code]








    [b]
    Could you please help me check if these two codes work for the 'Cherokey 4WD' and 'Wirless GamePad V2.0' with using Xbee? If not, could you please teach me how can I modify the code to make them work with xbee?[/b]

    Any help would be greatly appreciated!

    Tony
  • You Reply: Hello! Grey,

    Thanks for your quick response. Your information is very useful. And I've written two arduino sketches for both "Wireless Game-pad V2.0 with Xbee" and "Cherokey 4WD with Xbee"

    Could you please help me check the below codes? Please let me know if there is anythings I need to modify or to add to these arduino sketches.


    Your helps would be greatly appreciated!




    [u]Sender (Wireless Game-pad V2.0 with [/u][u]Xbee):[/u]

    void setup() {
    Serial.begin(9600);
    }
    void loop() {
    Serial.println("UP"); //move forward
    delay(1000);
    Serial.println("Down");//move Backward
    delay(1000);
    }



    [u]Receiver (Cherokey 4WD with Xbee): [/u]

    int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control


    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH); 
      analogWrite (E2,b); 
      digitalWrite(M2,HIGH);
    }
    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b); 
      digitalWrite(M2,LOW);
    }


    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT);
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }



    void loop(void)
    {
      if(Serial.available() > 0)
      {
        char val = Serial.read();


        if(val != -1)
        {
          switch(val)
          {
          case 'UP'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case 'Down'://Move Backward
            back_off (255,255);  //move back in max speed
            break;     
          }
        }

        else stop();
      }
     
    }

  • You Reply: Hello! Grey,

    Thanks for your quick response. Your information is very useful. And I've written two arduino sketches for both "Wireless Game-pad V2.0 with Xbee" and "Cherokey 4WD with Xbee"

    Could you please help me check the below codes? Please let me know if there is anythings I need to modify or to add to these arduino sketches.


    Your helps would be greatly appreciated!




    [u]Sender (Wireless Game-pad V2.0 with [/u][u]Xbee):[/u]

    void setup() {
    Serial.begin(9600);
    }
    void loop() {
    Serial.println("UP"); //move forward
    delay(1000);
    Serial.println("Down");//move Backward
    delay(1000);
    }



    [u]Receiver (Cherokey 4WD with Xbee): [/u]

    int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control


    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH); 
      analogWrite (E2,b); 
      digitalWrite(M2,HIGH);
    }
    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b); 
      digitalWrite(M2,LOW);
    }


    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT);
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }



    void loop(void)
    {
      if(Serial.available() > 0)
      {
        char val = Serial.read();


        if(val != -1)
        {
          switch(val)
          {
          case 'UP'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case 'Down'://Move Backward
            back_off (255,255);  //move back in max speed
            break;     
          }
        }

        else stop();
      }
     
    }

  • You Reply: Hello! Grey,

    Thanks for your quick response. Your information is very useful. And I've written two arduino sketches for both "Wireless Game-pad V2.0 with Xbee" and "Cherokey 4WD with Xbee"

    Could you please help me check the below codes? Please let me know if there is anythings I need to modify or to add to these arduino sketches.


    Your helps would be greatly appreciated!




    [u]Sender (Wireless Game-pad V2.0 with [/u][u]Xbee):[/u]

    void setup() {
    Serial.begin(9600);
    }
    void loop() {
    Serial.println("UP"); //move forward
    delay(1000);
    Serial.println("Down");//move Backward
    delay(1000);
    }



    [u]Receiver (Cherokey 4WD with Xbee): [/u]

    int E1 = 5;    //M1 Speed Control
    int E2 = 6;    //M2 Speed Control
    int M1 = 4;    //M1 Direction Control
    int M2 = 7;    //M1 Direction Control


    void advance(char a,char b)          //Move forward
    {
      analogWrite (E1,a);      //PWM Speed Control
      digitalWrite(M1,HIGH); 
      analogWrite (E2,b); 
      digitalWrite(M2,HIGH);
    }
    void back_off (char a,char b)          //Move backward
    {
      analogWrite (E1,a);
      digitalWrite(M1,LOW); 
      analogWrite (E2,b); 
      digitalWrite(M2,LOW);
    }


    void setup(void)
    {
      int i;
      for(i=4;i<=7;i++)
        pinMode(i, OUTPUT);
      Serial.begin(9600);      //Set Baud Rate
      Serial.println("Run keyboard control");
      digitalWrite(E1,LOW); 
      digitalWrite(E2,LOW);
      pinMode(2,INPUT);
      pinMode(3,INPUT);
    }



    void loop(void)
    {
      if(Serial.available() > 0)
      {
        char val = Serial.read();


        if(val != -1)
        {
          switch(val)
          {
          case 'UP'://Move Forward
            advance (255,255);  //move forward in max speed
            break;
          case 'Down'://Move Backward
            back_off (255,255);  //move back in max speed
            break;     
          }
        }

        else stop();
      }
     
    }