Xbee recive-sent data confuse

NOW IM TOTTALY LOST :/

I read some posts from you Paul and tried to follow those steps. I followed to this , but still too much errors

#include <SoftwareSerial.h>
#include <string.h>
#include <stdio.h>

char store_info;
//char strings[30];
char info[20];
*char pwm;
*char mode;
*char dir;
int pwm_int;
int dir_int;
//int i = 0;
byte index = 0;

char delims[2] = "|";


void setup()
{
  Serial.begin(9600);
}

void loop()
{
 if(Serial.available() > 0)
 {
   
   while(Serial.available() > 0) // Don't read unless
                                                  // there you know there is data
   {
       if(index < 29) // One less than the size of the array
       {
           info = Serial.read(); // Read a character
           info[index] = store_info; // Store it
           index++; // Increment where to write next
           info[index] = '\0'; // Null terminate the string
       }
   }
      
   
   
   pwm = strtok(store_info, delims ); // pwm="231" 
   mode = strtok( NULL, delims ); // mode="F0" 
   dir = strtok( NULL, delims );  // dir = "2"
            
   
   pwm_int=atoi(pwm);      //convert to int
   dir_int=atoi(dir);      //conbert to int

  }
}
*char pwm;
*char mode;
*char dir;

The * NEVER goes before the type.

char store_info;

You can't store the whole string in a char. This needs to be an array.

           info[index] = store_info; // Store it

Backwards. You want to store info in store_info.

I changeg them , i hope you find it correct now friend :slight_smile:

#include <SoftwareSerial.h>
#include <string.h>
#include <stdio.h>

char store_info[30];
//char strings[30];
char info[30];
char *pwm;
char *mode;
char *dir;
int pwm_int;
int dir_int;
//int i = 0;
byte index = 0;

char delims[2] = "|";


void setup()
{
  Serial.begin(9600);
}

void loop()
{
 if(Serial.available() > 0)
 {
   
   while(Serial.available() > 0) // Don't read unless
                                                  // there you know there is data
   {
       if(index < 29) // One less than the size of the array
       {
           info[index]= Serial.read(); // Read a character
           store_info[index]=info[index];  // Store it
           index++; // Increment where to write next
           info[index] = '\0'; // Null terminate the string
       }
   }
      
   
   
   pwm = strtok(store_info, delims ); // pwm="231" 
   mode = strtok( NULL, delims ); // mode="F0" 
   dir = strtok( NULL, delims );  // dir = "2"
            
   
   pwm_int=atoi(pwm);      //convert to int
   dir_int=atoi(dir);      //conbert to int

  }
}

First program sends correct the data

Please if someone has the knownledge to help i will be pleased…

My problem is to merge 3 variables to 1 string and send it via Xbee and arduino, then i get it on other arduino via Xbee and extrack its variable to new one. I managed via help from guys here to merge the info and send it but cant get it and de-merge it.

P.S: Tx/Rx lights on Send-Arduino blinking only if i use usb-cable , with 9V battery they not … hmm

Send-Program and what shows on screen ( seems is correct )

#include <string.h>
#include <stdio.h>
char info[30] ;  // the whole info merged  
int pwm=231;     // will take values 0-255
char *mode="F0";  // will take values "FO" or "BO"
int dir=2;       // will take values 1 or 2 or 3
int n;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
    n=sprintf (info,"%d|%s|%d", pwm, *mode, dir); // info="231|F0|2"
    Serial.println(info);
    delay(4000);
}

Photo URL : https://imageshack.com/i/3ol11yj

Recieve/De-merge Program

#include <SoftwareSerial.h>
#include <string.h>
#include <stdio.h>

char store_info[30];
//char strings[30];
char info[30];
char *pwm;
char *mode;
char *dir;
int pwm_int;
int dir_int;
//int i = 0;
byte index = 0;

char delims[2] = "|";


void setup()
{
  Serial.begin(9600);
}

void loop()
{
 if(Serial.available() > 0)
 {
   
   while(Serial.available() > 0) // Don't read unless
                                                  // there you know there is data
   {
       if(index < 29) // One less than the size of the array
       {
           info[index]= Serial.read(); // Read a character
           store_info[index]=info[index];  // Store it
           index++; // Increment where to write next
           info[index] = '\0'; // Null terminate the string
       }
   }
      
   
   
   pwm = strtok(store_info, delims ); // pwm="231" 
   mode = strtok( NULL, delims ); // mode="F0" 
   dir = strtok( NULL, delims );  // dir = "2"
            
   
   pwm_int=atoi(pwm);      //convert to int
   dir_int=atoi(dir);      //conbert to int

  }
}

Cant understand whats going wrong, any ideas or other method to send 3 differend variable ;

Last note: I have set up both xbee S1, i also tested them by sending packets with X-TCU to arduino and worked perfect.So i think devices are correct setup

SOLVED.

send program

#include <string.h>
#include <stdio.h>
char info[30] ;  // the whole info merged  
int pwm=231;     // will take values 0-255
char mode='F';  // will take values "F" or "B"
int dir=2;       // will take values 1 or 2 or 3
int n;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
      n=sprintf (info,"<%d|%c|%d>", pwm, mode, dir); // info="<231|F0|2>"
    Serial.println(" -- merged info -- ");
    Serial.println(info);
    for(;;);                 // stay here, delete it if you want continue or whatever
}

Recieve program

#define SOP '<'
#define EOP '>'
char *pwm;
char *mode;
char *dir;

bool started = false;
bool ended = false;

char inData[80];
byte index;

void setup()
{
   Serial.begin(9600);
   // Other stuff...
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    char inChar = Serial.read();
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       ended = true;
       break;
    }
    else
    {
      if(index < 79)
      {
        inData[index] = inChar;
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet
    
   pwm = strtok(inData,"|"); // pwm="231" 
   mode = strtok( NULL,"|"); // mode="F0" 
   dir = strtok( NULL,"|");  // dir = "2"
   int val = atoi(pwm);
   int vel= atoi(dir);
   Serial.println("-- extract variables from info -- ");
   Serial.print("PWM value = ");
   Serial.println(val);
   Serial.print("Mode : ");
   Serial.println(mode);
   Serial.print("Direction = ");
   Serial.println(vel);
   for(;;);                     // delete it if you want  to continue
   
   // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
  // delay(1000);
}