Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Re: XBee 2.5 API Packet Parsing Problem on: May 02, 2011, 07:39:33 am
Hey Grag38,

Thanks very much for your response but I'm not sure I understand what you mean...

The data is being stored in a uint8_t byte array as you can see from the code (called packet[30]), which is coming directly from;

Perhaps you could elaborate slightly more on what you mean?

Many thanks

2  Using Arduino / Networking, Protocols, and Devices / XBee 2.5 API Packet Parsing Problem on: April 29, 2011, 08:28:49 am

I was wondering if anyone could give me some advice, I am having real problems doing what I think is a simple operation:

I am trying to parse API I/O sample packets from a XBee 2.5 (with Router/End Device Firmware 1347) with an accelerometer attached. The packets are being sent every 100ms to an Arduino FIO, with another XBee 2.5(also with with Router/End Device Firmware 1347). At the moment the code should just take the 6 bytes of sensor data and then send them to the Coordinator in a new packet. But I have tried using Andrew Rapp's XBee library to parse the data and it would not work properly: it parses the first two sensor readings but not the third, and intermittently throws up errors with no error code. So I have had somewhat more success using the example from Nootropic Design ( but this does parse the end of the packet properly (example below).

I am debugging using NewSoftSerial to see what the Arduino is parsing. To ensure accuracy, I have also parsed the data in Supercollider, with exactly the same logic, (as well as double checking in XCTU) so I know that the packets should look like this:

7E 00 16 92 00 13 A2 00 40 61 30 E0 3B 07 01 01 00 00 0D 02 57 01 F8 01 F2 71

But what I am getting printed in the NewSoftSerial port is this:

7E 00 16 92 00 13 A2 00 40 61 30 E0 3B 07 01 01 00 00 0D 02 57 01 FF FF FF FF

I have tried it with
if(Serial.available > 0)
as well, which seemed to incorrectly read the start of the packets.

Additionally, the packets are not transmitted smoothly from the Arduino FIO to the coordinator which also making me very confused!

If anyone has any feedback on why this is not working properly I would be very very grateful! I can't seem to find anything on the forums with a similar problem...

Please find the code below, your comments would be greatly appreciated!



 * Copyright (c) 2009 Andrew Rapp. All rights reserved.
 * This file is part of XBee-Arduino.
 * XBee-Arduino is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * XBee-Arduino is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with XBee-Arduino.  If not, see <>.

#include <XBee.h>
#include <NewSoftSerial.h>

// create the XBee object
XBee xbee = XBee();
uint8_t packet[30];
uint8_t payload[6];

// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x00000000, 0x00000000);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

int pin5 = 0;

int statusLed = 13;
int errorLed = 13;

long previousMillis = 0;
long interval = 50;
NewSoftSerial nss(3, 4);

void setup() {
  pinMode(statusLed, OUTPUT);
  pinMode(errorLed, OUTPUT);

void loop()
    unsigned long currentMillis = millis();
  //if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;   

  for(int i = 0; i < 30; i++){
    nss.print(" ");

void readPacket(){
  //if (Serial.available() > 0) {
    while (Serial.available()){
    int b =;
    if (b == 0x7E) {
      packet[0] = b;
      packet[1] =;
      packet[2] =;
      int dataLength = (packet[1] << 8) | packet[2];

      for(int i=1;i<=dataLength;i++) {
        packet[2+i] =;
      int apiID = packet[3];
      packet[3+dataLength] =;//checksum
     if (apiID == 0x92) {
          for(int i = 0; i < 6; i++) {
            payload[i] = packet[i+19];
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Modifying "blink without delay" on: April 06, 2008, 04:50:39 pm
Thats brilliant thank you very much Oracle and John_Ryan, you've been a great help...

I've ended up doing the millis() counter hack you talked about and it seems to be working fine.

I did look into the timer interrupt before, maybe i'll go back and try it again now i've gained some more knowledge from trying out different ways to solve this problem...

Thanks again,

4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Modifying "blink without delay" on: April 06, 2008, 02:11:01 pm
Thanks for your response Oracle...

However I am trying write this code without using delay(). The issue is that I need to have other time based code running and using delay() will prevent this from happening.

If you have any other ideas that would be much appreciated..


5  Forum 2005-2010 (read only) / Syntax & Programs / Modifying "blink without delay" on: April 06, 2008, 09:35:09 am
Dear Forum,

I would appreciate it greatly if you could take a look at my attempt to modify one of the tutorials. What I am trying to achieve is a quick blink on HIGH and a longer time on LOW. And using an analogue input change which LEDs are blinking. The code below works but as soon as the look up array (hitz) is modified the timings of all the blinks work independently of each other which is not the desired effect: I would like them to blink at the same time. I've tried various ways of trying to homogenise the previousMillis variable (which I believe is the problem but possibly not) for all 4 elements in the array but to no avail.

I must say at this point that I am not a coder so may well have missed something blindingly obvious to those more experienced but any help/ pointing in the right direction would be great:

long previousMillis[4] = {0,0,0,0};        // will store last time LED was updated
long interval[4] = {1000,1000,1000,1000};           // interval at which to blink (milliseconds)
int value[4];
int ledPin[4] = {3,4,5,9};
int average = 0;
boolean hitz[4] = {LOW,LOW,LOW,LOW};

void changeUp(){
  if((average >= 100) && (average <= 400)){
    hitz[0] = HIGH;
    hitz[0] = LOW;
  if((average >= 513) && (average <= 700)){
    hitz[1] = HIGH;
  else {hitz[1] = LOW;
  if((average >= 650) && (average<=850)){
    hitz[2] = HIGH;
    hitz[2] = LOW;
  if((average >= 800) && (average <= 1000)){
    hitz[3] = HIGH;
    hitz[3] = LOW;
void setup(){
  for(int i=0;i<4;i++)
    pinMode(ledPin[i], OUTPUT);
  for(int i=0;i<4;i++)
void loop()
  average = analogRead(0);
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, is the difference
  // between the current time and last time we blinked the LED bigger than
  // the interval at which we want to blink the LED.
  for(int i=0;i<4;i++){
  if (millis() - previousMillis[i] > interval[i]) {
    previousMillis[i] = millis();   // remember the last time we blinked the LED

    // if the LED is off turn it on and vice-versa.
    if (value[i] == LOW){
        value[i] = hitz[i];
      interval[i] = 50;
      value[i] = LOW;
      interval[i] = 3000;
    digitalWrite(ledPin[i], value[i]);


Many thanks,

Pages: [1]