Read Serial data from an arduino with c code I am trying to receive data through the serial port from my SBC (a TS-7200), i am working with linux and handle serial communication using C/C++.To send data to the SBC  i'am using an arduino uno.

So basically the arduino is printing ASCII text data through Pin1 (Hardware Serial) in a loop with a 3ms delay.

From the SBC i read raw data in no canonical mode, ( in the code below are the parameters and configurations for the serial port) i'am trying to read one characters at a time, following the example from this page :
https:/ from this page/chrisheydrick.com/2012/06/17/how-to-read-serial-data-from-an-arduino-in-linux-with-c-part-3/.

but when i run the code it print the number 2 as 3, and the number 3 as f, I am not able to read ASCII characters.

I have tried several things but I have not been able to find the problem, Hope someone can help me.

Here is the Arduino code:

 #include &lt;SoftwareSerial.h&gt;
 SoftwareSerial mySerial(2,3); // RX, TX  

 void setup() {

    Serial.begin(9600);
    mySerial.begin(9600);

  }

 void loop() {

   Serial.print(2);

   delay(3000);

   Serial.print(3);

   delay(3000);

} 


The c code from the linux side:

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;sys/ioctl.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;termios.h&gt;


char *portname = "/dev/ttyAM1";
char buf[256];

int main(int argc, char *argv[])
{
  int fd,stop = 0;

/* Open the file descriptor in non-blocking mode */
fd = open(portname, O_RDWR | O_NOCTTY);

/* Set up the control structure */
struct termios toptions;

/* Get currently set options for the tty */
tcgetattr(fd, &amp;toptions);

/* Set custom options */

/* 9600 baud */
cfsetispeed(&amp;toptions, B9600);
cfsetospeed(&amp;toptions, B9600);
/* 8 bits, no parity, no stop bits */
toptions.c_cflag &amp;= ~PARENB;
toptions.c_cflag &amp;= ~CSTOPB;
toptions.c_cflag &amp;= ~CSIZE;
toptions.c_cflag |= CS8;
/* no hardware flow control */
toptions.c_cflag &amp;= ~CRTSCTS;
/* enable receiver, ignore status lines */
toptions.c_cflag |= CREAD | CLOCAL;
/* disable input/output flow control, disable restart chars */
toptions.c_iflag &amp;= ~(IXON | IXOFF | IXANY);
/* disable canonical input, disable echo,
   disable visually erase chars,
   disable terminal-generated signals */
toptions.c_lflag &amp;= ~(ICANON | ECHO | ECHOE | ISIG);
/* disable output processing */
toptions.c_oflag &amp;= ~OPOST;

/* wait for 1 character to come in before read returns */
/* WARNING! THIS CAUSES THE read() TO BLOCK UNTIL ALL */
/* CHARACTERS HAVE COME IN! */
toptions.c_cc[VMIN] = 1;
/* no minimum time to wait before read returns */
toptions.c_cc[VTIME] = 0;

/* commit the options */
tcsetattr(fd, TCSANOW, &amp;toptions);

/* Wait for the Arduino to reset */
usleep(1000*1000);
/* Flush anything already in the serial buffer */
tcflush(fd, TCIFLUSH);

while(stop == 0){

  /* read up to 128 bytes from the fd */
  int n = read(fd, &amp;buf, 128);
  usleep(3000*1000);
  /* print how many bytes read */
  printf("%i bytes got read...\n", n);
  /* print what's in the buffer */
  printf("Buffer contains...\n%s\n", buf);
 }
 return 0;
}


This is what i see:

2 bytes got read...                                                              
Buffer contains...                                                               
f                                                                                
2 bytes got read...                                                              
Buffer contains...                                                               
3                                                                                
2 bytes got read...                                                              
Buffer contains...                                                               
f                                                                                
2 bytes got read...                                                              
Buffer contains...                                                               
3
RS232 uses +/- 12V (or sometimes +/- 5V), and is not compatible with TTL Serial, which uses 0V/5V. Also +12V in RS232 represents 0 and -12V represents 1; inverted from normal TTL.