I’m using xbee s2 to send a 4 sensors data form one a arduino to another
but my receiver code had a problem
transmit code
// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include “I2Cdev.h”
#include “MPU6050.h”
// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
#define LED_PIN 13
bool blinkState = false;
int f2 = A1; //analog pin 0
int f1=A0;
char s_str1[9];
char s_str2[9];
char s_str3[9];
char s_str4[9];
String str1,str2,str3,str4;
void setup(){
// join I2C bus (I2Cdev library doesn’t do this automatically)
Wire.begin();
// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it's really up to you depending on your project)
Serial.begin(9600);
// initialize device
Serial.println("Initializing I2C devices...");
accelgyro.initialize();
// verify connection
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
// configure Arduino LED for
}
void loop(){
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
int flex1 = analogRead(f1);
int flex2 = analogRead(f2);
int flex11= map(flex1, 225, 279, 180, 0);
int flex12 = map(flex2, 225, 279, 180, 0);
int vro = map(ay, -16000, 16000, 0, 179);
int vba=map(ax, -16000, 16000, 0, 179);
int flex112=constrain(flex11,0,180);
int flex122=constrain(flex12,0,180);
int vro2=constrain(vro,0,180);
int vba2=constrain(vba,0,180);
// read raw accel/gyro measurements from device
// Indicates the start of the message (e=motors, s=robot arm)
Serial.print(“z”);Serial.print(vro2); Serial.print("
");// Pinky
delay(30);
Serial.print(“s”);Serial.print(vba); Serial.print("
“);// Pinky
delay(30);
Serial.print(“y”);Serial.print(flex112); Serial.print(”
");// Pinky
delay(30);
Serial.print(“w”);Serial.print(flex122); Serial.print("
");// Pinky
delay(30);
Serial.flush();
Serial.flush();
}
Receiver code
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>=21)
{
if (Serial.find(“z”))
{
int y=Serial.parseInt();
Serial.print(y);Serial.print("
“);
}
if (Serial.find(“s”))
{
int r=Serial.parseInt();
Serial.print(r);Serial.print(”
");
}
delay(20);
}}
i’m a beginner an i’m about to graduated
please what is the problem ?