Go Down

Topic: Delimiters of two incoming series 1 Xbees (Read 321 times) previous topic - next topic

danieljay

I have a total of 3 series 1 xbees communicating in transparent mode through serial. Two of them are sending incoming reads and one of them is receiving.  I wanted to separate the incoming values with delimiters to know what value is coming from where.I've gotten up to this point with success.  Problem now is I dont know how to label this incoming values through the receiving Arduino. I simply just want to add something like, "Serial.print("this is the first sensor = "); and so fourth for second sensor. I am just not sure where it is appropriate within the code. here is the code below:

Emitter : (code is the same for both )

Code: [Select]
// Example of sending numbers by Serial
// Author: Nick Gammon
// Date: 31 March 2012

const char startOfNumberDelimiter = '<';
const char endOfNumberDelimiter   = '>';
const int rssi_pin = 9; //RSSI Pin of the XBee Module
int rssiDur;


void setup ()
 {
 //srand (42);
 Serial.begin (38400);
 } // end of setup
 
void loop ()
 {
   
    rssiDur = pulseIn(rssi_pin, LOW, 200); //sending this val
   

 for (int i = 0; i < 10; i++)
   {
   Serial.print (startOfNumberDelimiter);    
   Serial.print (rssiDur);    // send the number
   Serial.print (endOfNumberDelimiter);  
   Serial.println ();
   }  // end of for

 delay (300);
 }  // end of loop




....and the receiver


Code: [Select]
// Example of receiving numbers by Serial
// Author: Nick Gammon
// Date: 31 March 2012

const char startOfNumberDelimiter = '<';
const char endOfNumberDelimiter   = '>';

void setup ()
 {
 Serial.begin (38400);
 //Serial.println ("Starting ...");
 } // end of setup
 
void processNumber (const long n)
 {
   Serial.print("bike 2 = ");
 Serial.println (n);
 }  // end of processNumber
 
void processInput ()
 {
 static long receivedNumber = 0;
 static boolean negative = false;
 
 byte c = Serial.read ();
 
 switch (c)
   {
     
   case endOfNumberDelimiter:  
     if (negative)
       processNumber (- receivedNumber);
     else
       processNumber (receivedNumber);

   // fall through to start a new number
   case startOfNumberDelimiter:
     receivedNumber = 0;
     negative = false;
     break;
     
   case '0' ... '9':
     receivedNumber *= 10;
     receivedNumber += c - '0';
     break;
     
   case '-':
     negative = true;
     break;
     
   } // end of switch  
   
 }  // end of processInput
 
void loop ()
 {
 
 if (Serial.available ())
   processInput ();
   
 // do other stuff here
 } // end of loop

Go Up