Go Down

Topic: Solved :!!!Need guidance/help with final step of project with xbee serie 1. (Read 3091 times) previous topic - next topic

Fabiolus

Good day,

I have started a project a while back and decided to add extra to it by making it wireless, basically a remote control bot.

I have been reading and playing around trying to configure the xbees and failed. I would like if possible to transfer analog signal from transmitter to receiver. I have been looking at the API mode which seem to be easy but I might be wrong.

I have 2 xbees series 1
2 Arduino Uno
1 Joystick
2 explorer adaptor


The remote control is a simple plastic box holding an Arduino Uno, a switch, breadboard, batterie and joystick. The Arduino transmiter capture the Analog signal X&Y from joystick send to xbee conected to Arduino  and the signal is then captured by the xbee receiver sending the 2 analog signal to the sketch in Arduino ouptut it from PWM pins from Arduino to motors. The Arduino in the remote control is because I will be adding other features to the remote control in the future. The Arduino in the remote control help regulate voltage at the same time, fed with a 9 volts batterie.

The receiver would have the same setup inside a plastic box an Arduino Uno, xbee serie 1, switch. The receiver would read the analog signal from the xbee and send to pin A0&A1 then the sketch in Arduino would have the output out from PWM pins to motors.



I have built a very simple sketch capturing the signal, Should both Arduino be running the same sketch? Is it feasable to pass analog signal to xbee receiver and having xbee receiver capturing and outputing the analog signal to another Arduino?

For setting up the xbee maybe there is a simplier method? Or exactly how to configure them? Any advice would be greatly appreciated.

http://www.youtube.com/watch?v=bctfzcdU06g&feature=share&list=UU2cRVtkEbdUHeXSHHRO6rig



Code: [Select]
/*

Hardware:
- Arduino Uno
- Sabertooth 25 Dual 25A Motor Driver;kl
- 1 Mini Thumb Joystick
- 2 dc motors (using servo library since Sabertooth seem to only accept for R/C or micro controller control
- the joystick#1 up/down  control forward backaward/ left/right

Features:
- Move 2 motors using one Joystick Independently

The circuit:
- First motor signal out PWM pin 10 to sabertooth S2
- Second motor signal out PWM pin 3 to sabertooth S1
- Joystick1 X angle attached to analog pins A0
- Joystick1 Y angle attached to analog pins A1
Discontinued - Joystick2 X angle attached to analog pins A2
Discontinued - Joystick2 Y angle attached to analog pins A3

Author:
Fabiolus
sabertooth switch
1= down
2= up
3= up
4= up if this switch is up it changes the S2 motor and S1 making it easy to steer one goes
\ forward the other goes backward, you can apply to joystick#2 and #1 for backward/forward
5= down
6= down

*/

#include <Servo.h>

const int joyX1 = A0;        // Joystick 1 X Axis
const int joyY1 = A1;        // Joystick 1 Y Axis
//const int joyX2 = A2;        // Joystick 2 X Axis
//const int joyY2 = A3;        // Joystick 2 y Axis

int servoVal;      
int servoVal2;

Servo ST1, ST2;


void setup() {

 // Servo
 ST1.attach( 6, 1000, 2000);
 ST2.attach(5, 1000, 2000);

 // Inizialize Serial
 Serial.begin(9600);
}


void loop(){

   // Display Joystick values using the serial monitor
   outputJoystick();

   // Read the X joystick value  (value between 0 and 1023)
   servoVal = analogRead(joyX1);
   servoVal = map(servoVal, 0, 1023, 0, 180);     // scale it to use it with the servo (result  between 0 and 180)

   ST1.write(servoVal);                       // sets the servo position according to the scaled value

   // Read the Y joystick value  (value between 0 and 1023)
   servoVal2 = analogRead(joyY1);
   servoVal2 = map(servoVal2, 0, 1023, 0, 180);     // scale it to use it with the servo (result between 70 and 180)

   ST2.write(servoVal2);                          // sets the servo position according to the scaled value

   delay(15);                                     // waits for the servo to get there

}


/**
* Display joystick values for testing
*/
//void outputJoystick(){

  //Serial.print(analogRead(joyX1));
//   Serial.print ("---");
   //Serial.print(analogRead(joyX2));
//    Serial.println ("----------------");    
  // Serial.print(servoVal2);
//}

void GoForward (){
 
 
}

strykeroz

Hi

That looks like a heap of fun :)

There's no need for both Arduinos to be running the same code since one won't need to deal with motors and the other one doesn't need to deal directly with the controls.  You will be sending the values read from analogRead() functions on the thumbstick over the bee, so the Arduino at the vehicle end will be receiving values between 0 and 1023 rather than an analog signal.

Cheers !
Geoff
"There is no problem so bad you can't make it worse" - retired astronaut Chris Hadfield

Fabiolus

