3D PrintingGeneral

Gamepad v2.0 and xbee

userHead rodrrigo91 2015-01-25 02:17:52 32934 Views19 Replies
I'm trying to recognize the values in the receiver but I can´t find the way to read analog values and characters, It throw me away this data.

UP,DOWN,
500,500,500,500 for example... I need to read those analog, can someone help me?
2016-07-09 08:05:49 Look at basecamelectronics - They have a serial API to control TX/RX interface. They have several projects on got hub that will be of use.

For example:

void Gimbal_SendCommand(byte Command, byte *Data, int Size)
{
byte i, Checksum = 0;


Serial1.write('>');
Serial1.write(Command);
Serial1.write(Size);
Serial1.write(Command + Size);
for(i=0; i < Size; i++)
{
Checksum += Data[i];
Serial1.write(Data[i]);
}
Serial1.write(Checksum);

// Serial.print(Command);
// Serial.println(" Message sent.");

delay(20); /* 20ms delay as suggested in SimpleBGC firmware */
}
userHeadPic tnapoleon74
2016-07-09 08:05:49 Look at basecamelectronics - They have a serial API to control TX/RX interface. They have several projects on got hub that will be of use.

For example:

void Gimbal_SendCommand(byte Command, byte *Data, int Size)
{
byte i, Checksum = 0;


Serial1.write('>');
Serial1.write(Command);
Serial1.write(Size);
Serial1.write(Command + Size);
for(i=0; i < Size; i++)
{
Checksum += Data[i];
Serial1.write(Data[i]);
}
Serial1.write(Checksum);

// Serial.print(Command);
// Serial.println(" Message sent.");

delay(20); /* 20ms delay as suggested in SimpleBGC firmware */
}
userHeadPic tnapoleon74
2016-07-09 05:52:30 PS Why is this in the 3D section of the board? userHeadPic Smith Bob
2016-07-09 05:52:30 PS Why is this in the 3D section of the board? userHeadPic Smith Bob
2016-07-09 05:51:22 I couldn't find any sample receiver code. Since DFRobot has supplied the gamepad Tx code could you not supply a simple string decoder for an Arduino receiver?
It's hard work piecing this together into a solution without it. I am sure, from the above that it's just a few lines of code showing the Serial.read() part of a sketch.
I am sure many others would be helped.
Bob
userHeadPic Smith Bob
2016-07-09 05:51:22 I couldn't find any sample receiver code. Since DFRobot has supplied the gamepad Tx code could you not supply a simple string decoder for an Arduino receiver?
It's hard work piecing this together into a solution without it. I am sure, from the above that it's just a few lines of code showing the Serial.read() part of a sketch.
I am sure many others would be helped.
Bob
userHeadPic Smith Bob
2016-03-04 11:11:07 Hi moisesduranparraga,

Has it been solved? :shock:
userHeadPic Leff
2016-03-04 11:11:07 Hi moisesduranparraga,

Has it been solved? :shock:
userHeadPic Leff
2016-01-14 17:19:28 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 ^^
userHeadPic moisesduranparraga
2016-01-14 17:19:28 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 ^^
userHeadPic moisesduranparraga
2015-01-28 02:16:13 but how I can read a serie of numbers ? like 1023 and commas.
I have another problem with this if you can help me it will be very nice.


I have this code from dfRobot, when I press UP and L1 I want to do  something like turning a led, but actually my code works like this.. I press only one time L1 and y=true, if I press UP the led turns on every time I press UP, if I press both led turns on (that's what I want), how can I fix that problem? I tried to enter several loops there without success

Code: Select all
/*
 # Editor : Phoebe
 # Date   : 2014.11.6
 # Ver    : 0.1
 # Product: Devastator Tank Mobile Platform
 # SKU    : RBO0112
 # Description:    
 # Connect the D4,D5,D6,D7,GND to UNO digital 4,5,6,7,GND
 
*/
  
int E1 = 5;     //M1 Speed Control
int E2 = 6;     //M2 Speed Control
int M1 = 13;     //M1 Direction Control
int M2 = 7;     //M1 Direction Control
char val;
boolean y=false;
boolean x=false;
boolean z=false;
 
void stop(void)                    //Stop
{
   
  digitalWrite(M1,LOW);   
  
}  
void advance(void)         //Move forward
{
  x=true;
  if (z==true)
 { 
   if (x==true && y==true)
   {
     digitalWrite(M1,HIGH); 
     delay(450);
      
      
  }
  else
  {
    x=false;
    y=false;
    z=false;
}


}
}
void back_off  (void)         //Move backward
{
      y=true;
  
  if (y && x)
  {
    z=true;
  }
  else if (y && !x)
  {
    z=false;
    y=false;
  }
    else if (x && !y)
  {
    z=false;
    x=false;
  }




 
}
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<=13;i++)
    pinMode(i, OUTPUT); 
  Serial.begin(9600);      //Set Baud Rate

  digitalWrite(E1,LOW);  
  digitalWrite(E2,LOW);
 
}

