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
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.
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
Ok thank you all! I have attached my screenshots. I think they are working?!
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.
screenshot of how we run the arduino on terminal and print out put
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.
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?
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...
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.
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.