#2
Aug 04, 2013, 08:28 pm Last Edit: Aug 04, 2013, 09:02 pm by Fabiolus Reason: 1
Geoff,


Thanks for the encouragement. It turns out I was way off.

I strongly suggest to get the book Arduino Cookbook version 2 from Michael Margolis.

For Series 1 To have them communicated as a basic test.



Have 2 Xbees Series 1
2 USB Explorer board from Sparkun or equivalent
X-CTU and CoolTerm (This is what Ive missed)


Plug 1 xbee to usb port and launch Cool Term, go to options then do rescan and make sure to select correct port.
in Serial Port select baud Rate 9600 Data Bits 8 Parity None Stop Bits 1 THEN Click Terminal Terminal mode Raw Mode Enter Key Emulation CR+LF click ok.

Click Connect then enter these commands in terminal screen.

You will need to type +++ and wait a second to get the XBee's attention (it will respond
with "OK"):

Transmitor
ATRE {ENTER}
ATMY1234 {ENTER}
ATDL5678 {ENTER}
ATDH0 {ENTER}
ATID0 {ENTER}
ATD02 {ENTER}
ATIR64 {ENTER}
ATWR

Click disconnect

Do same thing for second xbee but enter these commands


You will need to type +++ and wait a second to get the XBee's attention (it will respond
with "OK"):

Receiver
ATRE {ENTER}
ATMY5678 {ENTER}
ATDL1234 {ENTER}
ATDH0 {ENTER}
ATID0 {ENTER}
ATWR {ENTER}

Now close CoolTerm.


keep only one xbee plug in and launch X-CTU. Go to Modem Configuration and click Read THEN make sure to use latest firmware, at the same time identify your PAN ID e.g: 6669 for both xbees (See screenshots). Now plug the second Xbee and open second instance of X-CTU select second xbee go to Modem Configuration click read, make sure same firmware is displayed by comparing first and second instance of X-CTU then put smae PAN iD.

On both instance of X-CTU click terminal, now whatever you type should appear on the other terminal, vis versa





Fabiolus

Well,

I am going to coontinue posting my progress, might come handy to another Arduinoerer.

I have put my program asside and uploaded a different sketch to test the wireless connection. So far the first test show that there is an analog signal being passed to the xbee receiving and sending to Arduino to convert to digital ouput. The Arduino receiving has a sketch that mapp values 0,1023 to 0, 255 for digital output for the LED.

NOTE: I am using the usb explorer board from sparkfun, even though it offers 5 volts input I am not using it because I want to use pin Vref from the xbees and I believe that it would burn the board if you connected Vref directly to 5 volts pin.


Now that the test is successful I will have to program the xbee transmitter to read 2 analog signal X&Y and do the same for the receiver and review my original program and leverage the second sketch to communicate both analog signals.

The settings are for xbees series 1

ref: http://youtu.be/QyTZFo40EMg

Transmitter xbee settings

ATRE
ATMY1234
ATDL5678
ATDH0
ATID0
ATD02
ATIR64
ATWR

Receiver xbee settings:

ATRE
ATMY5678
ATDL1234
ATDH0
ATID0
ATWR


Sketch in Arduino receiving.

Code: [Select]
/*
XBeeAnalogReceiveSeries1
Read an analog value from an XBee API frame and set the brightness
of an LED accordingly.
*/
const int ledPin = 9;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
configureRadio(); // check the return value if you need error handling
}
boolean configureRadio() {
// put the radio in command mode:
Serial.flush();
Serial.print("+++");
delay(100);
String ok_response = "OK\r"; // the response we expect.
// Read the text of the response into the response variable
String response = String("");
while (response.length() < ok_response.length()) {
if (Serial.available() > 0) {
response += (char) Serial.read();
}
}
// If we got the right response, configure the radio and return true.
if (response.equals(ok_response)) {
Serial.print("ATAP1\r"); // Enter API mode
delay(100);
Serial.print("ATCN\r"); // back to data mode
return true;
} else {
return false; // This indicates the response was incorrect.
}
}
void loop() {
  if (Serial.available() >= 14) { // Wait until we have a mouthful of data
if (Serial.read() == 0x7E) { // Start delimiter of a frame
// Skip over the bytes in the API frame we don't care about
for (int i = 0; i < 10; i++) {
Serial.read();
}
// The next two bytes are the high and low bytes of the sensor reading
int analogHigh = Serial.read();
int analogLow = Serial.read();
int analogValue = analogLow + (analogHigh * 256);
// Scale the brightness to the Arduino PWM range
int brightness = map(analogValue, 0, 1023, 0, 255);
// Light the LED
analogWrite(ledPin, brightness);
}
}
}


Fabiolus

#4
Aug 06, 2013, 12:53 am Last Edit: Aug 07, 2013, 06:54 pm by Fabiolus Reason: 1
Making progress a little,


I managed to control the motors for a first test. I still need to figure out how to setup the xbee transmitter to have 2 input analog pin, right now I only have pin 20 enabled on xbee.

