Shop OBEX P1 Docs P2 Docs Learn Events
wireless serial servo control — Parallax Forums

wireless serial servo control

this is probably a simple oversight on my part but i am at a road block, I have two propeller boards both connected to transceivers rx p0 and tx p1, the end result is to send a number between 100 and 1800 from board 1 to board two and control a servo. i believe my problem is with board two with combining the incoming" 1,8,0,0" into "1800" so that servo_angle(11, servo); can use it. any suggestions? thanks.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    You will probably want to post your code so we can see what is happening.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2016-06-06 16:36
    Are you sending ASCII characters? Are you sending some kind of terminator so that the receiving end knows you're done? Do you have some kind of framing character so that your receiving end knows you're sending a new command. Do you have more than one servo on the receiving end?

    Here's a simple method that waits on a number via ASCII characters from your serial input. Any non-digit character will cause it to end.
    pub get_value | value, c
    
      value := 0
    
      repeat
        c := serial.rx
        if ((c => "0") and (c =< "9"))
          value := (value * 10) + (c - "0")
        else
          return value
    

    Edit: Whoops, my code is in Spin, the Propeller's native language (because you hadn't yet posted code or specified language when I originally responded). Still, any C programmer should be able to convert my simple method -- C is, after all, the superior language. Right? ;)
  • i have tried more ways than i can remember,
    transmit = fdserial_open(0, 1, 0, 9600);

    dprint(transmit,"%d%c",servo1, 13);

    dprint(transmit,"%c%c",servo1, 13);

    dprint(transmit,"%c",servo1);

    dprint(transmit,"%d%d%d%d%d%d%d%d", A[0],A[1],A[2],A[3],A[4],A[5],A[6],A[7]);

    yes there are multiple servos.
  • sorry i am using simpleide
  • bnikkelbnikkel Posts: 104
    edited 2016-06-06 16:42
    here is my the last version of my transmitting code,
  • bnikkelbnikkel Posts: 104
    edited 2016-06-06 16:56
    i receive everything i send, so i believe my problem is with how i am storing the received information,

    servo1 = fdserial_rxChar(receive)
    servo1 = fdserial_rxCheck(receive)

    char servo1;

    char servo1[4] = {0,0,0,0};
  • here is my tx and rx code, i know the rx code is only receiving one byte at a time, so i guess my problem is when i have tried to store the 1745 in an array.

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

    fdserial *transmit;

    int servo1;


    int main() // Main function
    {

    //RX TX
    transmit = fdserial_open(13, 14, 0, 9600);

    servo1 = 1745;


    while(1)
    {

    dprint(transmit,"%d",servo1);
    pause(100);


    print("--%d --%c \n",servo1,servo1);

    }
    }









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

    fdserial *receive;



    char servo1;


    int main() // Main function
    {


    //RX TX
    receive = fdserial_open(0, 1, 0, 9600); // p0-p1 trancever


    while(1)
    {

    servo1 = fdserial_rxCheck(receive);


    print("--%d --%c \n",servo1,servo1);


    // servo_angle(11, servo1);

    }
    }




  • AribaAriba Posts: 2,690
    edited 2016-06-06 21:45
    If you send with dprint then the value is sent as decimal ASCII characters, so that a human can read it. The number of sent characters depend on the value, which makes the receiving part unnecessary complicated.

    You have values between 100 and 1800, this fits well into 16bit (= 2 bytes). It even fits in a 14bit range (0..16383) , so you can send it as two 7bit "bytes". The spare bit in a byte can then be used as a Sync marker.

    Here is a -not tested- possible code for your two Main routines:
    // Transmit a 14bit value:
    
    int main()
    {
      int servo1;
      transmit = fdserial_open(13, 14, 0, 9600);
      servo1 = 1745;
    
      while(1)
      {
         fdserial_txChar(transmit, 0x80);           //send a Sync-Byte
         fdserial_txChar(transmit, servo1 >> 7);    //send Higher 7 bits
         fdserial_txChar(transmit, servo1 & 0x7F);  //send Lower 7 bits
         pause(100);
         print("sent: %d \n",servo1);
      }
    }
    
    ---------------------------------
    
    // Receive the 14bit value:
    
    int main()
    {
      int serval;
      receive = fdserial_open(0, 1, 0, 9600);  // p0-p1 trancever
    
      while(1)
      {
        while(fdserial_rxChar(receive) != 0x80) ;   //wait for Sync Byte
        serval = fdserial_rxChar(receive) << 7;     //get Higher 7 bits
        serval += fdserial_rxChar(receive) & 0x7F;  //get and add Lower 7 bits
        print("got: %d \n",serval);
    
    //  servo_angle(11, serval);
    
      }
    }
    

    Andy

    (btw. use the capital C icon in the Forum-Editbox to post code)
  • Thank you so much for your help, i added your code to all the other code i already have and now everything is working perfect,
Sign In or Register to comment.