Unable to read the Serial Port through Arduino the way Serial Port Monitor softwares read it I have a device feeding Rx Tx data every minute. I connected it to the computer. I downloaded a Serial Port Monitor Software, and here is the data I captured using that software.



Now when I try to capture the same data using Arduino, it captures something else as you can see in the image below. I tried reading it as hex, char, byte, unsigned int, but it just doesn't read the data properly.



Here I have provided my code. Can someone please identify the problem for me? I've been stuck on this for 2 weeks at least, and it is just not a good feeling! Any help will be much appreciated.


  Using Arduino Ethernet with microSD Card Slot


//#include &lt;SoftwareSerial.h&gt;
#include &lt;SPI.h&gt;
#include &lt;SD.h&gt;


static const int baud = 19200;
static const int chipSelect = 4;
static const int rx = 0;
static const int tx = 1;


File dataFile;
//SoftwareSerial serialPort = SoftwareSerial(rx, tx);


void setup() {

  Serial.begin(baud);     // opens serial port, sets data rate to 19200 bps
  while (!Serial) {
    ;
  }
  //serialPort.begin(baud);

 // pinMode(rx, INPUT);
 // pinMode(tx, OUTPUT);

   Serial.print("Initializing SD card...");

   if (!SD.begin(chipSelect)) {
       Serial.println("initialization failed!");
       return;
   }
   Serial.println("initialization done.");


   dataFile = SD.open("data.txt", FILE_WRITE);
   Serial.println("Data file created!");
   dataFile.close();
}

unsigned int incomingByte = 0;
void loop() 
{
  if (Serial.available() &gt; 0) {
                // read the incoming byte:
     incomingByte = Serial.read();
     Serial.print(incomingByte, HEX);
    }

  dataFile = SD.open("data.txt", FILE_WRITE);
  dataFile.println(incomingByte, HEX);
  dataFile.close();
}



  You can build the Serial Port Monitor software using C# Console App, here is the code for that:


using System;
using System.IO.Ports;
using System.Text;

class PortDataReceived
{
    public static void Main()
    {

        SerialPort mySerialPort = new SerialPort("COM3");

        mySerialPort.BaudRate = 19200;
        mySerialPort.Parity = Parity.None;
        mySerialPort.StopBits = StopBits.One;
        mySerialPort.DataBits = 8;
        mySerialPort.Handshake = Handshake.None;
        mySerialPort.RtsEnable = true;


        mySerialPort.Open();
        while (true)
        {
            string data = ReadData(mySerialPort);

            if (!string.IsNullOrEmpty(data))
            {
                Console.WriteLine(data);

            }
        }

    }

    public static string ReadData(SerialPort serial)
    {
        byte[] buffer = new byte[serial.BytesToRead];
        serial.Read(buffer, 0, buffer.Length);

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i &lt; buffer.Length; i++)
            sb.AppendFormat("{0:X2} ", buffer[i]);

        return sb.ToString();
    }
}
It's not a good idea to use pins 0 and 1 for SoftwareSerial they are usually connected to Serial