Shop OBEX P1 Docs P2 Docs Learn Events
1st Prop project: Trouble with joystick/XBee to XBee comm — Parallax Forums

1st Prop project: Trouble with joystick/XBee to XBee comm

FalconFalcon Posts: 191
edited 2012-10-27 10:24 in Propeller 1
I've been a BS2 user for quite a while, and am just now starting to use the Propeller. I've completed the PE Kit but have no other propeller experience.

My ultimate goal is to make a remote control for a robot using two Propellers and two XBee modules.
I've started with some code from a Tymkrs.com post found here http://forums.parallax.com/showthread.php?141739-Making-Parallax-Modules-Wireless-with-XBee-modules&highlight=joystick to display joystick position on the PC.

I have this code to read the joystick (P/N 27800) and transmit the position via XBee mounted to a Propeller Demo Board.
I verified the joystick works with the Propeller on a Demo Board using the Kickstart code. I verified the XBee's work using the XBee "Getting Started" Tutorial but used a USB Adapter board.
XBee DOUT to pin5
XBee DIN to pin6
Joystick to pin0 and pin1
CON 
  _clkmode = xtal1 + pll16x 
  _xinfreq = 5_000_000 
  
  XB_Rx     = 5    ' XBee DOUT 
  XB_Tx     = 6    ' XBee DIN 
  XB_Baud   = 9600 
  CR        = 13   ' Carriage Return value       
                                                                    
OBJ 
   XB         : "FullDuplexSerial"
   rc         : "RCTime"    
Pub  Start |  UD, LR   
XB.start(XB_Rx, XB_Tx, 0, XB_Baud) ' Initialize comms for XBee 
   
waitcnt(clkfreq + cnt)

 repeat
    rc.rctime(0, 1, @LR)
    rc.rctime(1, 1, @UD)
    XB.Str(String("UD = "))
    XB.dec(UD)
    XB.Str(String(", LR = "))
    XB.dec(LR) 
    XB.tx(13)
    waitcnt(clkfreq / 2 + cnt)       ' 1/2 second delay



I'm using the following code to receive the data with another XBee and Propeller (on a Demo Board) and display it on the PC.
XBee DOUT to pin0
XBee DIN to pin1
CON 
  _clkmode = xtal1 + pll16x 
  _xinfreq = 5_000_000 
  ' 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 
  long stack[50]                ' stack space for second cog 
                                                                        
OBJ 
  PC    : "FullDuplexSerial"   
  XB    : "FullDuplexSerial" 
Pub Start  
  PC.start(PC_Rx, PC_Tx, 0, PC_Baud) ' Initialize comms for PC   
  XB.start(XB_Rx, XB_Tx, 0, XB_Baud) ' Initialize comms for XBee   
  cognew(XB_to_PC,@stack)       ' Start cog for XBee--> PC comms 
  PC.rxFlush                    ' Empty buffer for data from PC 
  repeat                    
    XB.tx(PC.rx)                ' Accept data from PC and send to XBee 
        
Pub XB_to_PC 
  XB.rxFlush                    ' Empty buffer for data from XB 
  repeat                  
    PC.tx(XB.rx)                ' Accept data from XBee and send to PC

I use a single USB cable to first program the sending Propeller, then the receiving Propeller. I then open the Parallax Serial Terminal (PST) with F12. After that I get no display on the PST.

I did see something about a Pass-Thru method. Is that something that is significant to using the Demo Board vs. the USB XBee Adapter?

I appreciate anyone that can get me pointed in the right direction,

falcon

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-26 18:51
    Just to make sure your terminal connection is working properly try changing:
    Pub Start  
      PC.start(PC_Rx, PC_Tx, 0, PC_Baud) ' Initialize comms for PC   
      XB.start(XB_Rx, XB_Tx, 0, XB_Baud) ' Initialize comms for XBee   
      cognew(XB_to_PC,@stack)       ' Start cog for XBee--> PC comms 
      PC.rxFlush                    ' Empty buffer for data from PC 
      repeat                    
        XB.tx(PC.rx)                ' Accept data from PC and send to XBee 
    

    To:
    Pub Start  
      PC.start(PC_Rx, PC_Tx, 0, PC_Baud) ' Initialize comms for PC   
      XB.start(XB_Rx, XB_Tx, 0, XB_Baud) ' Initialize comms for XBee
      [B]repeat
        waitcnt(clkfreq / 2 + cnt)
        PC.str(string(13, "Press any key to start."))
        result := PC.rxcheck
      while result =< 0  
    [/B]  cognew(XB_to_PC,@stack)       ' Start cog for XBee--> PC comms 
      PC.rxFlush                    ' Empty buffer for data from PC 
      repeat                    
        XB.tx(PC.rx)                ' Accept data from PC and send to XBee 
    

    You should at least see:
    Press any key to start.
    Press any key to start.
    

    In the terminal window.

    If you don't then there's a problem with the serial connection/terminal window. If you see the above message then we know to look elsewhere.
  • FalconFalcon Posts: 191
    edited 2012-10-27 04:42
    Thank you for your reply,

    I received a "expected an expression term" error pop-up with the "XB_to_PC" highlighted.

    falcon
  • Mike GreenMike Green Posts: 23,101
    edited 2012-10-27 07:34
    Duane gave you a piece of code to substitute for the existing Start method in your existing program. It won't compile without the rest of the program you originally listed. The message you got is probably due to XB_to_PC being undefined.
  • FalconFalcon Posts: 191
    edited 2012-10-27 08:18
    You are correct Mike. I had replaced everything after Pub Start. I corrected that and now the code loads but I do not get the "Press any key to start." text in the PST . I must have a problem with the serial connection/terminal window as Duane Degn mentioned.

    I changed the USB cable and switched to a different USB port on my PC, I unplugged all unnecessary USB cables. Still no "Press any key to start." text in the PST.

    Here is my step by step process:
    1. Unplug Rx (Prop Demo board with XBee) USB cable
    2. Plug USB cable to Tx (Prop Demo board/XBee/joystick)
    3. Load TX code as seen above.
    4. Move USB cable to Rx (Prop Demo board/XBee)
    5. Load RX code above with snippet from Duane Degn
    6. Click Enable on PST (previously opened)
    7. Press Reset on Rx (Prop Demo board/XBee)

    Still no "Press any key to start." text in the PST.

    I even switched the Prop Demo Boards thinking one was damaged, but that didn't help.

    What could be wrong with the serial connection/terminal window function?

    falcon
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-27 08:55
    When you do step #5 what com port does the Propeller Tool use?

    You want to make sure the serial terminal is set to this same com port. You also want to make sure the serial terminal is set to the correct baud.
  • FalconFalcon Posts: 191
    edited 2012-10-27 09:10
    That was it Duane Degn. The PST was set to the default 115200 but the code was set for 9600. I corrected the baud and reverted back to the original code and the joystick values appeared on the PST as they should.

    I appreciate your and Mike Green's help. It looks like I have a long way to go to become competent with the propeller. I am pretty comfortable with the BS2 but like the idea of multiple processors so I will forge ahead.

    Next step: Convert Joystick values to Pulse Out commands to operate servos.

    Thank you both.

    falcon
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-27 10:24
    I'm glad you got it working.

    The Prop is a great microcontroller for robotics. IMO, it's worth the effort to learn to use it.

    You'll find lots of people willing to help you out.

    Post #15 of my QuickStart servo tester thread has a very simple servo demo program. You might find it useful. There's also a demo program in the Prop Tool's library but I think my version is even easier to understand "official" demo (which is also good demo).
Sign In or Register to comment.