I'm a beginner at Arduino and serial port programming. I'm trying to communicate with my Uno over USB to read a varying voltage, and gather a bunch of data points of (time, voltage). The sketch just calls Serial.println in loop(), sending the current millis() time, and a voltage. On my laptop I have a C program that opens the serial port, reads the lines. They look like:
1300 450
1302 451
1305 449
This seems to work, except right when the program starts, it sees some lines like:
16375 485
16405 483
138 480
16167 484
0 484
23 483
... now it's fine ...
The times appear to be high, mixed with junk, and then reset to 0. Does this mean the board is crashing and restarting?
Is there a buffer overflowing somewhere? I'm guessing this isn't the right way to use a serial port. Maybe there has to be back and forth? And one side can only send when the other says it's ready?
Is there a buffer overflowing somewhere? I'm guessing this isn't the right way to use a serial port. Maybe there has to be back and forth? And one side can only send when the other says it's ready?
Be nice to see some code, to know what is happening.
Nothing will be sent by the program until the serial port is ready. No handshaking is required to make that happen. The millis() value is increasing, from reset on. It does not take a while to stabilize. Whatever is defining the voltage might.
The only read possibility is in your code, which we can't see.
I think in C I have to set the baud rate after it's opened, since I call tcsetattr with the fd and the options that include the baud rate.
points is really a member variable, and that gets free'd. I declared it local for posting this code. I just cleaned up the fd problem you mentioned, but the original problem persists.
The board is probably resetting when the USB serial port is opened.
This is part or all of my problem. I’ve changed my sketch to do Serial.println("starting") in setup(), and the code on the computer looks for that before reading data. So far it’s working.