void serial (void)
{
      switch(val)
      {
      case 'UP'://Move Forward
        advance ();  //move forward in max speed
        break;
      case 'L1'://Move Backward
        back_off () ;  //move back in max speed
        break;
      case 'BACK'://Turn Left
        turn_L (100,100);    
        break;      
      case 'US'://Turn Right
        turn_R (100,100);
        break;
      case 'v':
        break;
      default:
        stop();
      }
}

void loop()
{
  if(Serial.available())
  {
    val = Serial.read();
    serial();
  }
}
  
   
 
userHeadPic rodrrigo91
2015-01-28 02:16:13 but how I can read a serie of numbers ? like 1023 and commas.
I have another problem with this if you can help me it will be very nice.


I have this code from dfRobot, when I press UP and L1 I want to do  something like turning a led, but actually my code works like this.. I press only one time L1 and y=true, if I press UP the led turns on every time I press UP, if I press both led turns on (that's what I want), how can I fix that problem? I tried to enter several loops there without success

Code: Select all
/*
 # Editor : Phoebe
 # Date   : 2014.11.6
 # Ver    : 0.1
 # Product: Devastator Tank Mobile Platform
 # SKU    : RBO0112
 # Description:    
 # Connect the D4,D5,D6,D7,GND to UNO digital 4,5,6,7,GND
 
*/
  
int E1 = 5;     //M1 Speed Control
int E2 = 6;     //M2 Speed Control
int M1 = 13;     //M1 Direction Control
int M2 = 7;     //M1 Direction Control
char val;
boolean y=false;
boolean x=false;
boolean z=false;
 
void stop(void)                    //Stop
{
   
  digitalWrite(M1,LOW);   
  
}  
void advance(void)         //Move forward
{
  x=true;
  if (z==true)
 { 
   if (x==true && y==true)
   {
     digitalWrite(M1,HIGH); 
     delay(450);
      
      
  }
  else
  {
    x=false;
    y=false;
    z=false;
}


}
}
void back_off  (void)         //Move backward
{
      y=true;
  
  if (y && x)
  {
    z=true;
  }
  else if (y && !x)
  {
    z=false;
    y=false;
  }
    else if (x && !y)
  {
    z=false;
    x=false;
  }




 
}
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<=13;i++)
    pinMode(i, OUTPUT); 
  Serial.begin(9600);      //Set Baud Rate

  digitalWrite(E1,LOW);  
  digitalWrite(E2,LOW);
 
}

void serial (void)
{
      switch(val)
      {
      case 'UP'://Move Forward
        advance ();  //move forward in max speed
        break;
      case 'L1'://Move Backward
        back_off () ;  //move back in max speed
        break;
      case 'BACK'://Turn Left
        turn_L (100,100);    
        break;      
      case 'US'://Turn Right
        turn_R (100,100);
        break;
      case 'v':
        break;
      default:
        stop();
      }
}

void loop()
{
  if(Serial.available())
  {
    val = Serial.read();
    serial();
  }
}
  
   
 
userHeadPic rodrrigo91
2015-01-27 05:15:36 yes but I have problems reading data in the receiver by serial using xbee userHeadPic rodrrigo91
2015-01-27 05:15:36 yes but I have problems reading data in the receiver by serial using xbee userHeadPic rodrrigo91
2015-01-26 18:05:45 Hello rodrrigo91,

You mean the joystick value?  or just button value? Have you check the product wiki?
http://www.dfrobot.com/wiki/index.php/W ... U:DFR0182)
Although it is not very good, but it should work. Have you read the analog data?
userHeadPic Grey.CC
2015-01-26 18:05:45 Hello rodrrigo91,

You mean the joystick value?  or just button value? Have you check the product wiki?
http://www.dfrobot.com/wiki/index.php/W ... U:DFR0182)
Although it is not very good, but it should work. Have you read the analog data?
userHeadPic Grey.CC
2015-01-25 02:17:52 I'm trying to recognize the values in the receiver but I can´t find the way to read analog values and characters, It throw me away this data.

UP,DOWN,
500,500,500,500 for example... I need to read those analog, can someone help me?
userHeadPic rodrrigo91