Pages: [1]   Go Down
Author Topic: Unexpected values - Xbee Problem.  (Read 261 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:


#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);


}


Logged

Pages: [1]   Go Up
Jump to: