Arduino ADC problem

I’m rookie at arduino , and now I have some ADC problem .

Currently I have " one Arduino uno R3 " , " two series1 XBee (define one call XBee1 , one call XBee2)" and " one 3-axis accelerometer " .

The " 3-axis accelerometer " connection to XBee1 use ADC mode , and XBee1 will sent data to XBee2 .

The XBee2 connection to Arduino , and the Arduino use USB transmission line connection to PC .

Two XBee setting are : (XBee1: DL=0x1234 , MY=0x5678 , D0=D1=D2=2 , IR=0x14 , IT=5) and (XBee2: DL=0x5678 , MY=0x1234 , P0=P1=2 , IU=1 , IA=0x5678or0xFFFF)

Finally use Arduino development software’s " Serial Monitor " print result use “16hex” on the screen . For example : 7E 0 26 83 56 78 1C 0 5 E 0 1 55…

My question is described as attachment :

Sorry I have poor English and if someone doesn’t understand in the article , welcome to respond .
Hope anyone can give some any suggestions . Let me solve this problem . Thanks a lot .

Description of the problem.txt (4.28 KB)

Which "3-axis accelerometer" do you have? They are not all the same.

To johnwasser :

I think the " 3-axis accelerometer " is ADXL330 . Because there was no clearly marked on the accelerometer .

They have 6 pins : VCC , ST , GND , X , Y , Z , respectively.

VCC connect to 3.3V , X connect to XBee’s ADO(pin20) , Y connect to XBee’s AD1(pin19) , Z connect to XBee’s AD2(pin18) .

The sample data you provided is:

7E 0 26 83 56 78 1C 0 5 E 0 1 55................

The 00 26 indicates the message is 38 bytes. It would be good to see more data.

7E Start Delimiter 0026 Length (38 bytes from here to checksum) 83 API Identifier: 16-bit A/D 5678 Source address. 1C RSSI (Received Signal Strength) 00 Option Byte 05 Sample Quantity 0E00 Channel indicators 0E00=0b0000111000000000 = A2, A1, A0 0155 Value 1 for channel A0 xxxx Value 1 for channel A1 xxxx Value 1 for channel A2 xxxx Value 2 for channel A0 xxxx Value 2 for channel A1 xxxx Value 2 for channel A2 xxxx Value 3 for channel A0 xxxx Value 3 for channel A1 xxxx Value 3 for channel A2 xxxx Value 4 for channel A0 xxxx Value 4 for channel A1 xxxx Value 4 for channel A2 xxxx Value 5 for channel A0 xxxx Value 5 for channel A1 xxxx Value 5 for channel A2 xx Checksum (not included in Length)

Perhaps you should show more data, at least three or four messages worth.

To johnwasser :

The sample data and my questions is in the attachment , did you see it ?

If you can't see it , I will post those data in the reply . Thank to your reply .

It looks like only the first message and half the second message arrive correctly. After that looks like all garbage, mostly 7E and ED bytes.

Yes, a correct message should be 42 bytes but you can't expect to receive every character correctly every time. If you take in 42 characters and then assume you have a correct message then if you ever miss a character or gain a character you will be out of sync forever. When you want to receive a message you should look for 0x7E followed by 0x00 and 0x26. If any of those three don't match you should look for the next 0x7E. If you get to the checksum and that doesn't match you should throw out that message and go back to looking for a 0x7E.

Is it possible that your program is corrupting the data? Either that or your hardware is flakey.

To johnwasser :

Thank for your reply , and I further solve the packet not complete problem .

Because I change XBee1’s IR and IT . IR change to 1300 and IT change to 1 .

The setting become sample ADO , AD1 and AD2 once each every 4864ms .

It then buffers 1 samples each before sending them back to the base module .

The base should then receive a 18-Byte transmission (6 Bytes data and 12 Bytes framing) every 4864 ms .

And the program delay time I setting “delay(250)” .

Because 4864/18=270.22 , so delay time must < 270.22 , then it will be received the packet complete .

Now I received the packet each one is liked 7E 0 26 83 56 78 21 0 1 E 0 3 FF 3 FF 3 FF 78 .

It’s correct . But now I have new problem :

Why I received the data is “3 FF 3 FF 3 FF” , and correspond X , Y , Z , respectively , is it correct ?

If it’s error , can you tell me the error in where ? Thank you a lot .

kobe1117: But now I have new problem :

Why I received the data is "3 FF 3 FF 3 FF" , and correspond X , Y , Z , respectively , is it correct ?

If it's error , can you tell me the error in where ? Thank you a lot .

That means that all three inputs are at 3.3V (full scale).

You should NOT be using delay() in place of Serial.available(). Maybe that's part of the problem you were having. What does your sketch look like?

To johnwasser :

The following is my simple sketch program :

int val=0;

void setup() { Serial.begin(9600); }

void loop() { val = Serial.read(); if (-1 != val) { Serial.println(val, HEX); delay(250); } }

If it's wrong , how can I change or add something to my program ?

And now the three inputs are at 3.3V , is it correct ? Thank for your reply .

This sketch should do the same thing without the need for delay():

void setup() 
{
  Serial.begin(9600);
}

void loop()
{
    if (Serial.available())
        Serial.println(Serial.read(), HEX);
}

To johnwasser :

Thank for your reply , I will try it . What it works look like , tomorrow I will give you a reply . Thank you so much .

To johnwasser :

Your code as the same as result with delay() .

Now I probably know the reason of 3 FF 3 FF 3 FF .

Because I use FTDI to support XBee1 power , they support XBee 5V , but XBee just use 3.3V , so I received 3 FF 3 FF 3 FF , right ?

When I used 3.3V , each data form I received liked 7E 0 E 83 56 78 1C 0 1 E 0 3 EC 3 EC 3 EE B4 .

Now how can I further analysis " 3 EC 3 EC 3 EE " ?

Thank you .