Shop OBEX P1 Docs P2 Docs Learn Events
Stingray not working with Xbee — Parallax Forums

Stingray not working with Xbee

MicrocontrolledMicrocontrolled Posts: 2,461
edited 2011-03-02 09:47 in Propeller 1
I have a stingray connected to an Xbee module, with the module connected to (of course) power, and DOUT to 16 and DIN to 17. I have a remote to work with the Xbee, but although the signals are coming though when I plug the USB cable into the Xbee, I don't get anything with the stingray. Here is the code I am using. If I start the function with "Auto" it works fine, as the Xbee isn't used.
CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

VAR

  byte dir[4]
  byte speed
 
OBJ

  ping  :  "Ping"
  pwm   :  "PWMx8"
  ser   :  "FullDuplexSerial"
   
PUB Start

  ser.start(16,17,0,9600)
  pwm.start(24, %0000_1111, 23000)
  dira[24..27]~~
  dira[0]~~
  outa[0]~
  Manuel
  
PUB Manuel | command, i

  speed := 128
  repeat
    case ser.rxcheck
     ' "a": Auto
      "*": ser.tx("@")
      "u":
        dir[1] := speed
        dir[2] := speed
        dir[3]~
        dir[4]~
      "d":
        dir[1]~
        dir[2]~
        dir[3] := speed 
        dir[4] := speed
      "r":
        dir[1]~
        dir[2] := speed
        dir[3]~
        dir[4]~
      "l":
        dir[1] := speed
        dir[2]~
        dir[3]~
        dir[4]~
      "s":
        repeat i from 1 to 4
          dir[i]~           
    pwm.duty(24, dir[1])
    pwm.duty(25, dir[3])
    pwm.duty(26, dir[4])     
    pwm.duty(27, dir[2])

PUB Auto | dist, v1, v2, v3, v4, dirc, cntr, distback

  dir := "r" 
  repeat
    dist := ping.Inches(8)
    distback := ping.Inches(9)
   ' ser.tx(0)
    'ser.dec(dist)
    if dist < 16
      if distback > 16
        v1~
        v2~
        v3 := 128
        v4 := 128
      else
        v1 := 128
        v2~
        v3~
        v4 := 128  
    elseif dist < 36
      outa[0]~~
      if dirc == "r"
        v1~
        v2 := 128
      if dirc == "l"
        v1 := 128
        v2~  
      v3~
      v4~
      cntr++
      if cntr == 5
        cntr~
        if dirc == "r"
          dirc := "l"
        else
          dirc := "r"  
     ' ser.str(string(" Close"))
    else
      v1 := 128
      v2 := 128
      v3~
      v4~
      'ser.str(string(" Far"))
    'waitcnt(clkfreq/4 + cnt) 
   ' if dist > 13
    outa[0]~                 
    pwm.duty(24, v1)
    pwm.duty(25, v3)
    pwm.duty(26, v4)     
    pwm.duty(27, v2)        
    'outa[25..26] := %00     
    waitcnt(clkfreq/8 + cnt)

Thanks,
Microcontrolled

Comments

  • SRLMSRLM Posts: 5,045
    edited 2011-03-02 09:47
    For your case statement you should add a default case, or at least a -1 case (if there is nothing in the buffer). The code may still work without it, but it's not clear what should happen. I'd also add in an LED that you toggle if you get valid data of any kind, just so that you can check that there is some sort of communication. Next, I'd disconnect the DOUT pin on the transmitter XBEE and connect in it's place the DOUT pin on the receiver (and all grounds, of course). Then you can check on the same computer whether or not the units are connected. Finally, I would make sure that all the units are reset to factory defaults. If you're using Windows you can do this with the X-CTU software.
Sign In or Register to comment.