Can't get my terminal to print a .csv file with high baud rate

Hello all, I'm running the following arduino code (from Arduino UNO), and I've increased my baud rate form 9600 to 115200.

//int sensorValue_1;  // variable to store the value coming from the sensor
//int sensorValue_2;
//int sensorValue_3;
//unsigned long time1;
//unsigned long time2;
//unsigned long time3;

void setup() {
  Serial.begin(115200);          //  setup serial
}

void loop() {
  // read the value from the sensor:
  //analogRead(A0);
  //delay(2);
  Serial.print(analogRead(A0));
  Serial.write(' ,');
  Serial.print(millis());
  Serial.write(' ,');

  //analogRead(A1);
  //delay(2);
  Serial.print(analogRead(A1));
  Serial.write(' ,');
  Serial.print(millis());

  Serial.write('\n');
}

When I run this code, I can get the Arduino its self to record at this speed and it's no problem! The only issue is that when I try to print this output as a .csv from my terminal

cat /dev/cu.usbmodem1411 -b 115200 > ~/Desktop/out.csv

I get weird symbols that aren't the numbers I'm expecting. It works fine at a baud rate of 9600 but nothing higher. Any suggestions on how to print out this output from Arudino using regular numbers?

The Arduino is working but your computer cannot keep up. Solution if you can kill other processes that are using the CPU. If you cannot do that a faster computer or back to the old baud.

even though we can read it in the Arduino program? like we see the numbers going by! So just need it to print out.

If your computer is really receiving at 115200, you could send it to a file, or use a terminal program, which will have been written optimally for high baud rates. Then inspect the content afterwards. I'm surprised your screen isn't keeping up, though.
When you see garbage characters, I suspect it's more likely you've either got a baud mismatch, or what you're seeing on the Arduino is not what your sending, for whatever reason.

We are using the terminal and that's slowing it down we think. Do you know of a program that can run Arduino code and also save the file? Or save the output directly from Arduino? We are newbies here :slight_smile:

On linux, I use GTKTerm to log files of serial data at serial Baud rates much higher than 115200. On Windows, PuTTY and TeraTerm work great.

3 Likes

This is one of the few times where I'd actually request a screenshot, to verify what you are seeing.

1 Like

Ok thank you all! I have attached my screenshots. I think they are working?!

  1. the screenshot of the arduino code so you can see baud rate and that the Arduino is collecting data in the background, I assume at the correct baud rate.
  2. screenshot of how we run the arduino on terminal and print out put
  3. screenshot of the actual output where it starts to record, then gets to be garbage after a bit. I will not that lines 1-15 are what we usually get, and those weird numbers there typically stop after some burn in time. So we just cut that out typically when analyzing. But the weird characters starting at line 16 aren't usual.

Does that help??



oops, reply is above but you might not be tagged.

One other thing you can do that might come in handy elsewhere is to wire an SD module or adapter (the full size SD "sleeve" for microSD, solder wires to those contacts, ask about Voltage Leveling to DIY your own Arduino--SD adapter cheap!)

and then write your data to SD.

if you are slewing loads of fast data, print to screen will be useless anyway. You might need a media reader/writer for the PC but those worth having! SD for remote data loggers is Sweet!

If your contacts need brightening (cause corroded), a soft pencil eraser is good. Insert and remove the brightened contacts a few times to wipe the oxide off the inside contacts then erase again if it acts maybe-ish. Consider that your phone uses microSD and how often do those contacts need cleaning?

fix this, everywhere. Should be
Serial.write(" ,");

how does the difference in "/' make a difference for one baud rate and not the other?

Don't know, but doing something incorrect should be corrected. Serial write expects a null-terminated string, the way you're using it, or a single literal, a char, 'c',
If you don't know the difference there, it's time to hit the books. No slight intended.

edit - Since you came here looking for help, maybe try it, and see if it helps?

For one thing, writing garbage into the serial buffer is sooner or later going to result in garbage out. So there's that. The rubbish you're seeing later in the run is typical of a serial buffer run amuck, transmitting whatever it finds in memory. So...

awesome ok someone else suggested this too so we'll try it!

Serial.print( string pointer ) expects a null terminated string.
Serial.write( char ) expects a single char.

For beginners, every array name is a pointer to the start of the array.

IF the Arduino serial output buffer fills, execution blocks except to transmit and finish buffering output until there is space in the buffer. Arduino should print chars.
At the PC end however I can only guess what happens.

The second screenshot shows the terminal still set to 19200.

1 Like

well spotted!

Thanks, @J-M-L , I've never written a line of serial code.
Please have Arduino update this page to reflect your view.

What our OP had was Serial.write(' ,'); which was clearly an attempt to send a space character and a comma as a string. But, what happens with the compiler when you give it two characters within single quotes like that? You tell me, I'm not going to go test it. Instead, I attempted to give him a legal way to get his two characters printed, as a valid " ," string, as per the Serial.write(str); documentation.

I'm out of here. Take it away, batman!

Right! I only use Serial.write() to transmit ASCII values but

please note that Serial.write( buf, len ) does not expect a null terminated string though sending nulls may end transmission.
It sends data as bytes.

buf : an array to send as a series of bytes.
Note that it does not say byte array or char array, try it array!

But you are right, it's NOT just for sending chars and can send strings!