Shop OBEX P1 Docs P2 Docs Learn Events
XBee I/O — Parallax Forums

XBee I/O

RsadeikaRsadeika Posts: 3,837
edited 2013-05-20 20:50 in Propeller 1
This thread will eventually become an XBee Temperature/Humidity log program, I hope. Below is the minimal code required, as per my coding experience, to work with the XBee. This works with CMM and some of the XMM modes, specifically the XMM-SPLIT... does not work.

Basically this program sends out via the XBee a "Did you get this?" message. This is the simplest form before I move into some XBee I/O stuff.

Ray
/*
* MyXbTHlog.c
*
* May 19, 2013
*
* Set for Activity Board   
*/

#include "simpletools.h"                      // Include simple tools

/* These defines do not work with the xbee = fopen(...). */
//#define Tx 13
//#define Rx 12
//#define BAUD 9600

FILE *xbee;

int main()                                    
{
  // Add startup code here.

/* Initialise XBee for operation. */
/*                   Baud  Tx  Rx          */
  xbee = fopen("SSER:9600, 13, 12", "r+");

  pause(300);  // Terminal catch up if necessary
  fprintf(xbee, "Program Start.\n");

  while(1)                                   
  {
    fprintf(xbee,"Did you get this?\n");
    pause(3000);  // Pause for three seconds.
  }
  return 0;  
}

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-05-19 07:37
    Check out stringification to sort your #define issue. Something like this should work:
    #include "simpletools.h"                      // Include simple tools
    
    [COLOR="orange"]#define xstr(s) str(s)
    #define str(s)  #s
    #define SSER(_baud_, _tx_, _rx_) "SSER:"xstr(_baud_)", "xstr(_tx_)", "xstr(_rx_)[/COLOR]
    
    #define Tx 13
    #define Rx 12
    #define BAUD 9600
    
    int main()                                    
    {
    /* Initialise XBee for operation. */
      FILE *xbee = fopen([COLOR="blue"]SSER(BAUD, Tx, Rx)[/COLOR], "r+");
    
      pause(300);  // Terminal catch up if necessary
      fprintf(xbee, "Program Start.\n");
    
      while(1)                                   
      {
        fprintf(xbee,"Did you get this?\n");
        pause(3000);  // Pause for three seconds.
      }
      return 0;  
    }
    
  • David BetzDavid Betz Posts: 14,516
    edited 2013-05-19 19:10
    Rsadeika wrote: »
    This thread will eventually become an XBee Temperature/Humidity log program, I hope. Below is the minimal code required, as per my coding experience, to work with the XBee. This works with CMM and some of the XMM modes, specifically the XMM-SPLIT... does not work.
    I don't have an Activity Board but it is my understanding that the only XMM it supports is using the SD cache driver and the EEPROM cache driver. Neither of those will support any XMM mode other than xmmc. You need external RAM to support either xmm-single or xmm-split.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-05-20 03:58
    @kuroneko, Thanks, I will give it a try. For people just getting into C, that is a small example as to how complex coding can get, just to take care of a, what I thought was a simple problem.

    @David Betz, Thanks, I am in the habit of trying all the memory models, just to see what happens.

    At this point I think I need some XBee experts to step up and join in. So far, the program is set up for a simple peer to peer transmission, it does not have any capability to have its own ID where it only responds to a specific request. I think that would be the next step, while the program is still in a very simple form. Adding this to the program will also test whether SSER is capable, or will it have to use FDS. I will look through some of my old code to see how far I got, but I do remember I did not get it to work. It seems the problem I was having was that it needed to some polling, which meant threads or multicog use, which presents its own problems.

    Ray
  • edited 2013-05-20 20:50
    Hi Ray,

    Just so you know, simple libraries + examples for the various peripherals you are working on and many others will be appearing in the Learn folder throughout he summer. The XBee object is waiting on some under the hood changes to the learn library that should be happening over the next couple weeks. If you want an to work with some interim code, please send me a PM.

    Thanks, Andy
Sign In or Register to comment.