Go Down

Topic: Unexpected values - Xbee Problem. (Read 320 times) previous topic - next topic

dave13

Hello everyone,

I am working on a project in which I acquire some information with Arduino. This data is send to other Xbee module.

The point is that I should receive something like this :

.xv -0.04
.yv -0.19
.zv -1.00

On a Loop , where the values after the chars 'xv', 'yv' and 'zv' are the values from the accelerometer.

It works fine but sometimes I receive unexpected values, as for example:

.xv -0.04
.yv -0.19
.zv -1.00

.xv -0.04
.yv -0..zv -1.00
.zv -1.00
.xv -0.yv -0.19
.zv -1.00
.xv -0.04
.yv -0.19
.zv .xv -0.04...


I assume that for some reason I don't receive my data well but I don't know why.
I tried to put some delays after every Serial.print but it won't work.

I attach you a simple program which I am doing the probes.


Code: [Select]



#define ADC_ref 3.3

#define zero_x 1.65

#define zero_y 1.65

#define zero_z 1.65

#define sensitivity_x 0.3

#define sensitivity_y 0.3

#define sensitivity_z 0.3

unsigned int value_x;
unsigned int value_y;
unsigned int value_z;

float xv;
float yv;
float zv;

void setup()   {



  Serial.begin(9600);

}

void loop() {

  value_x = analogRead(2);
  value_y = analogRead(1);
  value_z = analogRead(0);

  xv=(value_x/1024.0*ADC_ref-zero_x)/sensitivity_x;
  yv=(value_y/1024.0*ADC_ref-zero_y)/sensitivity_y;
  zv=(value_z/1024.0*ADC_ref-zero_z)/sensitivity_z;

  Serial.print("xv ");
  if (xv>=0){
    Serial.print("+"); 
  };
  Serial.println(xv);
  Serial.print("yv ");
  if (yv>=0){
    Serial.print("+"); 
  };
  Serial.println(yv);
  Serial.print("zv ");
  if (zv>=0){
    Serial.print("+"); 
  };
  Serial.println(zv);


  delay(20);


}



Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy