Go Down

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

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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy