title: Sending Data from Xbee Arduino to PC
body: <p>I have an application where I am using a MCP3421 18bit ADC to read analog data. The setup is Xbee+Xbee Sheild+Arduino + MCP3421 as Transmitter.   This I am reading and transmitting to a remote xbee+arduino module with LCD. The data is displayed fine on the LCD.  however I want to receive the data on the Serial port. When i try tp Do a Serial.println(s); on the receiving code the data which i get on serial port is garbled. Would appreciate any help</p>
  
  <p>Here is my Code</p>
  
  <p>Transmitting</p>
  
  <pre><code>#include  &lt;Wire.h&gt;
  #include &lt;LiquidCrystal.h&gt;
  #define TRUE 1
  #define FALSE 0
  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  void setup(void)
  {
    Serial.begin(9600);
    Wire.begin();
    delay(100);
    Serial.println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;");  // just to be sure things are working
    lcd.begin(16, 2);
  }
  
  void loop(void)
  {
  
    byte address, Hi, Lo, Config;
    int ADVal;
  
    while(1)
    {
      address = 0x68;
      Wire.beginTransmission(address);
      Wire.write(0x88);   // config register %1000 1000
      // /RDY = 1, One Conversion, 15 samples per, PGA = X1
  
      Wire.endTransmission();
  
      delay(1);
      Wire.requestFrom((int)address, (int) 3);
      Hi = Wire.read();
      Lo = Wire.read();
      Config = Wire.read();
      Wire.endTransmission();
  
      ADVal = Hi;
      ADVal = ADVal * 256 + Lo;
  
      //  Serial.print(ADVal, DEC);
      //Serial.print("  ");
      //Serial.println(Config, DEC);
      Serial.print("&lt;");
      Serial.print(ADVal);
      Serial.print("&gt;");
  
  
      //lcd.setCursor(0,0);
      //lcd.print(ADVal);
      lcd.setCursor(0,1);
      //float val = ADVal * 0.00006244087;
      //lcd.print(val,3); 
      delay(1);
    }
  }
  </code></pre>
  
  <p>and this is the receiving code</p>
  
  <pre><code>#include &lt;LiquidCrystal.h&gt;
  LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
  bool started = false;
  bool ended= false;
  char inData[10]; // Leave plenty of room
  byte index;
  float i;
  
  //char inData[24]; // Or whatever size you need
  //byte index = 0;
  
  void setup(){
    // set up the LCD's number of columns and rows: 
    lcd.begin(16, 2);
    // initialize the serial communications:
    Serial.begin(9600);
  }
  
  void loop()
  {
    //Serial.println(s);
    while(Serial.available() &gt; 0)
    {
      char aChar = Serial.read();
      if(aChar == '&lt;')
      {
        // Start of packet marker read
        index = 0;
        inData[index] = '\0'; // Throw away any incomplete packet
        started = true;
        ended = false;
      }
      else if(aChar == '&gt;')
      {
        // End of packet marker read
        ended = true;
        break; // Done reading serial data for now
      }
      else
      {
        if(index &lt; 10) // Make sure there is room
        {
          inData[index] = aChar; // Add char to array
  
          index++;
          inData[index] = '\0'; // Add NULL to end
  
        }
      }
    }
  
    // When we get here, there is no more serial data to read,
    // or we have read an end-of-packet marker
    if(started &amp;&amp; ended)
    {
      // We've seen both markers - do something with the data here
      lcd.setCursor(0,0);
      i = atoi (inData);
      float s = (i * 0.3051851); //multiplying with calibration factor
      float value = ( s / 1000 );
  
      lcd.setCursor(1,0);
      lcd.print(value,3); // print value after multiplying with calibration factor to LCD
  
      lcd.setCursor(0,1 );
      lcd.print(i); // Print raw ADC counts as recieved from transmitter
  
      index = 0;
      inData[index] = '\0';
      started = false;
      ended = false;
  
    }
  } 
  </code></pre>
  
  <p>The receiving arduino do get the data through Xbee and it displays values perfectly on the LCD( Attached PIC). I also need to receive the data on a PC attached to the receiving arduino through its USB/Serial port.</p>
  
  <p>When i try to use the serial monitor the display on LCD vanishes and the serial monitor displays garbled values. I thing the Serial.print(s) is sending back the data to the XBEE  as both the DO and DI LED starts blinking on the XBEE SHIELD.</p>