adxl335 and xbee!!!

Xbee projects like the adapter, xbee tutorials, tweetawatt/wattcher, etc. purchased at Adafruit

Moderators: adafruit_support_bill, adafruit

adxl335 and xbee!!!

Postby daremots » Sun Aug 08, 2010 9:42 pm

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 .
daremots
 
Posts: 12
Joined: Sun Aug 08, 2010 8:48 pm

Re: adxl335 and xbee!!!

Postby adafruit_support_bill » Mon Aug 09, 2010 4:47 am

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'
User avatar
adafruit_support_bill
 
Posts: 16078
Joined: Sat Feb 07, 2009 9:11 am

Re: adxl335 and xbee!!!

Postby daremots » Mon Aug 09, 2010 8:49 pm

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 8:48 pm

Re: adxl335 and xbee!!!

Postby daremots » Mon Aug 09, 2010 8:57 pm

and the serial monitor still shows readings even when i pulled off the power supply from the transmitting side.
daremots
 
Posts: 12
Joined: Sun Aug 08, 2010 8:48 pm

Re: adxl335 and xbee!!!

Postby adafruit_support_bill » Tue Aug 10, 2010 5:20 am

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);
}
User avatar
adafruit_support_bill
 
Posts: 16078
Joined: Sat Feb 07, 2009 9:11 am

Re: adxl335 and xbee!!!

Postby daremots » Mon Aug 16, 2010 9:32 pm

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
daremots
 
Posts: 12
Joined: Sun Aug 08, 2010 8:48 pm


Re: adxl335 and xbee!!!

Postby daremots » Wed Aug 18, 2010 4:50 pm

(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);
}
daremots
 
Posts: 12
Joined: Sun Aug 08, 2010 8:48 pm

Re: adxl335 and xbee!!!

Postby Davhydes » Mon Feb 06, 2012 3:05 am

Hello,
I have exactly the same problem than daremots.

Is there a solution to this problem?

Thank you :)
Davhydes
 
Posts: 2
Joined: Mon Feb 06, 2012 3:03 am

Re: adxl335 and xbee!!!

Postby adafruit_support_bill » Mon Feb 06, 2012 6:48 am

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.
User avatar
adafruit_support_bill
 
Posts: 16078
Joined: Sat Feb 07, 2009 9:11 am

Re: adxl335 and xbee!!!

Postby Davhydes » Mon Feb 06, 2012 11:21 am

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
Davhydes
 
Posts: 2
Joined: Mon Feb 06, 2012 3:03 am

Re: adxl335 and xbee!!!

Postby adafruit_support_bill » Mon Feb 06, 2012 12:06 pm

First build a string out of the ASCII characters, then you can use the atoi() function.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176289764
User avatar
adafruit_support_bill
 
Posts: 16078
Joined: Sat Feb 07, 2009 9:11 am


Return to XBee products from Adafruit

Who is online

Users browsing this forum: No registered users and 1 guest

Stuff to buy from the Adafruit store and links to product documentation!


New Products [108]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[31]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[34]
LCDs & Displays[48]
Components & Parts[70]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[111]
 
Wireless[14]
Cables[62]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]