adxl335 and xbee!!!

XBee projects like the adapter, xBee tutorials, tweetawatt/wattcher, etc. from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
daremots
 
Posts: 12
Joined: Sun Aug 08, 2010 9:48 pm

adxl335 and xbee!!!

Post by daremots »

Hey,
I have been facing some problem with my project, the project is about receiving values captured by the adxl335 accelerometer and sending via zbee transmitter to ma mac.

The problem i am facing is that , when i transmit the values , n try to display it in the serial monitor , the values are getting limited between 55,50,51,40....much of the time its showing 50 and 55, even though i try to move the accelerometer as fast as possible.
I am totally new to arduino , and more over this is my 1st post. My code must be the simplest you have ever seen , i am posting this cos i have no one to clear this thing for me , and that i need to get this done .

Transmitter code: [edit - moderator - to use code boxes]

Code: Select all

#include <NewSoftSerial.h>


NewSoftSerial xbee(9,8);
const int xpin = 0; // x-axis of the accelerometer
const int ypin = 1; // y-axis
const int zpin = 2; // z-axis (only on 3-axis models)
unsigned int tot,data_tx;

void setup()
{
// initialize the serial communications:
Serial.begin(9600);
xbee.begin(9600);
}

void loop()
{

data_tx = analogRead(xpin);

xbee.print(data_tx);

// delay before next reading:
delay(400);
} 
Receiver code:

Code: Select all

#include <NewSoftSerial.h>


NewSoftSerial xbee2(9,8);


void setup()
{
// initialize the serial communications:
Serial.begin(9600);
xbee2.begin(9600);
}

void loop()
{

if(xbee2.available() )
{
Serial.println(xbee2.read());
Serial.print("is rxvd");
Serial.print("\n");
}

// delay before next reading:
delay(400);
} 
Hope some one could help me figure out what changes i should make in my code to fix this problem .

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: adxl335 and xbee!!!

Post by adafruit_support_bill »

Can you post a sample of the actual output? Sounds like you are probably seeing the ASCII value if the individual digits from the readings. 48 = '0', 57 = '9'

daremots
 
Posts: 12
Joined: Sun Aug 08, 2010 9:48 pm

Re: adxl335 and xbee!!!

Post by daremots »

the values are : 52,48,51 ( for 5 times), then it became 57,55,52,49,54..etc..those vales kept on repeating.

and really sorry for posting this twice .

daremots
 
Posts: 12
Joined: Sun Aug 08, 2010 9:48 pm

Re: adxl335 and xbee!!!

Post by daremots »

and the serial monitor still shows readings even when i pulled off the power supply from the transmitting side.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: adxl335 and xbee!!!

Post by adafruit_support_bill »

Strange. Those numbers looks suspiciosly like ASCII digits. But I don't know why they would continue with no power to the transmitter:

52,48,51 ( for 5 times) would be:

403403403403403

57,55,52,49,54... repeating would be:

9742697426974269742697426

Instead of reading the analog value, try sending a known value from the transmitter side. Once you get the communication debugged, then you can go back to the sensor data.

Code: Select all

void loop()
{

data_tx = 100;   //// a known value

xbee.print(data_tx);

// delay before next reading:
delay(400);
} 

daremots
 
Posts: 12
Joined: Sun Aug 08, 2010 9:48 pm

Re: adxl335 and xbee!!!

Post by daremots »

Hey you where right, i was receiving the decimal values of the values that where transmitted. Well i read through another forum and found that this guy was having kind of the same problem and they have mentioned how to fix that.

This is the link :

http://www.arduino.cc/cgi-bin/yabb2/YaB ... 53899085/3

I used the atoi ().

Well now i am having another problem, its that when i sent 3 values, the x,y and z axis values, this is what i am gettin in ma serial monitor:



4
0
4
x value = 4043
4
7
y value = 3473
4
0
z value = 340is rxvd

4
0
4
x value = -188923
4
7
y value = -307923
4
0
z value = 340is rxvd

4
0
4
x value = -188923
4
7
y value = -307923
4
0
z value = 340is rxvd

4
0
5
x value = -88923
4
7
y value = 34743
4
0
z value = 340is rxvd

some how the z values are getting diplayed correct , bt the x and y values are messed up.

It will be really helpfull if you could help me fix the problem...:)
tc

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: adxl335 and xbee!!!

Post by adafruit_support_bill »

Can you post the code for that?

daremots
 
Posts: 12
Joined: Sun Aug 08, 2010 9:48 pm

Re: adxl335 and xbee!!!

Post by daremots »

(Edit - moderator - to use code box)

Code: Select all

#include <NewSoftSerial.h>
NewSoftSerial xbee2(9,8);
char x[2],y[2],z[2];
int  n1,n2,n3;

void setup()
{
  // initialize the serial communications:
  Serial.begin(9600);
  xbee2.begin(9600);
}

void loop()
{

  if(xbee2.available() )
  {
    Serial.flush();  // clearing all the values in buffer
    // x values
    for(int i=0;i<3;i++)
     {
      x[i]= xbee2.read();
      Serial.println(x[i]);
     }
    
    n1 = atoi(x);
    Serial.print("x value = ");
    Serial.print(n1);
    
    // y values
    Serial.flush();
    for(int i=0;i<3;i++)
     {
      y[i]= xbee2.read();
      Serial.println(y[i]);
     }
    
    n2 = atoi(y);
    Serial.print("y value = ");
    Serial.print(n2);
    
    // z values
    for(int i=0;i<3;i++)
     {
      z[i]= xbee2.read();
      Serial.println(z[i]);
     }
    
    n3 = atoi(z);
    Serial.print("z value = ");
    Serial.print(n3);
    
    Serial.flush();   // clearing all the values in buffer
    
  }
    
  Serial.println("is rxvd");
  Serial.print("\n");
  // delay before next reading:
  delay(400);
}

Davhydes
 
Posts: 2
Joined: Mon Feb 06, 2012 4:03 am

Re: adxl335 and xbee!!!

Post by Davhydes »

Hello,
I have exactly the same problem than daremots.

Is there a solution to this problem?

Thank you :)

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: adxl335 and xbee!!!

Post by adafruit_support_bill »

I see 2 potential problems with the code:

Serial.read() will return a -1 if there are no characters available. You need to test Serial.available() to see if there is anything to read.
Serial.flush() will flush any characters in the input buffer - causing you to lose data.

Update: that description of Serial.flush() only applies to IDE version prior to 1.0.

Davhydes
 
Posts: 2
Joined: Mon Feb 06, 2012 4:03 am

Re: adxl335 and xbee!!!

Post by Davhydes »

Thank you for your answer.

I think the problem is that values of ADXL335 are written as follow:

265 280 320
266 280 319
etc...

So I don't know how to get these 3 values on the Receiver Arduino.
Serial.read only reads 2, then 6, then 5, then [space], ... and translate into ASCII.

I saw a lot of questions about this topic on several forums but I'm very new to the programming field and I didn't see a convenient answer for me (moreover I'm french :?).

I would be very very happy if you could help me :)

Thank you

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: adxl335 and xbee!!!

Post by adafruit_support_bill »

First build a string out of the ASCII characters, then you can use the atoi() function.
http://www.arduino.cc/cgi-bin/yabb2/YaB ... 1176289764

Locked
Please be positive and constructive with your questions and comments.

Return to “XBee products (discontinued)”