Baud rate Arduino/Linux I'm trying to communicate some numbers between a Linux program and my Ardunino Uno. To this end I wrote a C++ program which somehow contains:

#include &lt;stdio.h&gt;

int a,b;
a = 1;
b = 2000;

File* serial = fopen("/dev/ttyACM0","w");
fprintf(serial,"%d,%d\n",a,b);
fclose(serial);


Now out of standards I guess, the baud rate is 9600 bit/s. If I use stty -F /dev/ttyACM0 115200 I can change the baude rate of that port to 115200 bit/s. However the communication does not work anymore. My arduino program waiting for number,number does not show any action to the same code as before. Oh, and in the Arduino program of course I changed the code to serial.begin(115200);.

How can I change the baude rate in such a setup? If it is a concern, I'm using Ubuntu and an Arduino Uno.
Setting baud rates in a C program isn't a trivial task. You need to use the low-level open() instead of fopen() and act on the returned file descriptor with ioctl() or tcsetattr() / tcgetattr().  The former method allows the setting of non-standard baud rates while the latter only allows specific baud rates to be used.

I wrote a C++ class to deal with it all for me a while back. You are welcome to examine the methodology and/or steal whatever bits of it you like to use in your own program.


https://github.com/majenkotech/SerialPort