multi analog data from 1 arduino to another arduino

Hey,

I need to make a drone for school. and I use it for two Arduino controller and reciever (connection with Xbee). My question is how can i 3 analog signals from one to another arduino arduino send and then use that data for the motors?

void Besturing()
{
Power = analogRead(Speed); // Hier lees je de potentiometer in die de snelheid zal bepalen en de waarden zal gebruikt worden met de variabelen Power.
Power = map(Power,0,1023,153,220); // Schaal aanpassen om de variabelen Power te kunnen gebruiken als PWM waarden.

ValX = analogRead(Xcoord); // Hier lees je de Xcoordinaten in en de waarde zal gebruikt worden met de variabelen ValY.
ValX = map(ValX,20,1000,-20,20); // Schaal aanpassen om een verschil te hebben tussen links en rechts en om als PWM te kunnen gebruiken.

ValY = analogRead(Ycoord); // Hier lees je de Ycoordinaten in en de waarde zal gebruikt worden met de variabelen ValY.
ValY = map(ValY,20,1000,-20,20); // Schaal aanpassen om een verschil te hebben tussen voorwaarts en achterwaarts en om als PWM te kunnen gebruiken.

int PWM1 = (Power - ValY + ValX + 10); // Hier gaan we al onze PWM waardes optellen voor Motor1.
int PWM2 = (Power - ValY - ValX); // Hier gaan we al onze PWM waardes optellen voor Motor2.
int PWM3 = (Power + ValY - ValX); // Hier gaan we al onze PWM waardes optellen voor Motor3.
int PWM4 = (Power + ValY + ValX); // Hier gaan we al onze PWM waardes optellen voor Motor4.
// Hier gaan we onze motors het PWM signaal laten gebruiken voor de snelheid te regelen.
analogWrite(Motor1,PWM1); // Motor1 gebruikt PWM1.
analogWrite(Motor2,PWM2); // Motor2 gebruikt PWM2.
analogWrite(Motor3,PWM3); // Motor3 gebruikt PWM3.
analogWrite(Motor4,PWM4); // Motor4 gebruikt PWM4.

}
help me plz !!!!

do analogRead on one side, returns a 10 bit value.
Divide by 4 get an 8-bit value.
Serial.write that value to xbee.

On receive side, read the value from xbee.
analogWrite the 8-bit value on one of the pins 3,5,6,9,10,11 to output PWM to control motor speed.

thx but can i send more than 1 analog value with Serial.write ?

Serial.write() lets you send a byte stream. You can put any data you like on that byte stream - just be aware that the receiver will need to do the same thing in reverse to extract the data from the incoming byte stream so you should choose an encoding scheme that makes this easy for the receiver.

Sure, say your data was in an array:

for (x=0; x<4; x=x+1){
Serial.Write(analogData[0] );
}

Sends out 4 bytes.

Sends out 4 bytes.

But, it's the same byte 4 times.

Yeah, little typo there, s/b:

Serial.Write(analogData[x] );

CrossRoads:
Yeah, little typo there, s/b:

Serial.Write(analogData[x] );

Are you sure?

I'd have tried Serial.write(), myself.

Dang, 2 errors in the same line of code! I'm not usually that bad.

CrossRoads:
I'm not usually that bad.

Sometimes, I'm even worse... 8)

My question is how can i 3 analog signals from one to another arduino arduino send and then use that data for the motors?

I suggest you work on the receiving code first, making code that is easy to decode the incoming data stream. The receiving code below is for servo, but demonstrates receiving a numeric value with a component identifier, followed by a data packet delimiter. The sending code can be easily formatted in this manner.

//zoomkat 11-22-12 simple delimited ',' string parse 
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added 

String readString;
#include <Servo.h> 
Servo myservoa, myservob, myservoc, myservod;  // create servo object to control a servo 

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

  //myservoa.writeMicroseconds(1500); //set initial servo position if desired

  myservoa.attach(6);  //the pin for the servoa control
  myservob.attach(7);  //the pin for the servob control
  myservoc.attach(8);  //the pin for the servoc control
  myservod.attach(9);  //the pin for the servod control 
  Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}

void loop() {

  //expect single strings like 700a, or 1500c, or 2000d,
  //or like 30c, or 90a, or 180d,
  //or combined like 30c,180b,70a,120d,

  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c == ',') {
      if (readString.length() >1) {
        Serial.println(readString); //prints string to serial port out

        int n = readString.toInt();  //convert readString into a number

        // auto select appropriate value, copied from someone elses code.
        if(n >= 500)
        {
          Serial.print("writing Microseconds: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
          if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
          if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
          if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
        }
        else
        {   
          Serial.print("writing Angle: ");
          Serial.println(n);
          if(readString.indexOf('a') >0) myservoa.write(n);
          if(readString.indexOf('b') >0) myservob.write(n);
          if(readString.indexOf('c') >0) myservoc.write(n);
          if(readString.indexOf('d') >0) myservod.write(n);
        }
         readString=""; //clears variable for new input
      }
    }  
    else {     
      readString += c; //makes the string readString
    }
  }
}

thank you for the help i hope i wil find it now :smiley: