Shop OBEX P1 Docs P2 Docs Learn Events
Xbee Tips And Tricks ( Help) — Parallax Forums

Xbee Tips And Tricks ( Help)

chris joneschris jones Posts: 391
edited 2011-02-08 19:00 in Accessories
Hello

i am working on a cool project and will rely on my xbee modules a lot, i have had a lot of issues getting my xbees off the ground but was a hardware issue all along. So i would like to start this forum thread to see if i can get some help from the community on my ideal’s and questions i have about my xbees.

Current Setup
2 prop demo boards
2 xbee S1
2 LCD
2 Adapter boards ( http://www.parallax.com/Store/Access...2/Default.aspx )
1 USB Adapter board

Comments

  • chris joneschris jones Posts: 391
    edited 2011-01-30 09:02
    First Quick question how to i get my xbees Mac address and display to my LCD.
  • sylvie369sylvie369 Posts: 1,622
    edited 2011-01-30 13:26
    Do you have your XBees mounted on any kind of adapter board? You'll need adapter boards for both of them.

    You should get at least one of these:

    http://www.parallax.com/Store/Accessories/CommunicationRF/tabid/161/CategoryID/36/List/0/SortField/0/catpageindex/2/Level/a/ProductID/643/Default.aspx

    When you put an XBee on that board and connect it through a USB cable to your computer, you can use the free XCTU software (available at Digi.com, links on the Parallax site) to read whatever information you want to from the XBee, and also to change the various settings. That's the easiest way to do those things.

    If you remove the USB cable from that board, and you've installed headers, it can also be used to mount the XBee on a breadboard. Otherwise you'll want another adapter to mount your second XBee on, so you can connect it to your Prop demo boards. Since the Prop is 3.3V (which matches the XBee), you can simply use one of these:

    http://www.parallax.com/Store/Accessories/CommunicationRF/tabid/161/CategoryID/36/List/0/SortField/0/catpageindex/2/Level/a/ProductID/642/Default.aspx
  • chris joneschris jones Posts: 391
    edited 2011-01-30 13:37
    sorry yes i have 2 adapter boards as well and 1 usb adapter board to configure the xbees.
  • sylvie369sylvie369 Posts: 1,622
    edited 2011-01-30 16:47
    Okay, I see you added them to your list.

    I'm not sure what you mean by "my xbees Mac address" - are you talking about its hardware serial number? The ATSL and ATSH commands will get you the high and low words of the serial number, but normally you use other means of addressing an XBee, notably the "MY" source address, in combination with the PANID (network ID number). Alternatively, you can set and use a unique Node Identifier label for each of your XBee modules. Your other XBees can use those addresses/PANIDs/NIs to address a specific XBee.
  • chris joneschris jones Posts: 391
    edited 2011-01-30 17:05
    so do i set the "MY" source address in the configuration software from digikey?

    And one i set the ID how do i access it from my propeller chip?
  • sylvie369sylvie369 Posts: 1,622
    edited 2011-01-30 18:59
    You have two options for setting up the XBee modules.

    1 - You can mount the module on your USB board and use XCTU to read the current settings, make the changes you need, and then write the new settings to the module. They will stay set that way then until you explicitly change them.
    2 - You can read and change the settings through your Propeller software. Of course you can write the changes you make that way to nonvolatile memory as well, but it's fine to just set up your software so that when the program runs, it makes the changes, so that it doesn't matter what the settings are before that point.

    Reading and setting the settings through the Prop chip is a matter of using the XBee object in the OBEX (or of just sending the serial data yourself through your own code, if you prefer). Here's a snippet of Spin code I'm using:
    OBJ 
      XB   : "XBee_Object"       
      Comm : "FullDuplexSerialPlus"  
      Num  : "Numbers"
      LCD  : "Debug_LCD"
      BS2  : "BS2_Functions"
    VAR     byte          Alt[6]       ' Variable to hold the first 6 bytes of altitude data from MAWD. First 5 bytes are 5 digits of altitude, then CR (then LF, unread).
            word          AltN         ' Variable to hold numerical value of altitude, after conversion from string. 
            word          MaxAlt       ' Variable to hold maximum altitude
            byte          Event0       ' Has pull-pin 0 pulled?
            byte          Event1       ' Has pull-pin 1 pulled?
            long          PinStack[65] ' Stack for cog running PinsCheck (stack size set by trial and error: 9 is too small, and overwrites E1).
            long          LCDStack[65] ' Stack for cog running LCDUpdate
            word          LCDBuffer[8] ' Variable to hold values to be displayed on the LCD.
                          { 0 - AltN
                            1 - MaxAlt
                            2 - Flight status: 0 = Ready, 1 = In flight, 2 = Landed
                            3 - Event 0: 0 = No event, 1 = Event
                            4 - Event 1: 0 = No event, 1 = Event
                            5 - Data received: 0 = No, 1 = Yes
                            6-7 (reserved)
                          }
            word          LCDBufOld[8] ' Temporary buffer to be compared with current contents to determine whether or not to update LCD.
            byte          temp, flag   ' General purpose variables 
    Pub Start 
        XB.start(0,1,0,9600)           ' XBee Comms - RX,TX, Mode, Baud
        XB.AT_init
        XB.AT_Config(String("ATMY 0")) ' Config to receive as Module 0 to match XBee-MAWD telemetry output DL setting.
        DIRA[22..23]~                  ' Set pins 22 and 23 as inputs from the XBee I/O pins 0 and 1
        XB.AT_Config(String("ATD0 5")) ' Config to use XBee DIO pin 0 as a digital output, default HIGH
        XB.AT_Config(String("ATD1 5")) ' Config to use XBee DIO pin 1 as a digital output, default HIGH
        XB.AT_Config(String("ATIA 1")) ' Config to receive DIO data from module whose MY = 1. 
        XB.AT_Config(String("ATIU 0")) ' Config so that DIO pin states are not sent out UART, where they would interfere with alt data
    

    You should read through the XBee object to get a sense of what can be done, and how to do it.
  • chris joneschris jones Posts: 391
    edited 2011-01-30 19:13
    Thanks, i used option 1 and set my id as a 3 digit number. your exmaples shows how to set the My Address but not get the id unless i am overlooking it.I will also look over the xbee object to see if i am missing anything.
  • sylvie369sylvie369 Posts: 1,622
    edited 2011-01-31 07:48
    You should be able to get the value using either AT_Config or API_Query, from Martin's XBee object. I don't remember if I have any code that reads the configuration information, though.

    I would try declaring a string, then using AT_Config with ATMY and a pointer to your string to get the MY address into that string.
  • chris joneschris jones Posts: 391
    edited 2011-01-31 09:21
    ok , thanks i will give this a try.............
  • chris joneschris jones Posts: 391
    edited 2011-02-02 15:22
    I added thsi code and it seems to always return null any idelas what i am doing wrong

    ID := XB.AT_Config(string("ATMY"))
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2011-02-02 17:57
    Reading the XBee Object Documentation for AT_Config, you will see this:
    PUB AT_Config(stringptr)
    {{
    Send a configuration string for AT Mode
    XB.AT_Config(string("ATMY 2"))
    May also be used to query
    XB.AT_Config(string("ATMY")) ' request value
    addr := XB.RxHEX ' accept value
    FOR Transparent (Non-API) MODE USE
    Be sure to issue .AT_Init once at startup
    }}

    You can use
    AT_Config(string("ATMY"))
    to request the value, but you need another line of code accept the data returned by the XBee:
    ID := XB.RxHex

    -Martin
  • chris joneschris jones Posts: 391
    edited 2011-02-02 19:40
    Hello

    i seem to have something messed up can you glance at my code and see if everything is correct.
    ''****************************************
    ''*  Sensor Node technology              *
    ''****************************************
    CON
      _clkmode = xtal1 + pll16x                             ' use crystal x 16
      _xinfreq = 5_000_000                                  ' 5 MHz cyrstal (sys clock = 80 MHz)
      LCD_PIN   = 2                                         ' for Parallax 4x20 serial LCD on P0
      LCD_BAUD  = 19_200
      LCD_LINES = 4
        ' Set pins and Baud rate for XBee comms  
      XB_Rx     = 0        ' XBee DOUT
      XB_Tx     = 1        ' XBee DIN            
      XB_Baud   = 9600
      ' Set pins and baud rate for PC comms 
      PC_Rx     = 31  
      PC_Tx     = 30
      PC_Baud   = 9600          
    VAR
      byte ID[10]
      
    OBJ
      lcd   : "debug_lcd"
      XB    : "XBee_Object"     
    
    PUB main | idx
      'start the xbee nodules
      XB.start(XB_Rx, XB_Tx, 0, XB_Baud)                    ' Initialize comms for XBee
      XB.AT_Init                                            ' Initialize for fast AT command use - 5 second delay to perform                       
      if lcd.init(LCD_PIN, LCD_BAUD, LCD_LINES)             ' start lcd
        lcd.cursor(0)                                       ' cursor off
        lcd.backLight(true)                                 ' backlight on (if available)
        lcd.custom(0, @Bullet)                              ' create custom character 0
        lcd.cls                                             ' clear the lcd
        lcd.str(string("Sensor Node 1", 13))
        lcd.putc(0)                                         ' display custom bullet character
        lcd.str(string(" Status", 13))
        lcd.putc(0)
        lcd.str(string(" Wireless", 13)) 
        lcd.putc(0)
        lcd.str(string(" Energy"))       
        repeat
          repeat
            XB.AT_Config(string("ATMY")) 
            'to request the value, but you need another line of code accept the data returned by the XBee:
            ID := XB.RxHex
            updateLcd(ID)
            'waitcnt(clkfreq / 5 + cnt)                      ' pad with 1/5 sec
    
    PRI updateLcd(value)
          
        lcd.gotoxy(12, 1)
        lcd.str(value)                         
        lcd.gotoxy(11, 2)
        lcd.str(value)                                   
        lcd.gotoxy(7, 3)
        lcd.str(value)                                              
                    
          
    DAT
      Bullet      byte      $00, $04, $0E, $1F, $0E, $04, $00, $00
    {{
    }} 
    
  • chris joneschris jones Posts: 391
    edited 2011-02-03 05:37
    it looks like i might be missing this in my code

    XB.AT_init
    XB.AT_Config(String("ATMY 0")) ' Config to receive as Module 0 to match XBee-MAWD telemetry output DL setting.

    _________________________________

    its using pin 0 to get the setings P0 DOUT
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2011-02-03 05:52
    In UpdateLCD, I suspect you would want to use:
    LCD.Dec(value)
    or
    LCD.Hex(value)
    since the ID is stored as a value and not a string.

    Also, your repeat loop has this being done continuously with no delay in it - probably not a good idea. Read and display once and end with a repeat for testing.

    You also have ID defines as an array, where it only needs to be a word value - again, not a string that is returned.

    Some untested revisions... Ok, I've not used the new forums much yet, and how to insert code in a post escapes me right now, so attached.

    XBee_LCD.spin

    Good luck!
    -Martin
  • sylvie369sylvie369 Posts: 1,622
    edited 2011-02-03 05:54
    It looks to me like your code has the XB.AT_init line already.

    You don't need to set your XBee's MY before reading it. Every XBee has a MY address, whether you've ever changed it or not. I believe they're shipped with their MY set to 0, but I'm not certain about that. Regardless, you should be able to read the MY address even if you've never set it.
  • chris joneschris jones Posts: 391
    edited 2011-02-03 22:37
    Martin i gave your code a try and i still return a empty value.
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2011-02-05 18:22
    Chris,
    It's good code for reading the XBee. Did you get any other errors?

    Start slow, be sure you can read the XBee and send to the PST instead, then add in your LCD stuff and test that.

    I tested the code I sent without the LCD. It read it.

    -Martin
  • chris joneschris jones Posts: 391
    edited 2011-02-05 18:24
    ok good ideal i need to crawl befor i walk i will make sure i can get the infomation to a terminal screen and update you one io i try that.
  • chris joneschris jones Posts: 391
    edited 2011-02-08 19:00
    Martin i tried the code with just the terminal and i still get a blank screen my code is posted
    ''****************************************
    ''* Sensor Node technology *
    ''****************************************
    CON
    _clkmode = xtal1 + pll16x ' use crystal x 16
    _xinfreq = 5_000_000 ' 5 MHz cyrstal (sys clock = 80 MHz)
    LCD_PIN = 2 ' for Parallax 4x20 serial LCD on P0
    LCD_BAUD = 19_200
    LCD_LINES = 4
    ' Set pins and Baud rate for XBee comms 
    XB_Rx = 0 ' XBee DOUT
    XB_Tx = 1 ' XBee DIN 
    XB_Baud = 9600
    ' Set pins and baud rate for PC comms 
    PC_Rx = 31 
    PC_Tx = 30
    PC_Baud = 9600 
    VAR
    ' byte ID[10] - no reason to make global if passing value to another routine
     
    OBJ
    lcd : "debug_lcd"
    XB : "XBee_Object"
    Term : "FullDuplexSerial" 'to serially commincate with the XBee module " 
    PUB main | idx, ID ' Put ID here to make local
    'start the xbee nodules
    XB.start(XB_Rx, XB_Tx, 0, XB_Baud) ' Initialize comms for XBee
    XB.AT_Init ' Initialize for fast AT command use - 5 second delay to perform 
    if lcd.init(LCD_PIN, LCD_BAUD, LCD_LINES) ' start lcd
    lcd.cursor(0) ' cursor off
    lcd.backLight(true) ' backlight on (if available)
    lcd.custom(0, @Bullet) ' create custom character 0
    lcd.cls ' clear the lcd
    lcd.str(string("Sensor Node 1", 13))
    lcd.putc(0) ' display custom bullet character
    lcd.str(string(" Status", 13))
    lcd.putc(0)
    lcd.str(string(" Wireless", 13)) 
    lcd.putc(0)
    lcd.str(string(" Energy"))
    XB.AT_Config(string("ATMY")) 
    'to request the value, but you need another line of code accept the data returned by the XBee:
    ID := XB.RxHex
    updateLcd(ID)
    repeat
    waitcnt(clkfreq / 5 + cnt) ' pad with 1/5 sec
    PRI updateLcd(value)
     
    lcd.gotoxy(12, 1)
    lcd.hex(value, 4)
    Term.hex(value, 4) 
    ' lcd.gotoxy(11, 2)
    ' lcd.hex(value) 
    ' lcd.gotoxy(7, 3)
    ' lcd.hex(value) 
     
     
    DAT
    Bullet byte $00, $04, $0E, $1F, $0E, $04, $00, $00
    {{
    }}
     
    
Sign In or Register to comment.