I'm having trouble reading data from my arduino uno on my macbook (macos version 10.14.1) ...
basically, my 1 byte read calls return garbage data ...
the arduino serial monitor, when set to 115200 baud reads the character based input from the arduino fine ...
but I'm having trouble setting that baud rate from my macos basedC program, which is trying to read the device ...
the code below fails on the tcsetattr call with an errno of 22 (EINVAL) ...
I think because the speed value exceeds 38400 bpi ...
(the man page that contains tcsetattr has baud rate values up to 38400 ...)
char *arduino = "/dev/cu.usbmodem14101";
struct termios cucontrol;
speed_t inspeed;
...
fd = open(arduino, O_RDONLY);
if(fd == -1){
printf("cant open %s\n",arduino);
exit(0);
}
if(tcgetattr(fd,&cucontrol) == -1){
printf("ctcgetattr failure errno = %d\n",errno);
exit(0);
}
inspeed = cfgetispeed(&cucontrol);
printf("initial input speed is %d\n",inspeed);
inspeed = 115200;
if(cfsetispeed(&cucontrol,inspeed) == -1){
printf("problem setting speed of %d, errno = %d\n", inspeed, errno);
exit(0);
}
if(tcsetattr(fd,TCSANOW,&cucontrol) == -1){
printf("tcsetattr failure, errno = %d\n",errno);
exit(0);
}
stty -g reveals a baud rate of 115200 when the arduino serial monitor is running ...
and 9600 baud when it is not running ....
I tried setting the baud rate on the arduino side to 9600 via a Serial.begin(9600),
but that seemed to have no effect ....
I don't know how the arduino serial monitor manages to set the baud rate to 115200 ...
suggestions/comments appreciated ...