Pages: [1]   Go Down
Author Topic: help me in EasyTransfer Library  (Read 1343 times)
0 Members and 1 Guest are viewing this topic.
Egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello arduino members plz i need to control 2 servos with 2 potentiometers wireless by 2 arduino & Xbee modules , i had EasyTransfer library to make it but i faced a problem with the example code because the code designed to control 1 servo with 1 pot & i tried to modify it but in vain because i can't find any Definition of the pot in this code like : int potpin = 0 , val = analogRead(potpin) ........ so plz help - See the code

Code:
/*This is an example of the EasyTransfer Library 2way communications.

This sketch is for the Arduino with the servo attached to pin 9.

The other Arduino has a potentiometer attached to analog pin 0.
Both have a putton attached to pin 12 and output a status using the LED on pin 13.

The idea is each arduino will read the status of the button attached to it, and send it
to the other Arduino, which will toggle it's LED based on the others button. The button
should connect pin 12 to ground when pushed.

And the Arduino with the potentiometer will send it's value to the one with the servo.
The servo will move to the position based on the potentiometer.
*/

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

//create two objects
EasyTransfer ETin, ETout;
//create servo
Servo myservo;

struct RECEIVE_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to receive
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int buttonstate;
  int servoval;
};

struct SEND_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to receive
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int buttonstate;
};


//give a name to the group of data
RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;


void setup(){
  Serial.begin(9600);
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);
 
  pinMode(13, OUTPUT); 
  pinMode(12, INPUT);
  //enable pull-up
  digitalWrite(12, HIGH);
 
  myservo.attach(9);
}

void loop(){
 
  //first, lets read our button and store it in our data structure
  if(!digitalRead(12))
    txdata.buttonstate = HIGH;
  else
    txdata.buttonstate = LOW;
 
 //then we will go ahead and send that data out
  ETout.sendData();
 
 //there's a loop here so that we run the recieve function more often then the
 //transmit function. This is important due to the slight differences in
 //the clock speed of different Arduinos. If we didn't do this, messages
 //would build up in the buffer and appear to cause a delay.
 
  for(int i=0; i<5; i++){
    //remember, you could use an if() here to check for new data, this time it's not needed.
    ETin.receiveData();
   
    //set our LED on or off based on what we received from the other Arduino
    digitalWrite(13, rxdata.buttonstate);
   
    //set our servo position based on what we received from the other Arduino
    //we will also map the ADC value to a servo value
    myservo.write(map(rxdata.servoval, 0, 1023, 0, 179));
   
    //delay
    delay(10);
  }
 
  //delay for good measure
  delay(10);
}

cheers
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
because the code designed to control 1 servo with 1 pot
No. It is designed to send one packet containing two ints.

It does not matter what those two ints represent. They could be two potentiometer values, two sensor values, two switch states, or two random numbers.

Of course, you can change the number of ints in the structure, or add other variable types.
Logged

Egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for ur interest , see these modification & tell me if it true


Code:
#include <Servo.h>
#include <EasyTransfer.h>

EasyTransfer ETin, ETout;

Servo myservo ;
Servo myservo2 ;

struct RECEIVE_DATA_STRUCTURE{
 
  int servoval;
  int servoval2;
 
};

struct SEND_DATA_STRUCTURE{
 
  int servoval;
  int servoval2;
};


RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;


void setup(){
  Serial.begin(9600);
  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);
 
  myservo.attach(9);
  myservo2.attach(10);
}

void loop(){
 
  txdata.servoval = analogRead(0);
  txdata.servoval2 = analogRead(1);
 
  ETout.sendData();
 
 
  for(int i=0; i<5; i++){
   
    ETin.receiveData();
   
    myservo.write(map(rxdata.servoval, 0, 1023, 0, 179));
    myservo2.write(map(rxdata.servoval2, 0, 1023, 0, 179));
 
    delay(10);
  }
 
  delay(10);
}

cheers
« Last Edit: May 05, 2012, 09:30:12 am by amr_hamed » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Servo myservo ;
Servo myservo2 ;
When you are counting servos, do you count "Yes, that is a servo, 2, 3..." or do you count "1, 2, 3..."?

Code:
  if(!digitalRead(12))
    txdata.buttonstate = HIGH;
  else
    txdata.buttonstate = LOW;
The digitalRead() function does not return a boolean value. You should not write code whose intent is not clear. There should be no reason to think about whether HIGH or LOW is true, and the effect of negating that. Use
Code:
if(digitalRead(12) == HIGH)
{
}
else
{
}
and put the correct actions in the correct blocks.

What happens when you execute that code?
Logged

Egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

see the code again because i have removed the button case becasue i don't need it

best - amr
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46026
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
see the code again because i have removed the button case becasue i don't need it
Don't do that. If you modify the code, post it again.

Answer all the questions, if you need help.
Logged

Egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry  smiley-slim this the code again , i didn't try the code yet because i didn't get the xbee modules yet but i am waiting for it , i am doing that to be ready when the modules comes

Code:
#include <Servo.h>
#include <EasyTransfer.h>

EasyTransfer ETin, ETout;

Servo myservo ;
Servo myservo2 ;

struct RECEIVE_DATA_STRUCTURE{
 
  int servoval;
  int servoval2;
 
};

struct SEND_DATA_STRUCTURE{
 
  int servoval;
  int servoval2;
};


RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;


void setup(){
  Serial.begin(9600);
  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);
 
  myservo.attach(9);
  myservo2.attach(10);
}

void loop(){
 
  txdata.servoval = analogRead(0);
  txdata.servoval2 = analogRead(1);
 
  ETout.sendData();
 
 
  for(int i=0; i<5; i++){
   
    ETin.receiveData();
   
    myservo.write(map(rxdata.servoval, 0, 1023, 0, 179));
    myservo2.write(map(rxdata.servoval2, 0, 1023, 0, 179));
 
    delay(10);
  }
 
  delay(10);
}

Cheers
Logged

Egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello every body i need help smiley
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello every body i need help smiley
With what? Your last post was "here is the code, but I haven't tried it yet."

If you wan't help, you're going to have to try the code first and then report back any problems you have.
Logged

Egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for reply i will try it but , i need u to confirm that i will upload this code in the 2 arduinos with the 2 Xbees

sincerely
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for reply i will try it but , i need u to confirm that i will upload this code in the 2 arduinos with the 2 Xbees

sincerely
You have my permission to upload your code to your Arduino.
Logged

Pages: [1]   Go Up
Jump to: