Blockly and Xbee sending and receiving multiple variables

graffixgraffix Posts: 388
edited 2020-01-28 - 14:36:16 in Learn with BlocklyProp
Ive put together some code in blockly. So far Ive done a few things. Im trying to get all of the things assembled into two codes for a receiver and transmitter for a robot. I had it working. I was able to drive around. I then added some pushbuttons to the controller side of code. Ive used the serial terminal to see the code is doing as it should. Which it is. I dont think the sending and receiving portion of code is correct though. I receive one variable and then zeros for the rest. The one that comes through now doesnt change when the joystick is pressed either. Basically I have a Prop Boe for the controller. Using Rc time to read values from the two joysticks. Which are only using the Up/Down on each. There are two push buttons and two leds tied to each. That gives me 4 different modes the controller could be in. Zero leds on is mode 1, 1 led on is mode 2, the other is mode 3, lastly both on is mode 4. Then send that to the receiving Arlo. Im trying to work in sections and add on elements. Adding the pushbutton routine messed up what I had working for just driving it around. The Arlo is using a Prop activity board WX. I have the Arlo kit built and tested. There is one standard servo at the moment with a ping attached. So Id like to drive the Arlo using the two joysticks in a tank style steering as mode 1. When in mode 2 Id like one joy stick to control the servo instead of the drive system. While sending back ping distance be displayed on a lcd. I think my section of code for sending needs adjusted so I keep receiving the right numbers though. Can someone show me using blockly how I can send this and receive it to work with?

Comments

  • Just a guess but remove the "then a carriage return" checkmarks from all but the last of the Xbee Transmit blocks... Your input format in the receiver is expecting 6 decimal values without carriage returns between them.

    dgately
  • Thanks, removing the carriage returns I got this for results. I was looking into trying to packet the variables and send. Im not sure what the xbee is expecting to differentiate the next value. At first I thought the carriage returns were it. It may be an " ! " Then Id have to figure out how to block it out if it is that.
    1257 x 438 - 76K
  • dgatelydgately Posts: 1,303
    edited 2020-01-27 - 05:27:06
    Hmm... Put the checkmarks back in. You could try separate XBee receive blocks for each of the variables. Note: check the C code created with the "Code" button. It translates the XBee Receive into a C dscan command. I guess that the XBee transmit command needs either a carriage return or some whitespace between the sent decimal values.

    Try something like this for receiving each value:
    testMe.png
    1340 x 748 - 158K
  • That worked, I edited the arlo receiver code to something like that and Im receiving everything and the code works again. Thank You.... Now sadly I gotta try adding some more function to things and parts into the mix.
  • Are you or anyone else familiar with sending packets and confirming they were sent or the guard time of the xbees? Im reading the programming and customizing the propeller-chapter 5 and looking to apply some of that to my code using Blockly. Wouldnt sending the info in a single line help condense the code and make back and forth communications better? How would I go about that?
  • dgatelydgately Posts: 1,303
    edited 2020-01-29 - 02:06:32
    My experience with something similar...
    An XBee controller on a Propeller Project Board USB #32810 (has buttons and a joystick for control)
    An XBee on a Propeller Activity Board #32912, on a wheeled Parallax Stingray Robot frame

    As luck would have it, the program was written in Spin, and I was able to use JonnyMac's "HumanFriendlyControlProtocol" object. That object handles the processing of numeric and text data to/from any source (serial, XBee, etc...). Since you are using Blockly Prop, I'll just give you the jest of what might be done:
    Create a simple message protocol that you can parse easily. Keep it very simple, but use some key symbols that will allow you to debug that the message received is equal to the message sent:
    
      A symbol that identifies that start of a message (">"?)
      A delimiter to be used between data fields (comma?)
      A code to identify the message type (numeric, text, etc...)
      Since you will use a single line per packet, assume a carriage return as end-of-message
    
    
    Example string to send a numeric command code (works great for 10 numeric commands 0-9, but is expandable with numeric parsing of values greater than 9):
    
        ">,N,1"   '  Assume that ">" is the message-start
                      '  "," as delimiter
                      '  N says numeric value to follow
                      '  "," as delimiter
                      '  1 is a command value. Will need "scan string" to get a decimal value for this field
    
    You could expand this to include a number of numeric fields (commands) each separated by a comma.
    
    Text example:
    
        ">,A,a_text_command"   '   ">" is the message-start
                                              '  "," as delimiter
                                              '  A says alphabetic value to follow
                                              '  "," as delimiter
                                              '  a_text_command   ("move-foward", "turn-right", etc...)
    
    Note: You can simplify by removing the message-start, but I leave them in because I can easily see them within a digital logic probe during testing. 
    
    On the Receiving side, you would need to read in the string from the XBee (as you've done in your example), but will need to parse through the string, looking for '>', reading beyond any ","s, determining numeric (N) or text string (A), then gathering the data field(s) and processing the sent command(s).
    
    Start with simple numeric commands and use Blockly's Operators|Strings|split string OR scan string to 'parse' each field of the command string. Once you have the sent command value use the Blockly case block to process the command.
    

    Very simplified example... You'll want to check the msg-type before the case block...
    parseCmd.png
    dgately
    793 x 274 - 134K
Sign In or Register to comment.