I'm new in the Arduino world and i try to send serial data via a c++ comandline application (from a mac) to the arduino. I try to send 8 digits in a string and display them on 8 7segment displays. everything works fine as long i send the string direct from the arduino serial monitor. wen i try to send the data from the c++ app the leds on the arduino board (mega2560) starts to blink (like the board receives data) but nothing happens on the displays. as soon as i open up the serial monitor in arduino, everything works fine again, and the data from the c++ app is displayed on the 7segments.
can anyone help me with that please
but nothing happens on the displays. as soon as i open up the serial monitor in arduino, everything works fine again
Your C++ application is not setting all the attributes of the serial port correctly. The Serial Monitor does. Opening it corrects the mismatch, and allows data to be sent properly.
All you need to do is set the serial port attributes correctly.
Thanks for your quick answer. i can connect to the serial port via two ways:
i am not shure wich one are the right, but both react as the same. i remember that i never had this problem before with my old arduino nano board.
i can connect to the serial port via two ways:
Which is, of course, irrelevant. What is relevant is the code you are using.
the code on my mac comandline tool looks like this:
const int BUFFER_SIZE = 8;
int sendHDG = 1612;
using namespace std;
void init_port(int *fd, unsigned int baud)
struct termios options;
case 9600: cfsetispeed(&options,B9600);
case 19200: cfsetispeed(&options,B19200);
case 38400: cfsetispeed(&options,B38400);
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
fd = open("/dev/tty.usbmodemfa121", O_RDWR | O_NOCTTY | O_NDELAY);
if(fd == -1)
perror("open_port: unable to open port");
init_port(&fd,9600); //set serial port to 9600,8,n,1
write(fd, "12345678", BUFFER_SIZE);
ok, after some hours of searching, i finally find the solution:
- Disable Auto Reset
- Give some Delay after the port is open