Shop OBEX P1 Docs P2 Docs Learn Events
Xbee to Xbee Communication // Propeller Activity Board // 2-axis Joystick // C — Parallax Forums

Xbee to Xbee Communication // Propeller Activity Board // 2-axis Joystick // C

arlandiantoarlandianto Posts: 8
edited 2014-10-31 04:57 in Accessories
Hi all,

First of all, I'm quite new to Propeller Activity Board and XBee but I'm quite familiar with C programming.
Right now, I have 2 Propeller Activity Board, 2 Xbee 802.15.4 modules, and a 2-axis joystick.

Then I'm stumbled upon this website: http://tymkrs.tumblr.com/post/28632622791/making-a-2-axis-joystick-wireless-w-xbee
And I would really love to try this with my Activity board but in C Language instead of SPIN Language.

I've followed this tutorial as well: http://learn.parallax.com/propeller-c-simple-protocols/full-duplex-serial
Which is very nice, but I am still can't figure out how to communicate between two activity board in C language.

Any suggestion or help perhaps? There are no many learning tutorials using Xbee and Propeller C that I aware of...
Thank you!

Comments

  • JonnyMacJonnyMac Posts: 9,102
    edited 2014-10-28 22:34
    If you're familiar with C, porting from Spin should be no trouble at all -- dig in and have some fun. I don't like C very much, but I understand it well enough to port C programs to Spin all the time. Essential programming concepts apply across languages.
  • GenetixGenetix Posts: 1,754
    edited 2014-10-29 02:14
    Propeller C is only a year old so that's why most of the code is still in Spin.
    This might help:
    http://learn.parallax.com/propeller-c-simple-devices/joystick

    What exactly is it that you want to do? Usually one device with be the base unit and the other the remote. For example controlling a robot with the joystick.
    This might help but all the examples use Spin.
    http://www.parallax.com/sites/default/files/downloads/122-32450-XBeeTutorial-v1.0.1.pdf

    Here are some other examples:
    http://learn.parallax.com/projects/propeller-C-language
  • ValeTValeT Posts: 308
    edited 2014-10-29 04:01
    Hi all,

    First of all, I'm quite new to Propeller Activity Board and XBee but I'm quite familiar with C programming.
    Right now, I have 2 Propeller Activity Board, 2 Xbee 802.15.4 modules, and a 2-axis joystick.

    Then I'm stumbled upon this website: http://tymkrs.tumblr.com/post/28632622791/making-a-2-axis-joystick-wireless-w-xbee
    And I would really love to try this with my Activity board but in C Language instead of SPIN Language.

    I've followed this tutorial as well: http://learn.parallax.com/propeller-c-simple-protocols/full-duplex-serial
    Which is very nice, but I am still can't figure out how to communicate between two activity board in C language.

    Any suggestion or help perhaps? There are no many learning tutorials using Xbee and Propeller C that I aware of...
    Thank you!

    The following code will allow you to remote control your ActivityBot over XBee wireless. I am going to write a tutorial for this soon; sorry I don't have it done yet!

    Use this link to setup the joystick module. http://learn.parallax.com/propeller-c-simple-devices/joystick

    Please connect the Joystick to A/D pins 2 and 3.

    Here is my code for the Activity Board ( transmitter ):
    //ActivityBoard code here
    
    
    #include "simpletools.h"                      // Include simple tools
    #include "fdserial.h"
    #include "adcDCpropab.h"
    
    
    fdserial *xbee; //Initialize the full-duplex serial connection over XBee
    
    
    int main()
    {
      xbee = fdserial_open( 9, 8, 0, 9600 ); //open the serial connection
      adc_init( 21, 20, 19, 18 ); //initialize the analogue connections for the joystick
    
    
      float lrV, udV; //create 2 float values for incoming joystick values
    
    
      while ( 1 )
      {
        udV = adc_volts( 2 ); //get values from the joystick
        lrV = adc_volts( 3 );
    
    
        if ( udV < 1.00 ) //if joystick going backward, send backward value
        {
          dprint( xbee, "b" );
        } else if ( udV > 4.00 ) //if joystick going forward, send forward value
        {
          dprint( xbee, "f" );
        } else if ( udV < 4.00 && udV > 1.00 && lrV < 4.00 && lrV > 1.00 ) //if joystick is in center, send stop value
        {
          dprint( xbee, "s" );
        } else if ( lrV < 1.00 ) //if joystick is going left, send left value
        {
          dprint( xbee, "l" );
        } else if ( lrV > 4.00 ) //if joysitck is going right, send right value
        {
          dprint( xbee, "r" );
        }
    
    
        pause( 50 ); //only need to check joystick values 20 times a second
      }
    }
    
    

    Here is my code for the other Activity Board ( receiver ):
    //ActivityBot code here
    
    
    #include "simpletools.h"                      // Include simple tools
    #include "fdserial.h"
    #include "abdrive.h"
    
    
    fdserial *xbee;
    
    
    int main()                                    // Main function
    {
      xbee = fdserial_open( 9, 8, 0, 9600 );
    
    
      char c;
    
    
      while ( 1 )
      {
        c = fdserial_rxChar( xbee );
     
        if ( c == 'f' )
        {
          drive_speed( 64, 64 );
        } else if ( c == 'b' )
        {
          drive_speed( -64, -64 );
        } else if ( c == 'l' )
        {
          drive_speed( 0, 64 );
        } else if ( c == 'r' )
        {
          drive_speed( 64, 0 );
        } else if ( c == 's' )
        {
          drive_speed( 0, 0 );
        }
      }
    }
    
  • arlandiantoarlandianto Posts: 8
    edited 2014-10-29 07:26
    Thank you! I'll try to dig in and learn more from those :)
  • arlandiantoarlandianto Posts: 8
    edited 2014-10-29 07:32
    ValeT wrote: »
    The following code will allow you to remote control your ActivityBot over XBee wireless. I am going to write a tutorial for this soon; sorry I don't have it done yet!

    Use this link to setup the joystick module. http://learn.parallax.com/propeller-c-simple-devices/joystick

    Please connect the Joystick to A/D pins 2 and 3.

    Here is my code for the Activity Board ( transmitter ):
    //ActivityBoard code here
    
    
    #include "simpletools.h"                      // Include simple tools
    #include "fdserial.h"
    #include "adcDCpropab.h"
    
    
    fdserial *xbee; //Initialize the full-duplex serial connection over XBee
    
    
    int main()
    {
      xbee = fdserial_open( 9, 8, 0, 9600 ); //open the serial connection
      adc_init( 21, 20, 19, 18 ); //initialize the analogue connections for the joystick
    
    
      float lrV, udV; //create 2 float values for incoming joystick values
    
    
      while ( 1 )
      {
        udV = adc_volts( 2 ); //get values from the joystick
        lrV = adc_volts( 3 );
    
    
        if ( udV < 1.00 ) //if joystick going backward, send backward value
        {
          dprint( xbee, "b" );
        } else if ( udV > 4.00 ) //if joystick going forward, send forward value
        {
          dprint( xbee, "f" );
        } else if ( udV < 4.00 && udV > 1.00 && lrV < 4.00 && lrV > 1.00 ) //if joystick is in center, send stop value
        {
          dprint( xbee, "s" );
        } else if ( lrV < 1.00 ) //if joystick is going left, send left value
        {
          dprint( xbee, "l" );
        } else if ( lrV > 4.00 ) //if joysitck is going right, send right value
        {
          dprint( xbee, "r" );
        }
    
    
        pause( 50 ); //only need to check joystick values 20 times a second
      }
    }
    
    

    Here is my code for the other Activity Board ( receiver ):
    //ActivityBot code here
    
    
    #include "simpletools.h"                      // Include simple tools
    #include "fdserial.h"
    #include "abdrive.h"
    
    
    fdserial *xbee;
    
    
    int main()                                    // Main function
    {
      xbee = fdserial_open( 9, 8, 0, 9600 );
    
    
      char c;
    
    
      while ( 1 )
      {
        c = fdserial_rxChar( xbee );
     
        if ( c == 'f' )
        {
          drive_speed( 64, 64 );
        } else if ( c == 'b' )
        {
          drive_speed( -64, -64 );
        } else if ( c == 'l' )
        {
          drive_speed( 0, 64 );
        } else if ( c == 'r' )
        {
          drive_speed( 64, 0 );
        } else if ( c == 's' )
        {
          drive_speed( 0, 0 );
        }
      }
    }
    

    WOW! THANK YOU!
    This is very helpful!
    Luckily i have one ActivityBot as well and I'll definitely try this one out :)

    Looking forward for your tutorial as well!
  • ValeTValeT Posts: 308
    edited 2014-10-31 04:57
    WOW! THANK YOU!
    This is very helpful!
    Luckily i have one ActivityBot as well and I'll definitely try this one out :)

    Looking forward for your tutorial as well!

    Sorry for the late reply. Recently I've gotten really busy with FTC.

    Thanks! I will have the tutorial posted tomorrow or Sunday.

    Let me know if you have any issues as I am always available to help.
Sign In or Register to comment.