anyone is welcomed to clean up the code a little, or feedback on how I could include another signal to complete capture of both X&Y signal and send wirelessly.

http://youtu.be/7TFGah-UunM

Transmitter xbee series 1 settings

ATRE
ATMY1234
ATDL5678
ATDH0
ATID0
ATD02
ATIR64
ATWR

Receiver xbee series 1 settings:

ATRE
ATMY5678
ATDL1234
ATDH0
ATID0
ATWR






Code: [Select]
/*
XBeeAnalogReceiveSeries1
Read an analog value from an XBee API frame and set the brightness
of an LED accordingly.
*/

#include <Servo.h>

int servoVal;      
int servoVal2;


Servo ST1, ST2;


void setup() {

 // Servo
 ST1.attach( 6, 1000, 2000);
 ST2.attach(5, 1000, 2000);  
 
Serial.begin(9600);
configureRadio(); // check the return value if you need error handling
}

boolean configureRadio() {
// put the radio in command mode:
Serial.flush();
Serial.print("+++");
delay(100);
String ok_response = "OK\r"; // the response we expect.
// Read the text of the response into the response variable
String response = String("");
while (response.length() < ok_response.length()) {
if (Serial.available() > 0) {
response += (char) Serial.read();
}
}
// If we got the right response, configure the radio and return true.
if (response.equals(ok_response)) {
Serial.print("ATAP1\r"); // Enter API mode
delay(100);
Serial.print("ATCN\r"); // back to data mode
return true;
} else {
return false; // This indicates the response was incorrect.
}
}
void loop() {
 

 
 
 if (Serial.available() >= 14) { // Wait until we have a mouthful of data
if (Serial.read() == 0x7E) { // Start delimiter of a frame
// Skip over the bytes in the API frame we don't care about
for (int i = 0; i < 10; i++) {
Serial.read();
}
// The next two bytes are the high and low bytes of the sensor reading
int analogHigh = Serial.read();
int analogLow = Serial.read();

int analogValue = analogLow + (analogHigh * 256);
servoVal = map(analogValue, 0, 1023, 0, 180);     // scale it to use it with the servo (result  between 0 and 180)

ST1.write(servoVal);                       // sets the servo position according to the scaled value  
}
}
}

Fabiolus

Good day,


Finally after many obstacles, faulty wires, wrong code etc... success :smiley-mr-green:.


I present to you communication between 2 arduinos with xbees series 1 with1 joystick passing analog X&Y to other arduino via xbees wireless!!!! All using the EasyTransfer library from Bill Porter http://www.billporter.info/2011/05/30/easytransfer-arduino-library/

This sketch or method can be applied to many different project or other similar controlled bots with minimal coding expertise. I have search and red many books and none come even close to what you are about to see.

I hope you enjoy building your robots and making them controlled wireless.

Pre requisite:

2 xbees series 1 default settings(Out of the box!!) are ok but if you wish you can change the pan id but that is it!!!
1 joystick thumb joystick from ladyaya or equivalent 2 seperate joystick would work.

the way the sketch work you could have a mega arduino and include as much motors/servos/joystick/ button that you wish!!! have fun!!


2 arduino uno board
2 dc motors or servos
9 volts batterie
12/24 volts batterie


http://youtu.be/G-qAB9MzrPU


Please refer to schematic for wiring


Remote control Arduino sketch

Code: [Select]
#include <EasyTransfer.h>
EasyTransfer ET;

const int potpin1 = A0;
const int potpin2 = A1;

struct SEND_DATA_STRUCTURE{
int servo1val;
int servo2val;
};

SEND_DATA_STRUCTURE txdata;

void setup(){
  Serial.begin(9600);
  //  Serial.begin(115200);
  ET.begin(details(txdata), &Serial);
}

void loop(){

  int val1 = analogRead(potpin1);
  int val2 = analogRead(potpin2);
  val1 = map(val1, 0, 1023, 0, 180);
  val2 = map(val2, 0, 1023, 0, 180);
  txdata.servo1val = val1;
  txdata.servo2val = val2;

  ET.sendData();
}


robot Arduino receiving

Code: [Select]

#include <Servo.h>
#include <EasyTransfer.h>
EasyTransfer ET;

Servo myservo1;
Servo myservo2;

Servo ST1, ST2;

struct RECEIVE_DATA_STRUCTURE{
  int servo1val;
  int servo2val;
};

RECEIVE_DATA_STRUCTURE txdata;

void setup(){
  Serial.begin(9600);
  // Serial.begin(115200);

  ET.begin(details(txdata), &Serial);
  // Servo
  ST1.attach( 6, 1000, 2000);
  ST2.attach(5, 1000, 2000);
}

void loop(){
  if(ET.receiveData()){
    ST1.write(txdata.servo1val);
    ST2.write(txdata.servo2val);
  }
}




Go Up