Microseconds Timestamps in serial monitor

Are there anyone who knows to get microseconds timestamps on serial monitor.. I am receiving my data in microseconds. But I only can see the milliseconds timestamps. Can anyone please help me on this...

Hello
Print the result of micros() if this make sense?
The print() function takes some time itself to do.
Have a nice day and enjoy coding in C++.

Probably, yes. Need more detail? Give more detail! Code, schematics, component specs...

I don't think that the Serial Monitor can display with microseconds. Write your own app. Take into account that when your app picks up the data from the underlaying layers of the OS, it might already have been in your PC for e.g. a millisecond (or 5 or 10).

If you want to know when things did happen, do what @paulpaulson suggested and send microseconds from your Arduino code.

it is a voltage reading code. Voltages are varying in microseconds. In that case I want to see it on serial monitor with microseconds timestamps.. Did you get it

How to write a own app. could you please guide me on this

I gave time delay as delayMicroseconds().. Can't I use this,,

I got one tiny bit more, because you gave one tiny bit more. At this rate it will take days of questions and answers until anyone is able to help you, I think.

That doesn't make sense. Your PC-OS isn't a high speed real time operating system. As @sterretje already pointed out, there may be a delay of several milliseconds between sending something from Arduino and receiving it in the serial monitor. So what will you get with a timestamp of microsecond at the PC? And what baud rate are you using? Usually a typical serial connection isn't really a high speed transmission.
As already suggested, only printing the results of micros() may be a solution.

How can I do that.. Please help me

I am receiving an analog signal and I need to show the voltage values on serial monitor of it. It is a very high speed signal and voltages are varying in very high speed ( microseconds). I want to measure each and every values.. But in serial monitor only can see the milliseconds time differences from the timestamps of serial monitor

A normal Arduino needs around 100 us for a single ADC.

What Arduino are you using? And what is really 'high speed' in your case? 1µs? 10µs? 100µs? The AD conversion of a standard Arduino isn't 'high speed'. And also the serial communication between Arduino and PC is not 'high speed'.
Tell a bit more about your analog signal and what you really want to do with it.

@chamathkaa

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.

It will help you get the best out of the forum in the future.

Thank you

You could save micros() value before each analogRead, after adc sampling the elapsed time can be calculated by substracting the saved micros() value from the actual micros(). This way you get only the approx. time elapsed between each analog read and minimize the characters which has to be sent on serial (use at least 57600 baud instead of 9600). If you need timestamp you can create it later in a spreadsheet for example. To speed things up, you could change the ADC clock prescaler (Timing section), but as the post points out, the lowest you should go is 16 (maybe 8). Avoid division in the formula calculating the voltage from the raw value or print out the raw value itself and post calculate the voltage. But as others pointed out, the 1us resolution cannot be reached. Maybe 10-20us with an ATmega328.

What are you planning to do with this amount of data anyway? A cheapo aliexpress 200kHz "oscilloscope" can do better. And you get trigger, measurements, etc.

Ok, #15 actually won't work with 10-20us. :upside_down_face: I did some timing measurements with a scope and direct port manipulation.

1. Suggested 57600 baud is useless in this case, use 2Mbps.

char number[16];
unsigned int rawVal = 0u;

void setup()
{
  Serial.begin(57600);
  //Serial.begin(2000000);
  ADCSRA &= ~(bit (ADPS0) | bit (ADPS1) | bit (ADPS2)); // clear prescaler bits
  ADCSRA |= bit (ADPS2);                               //  16
  pinMode(2, OUTPUT);
}

void loop()
{
  rawVal = analogRead(PIN_A1);
  PORTD |= B00000100;
  Serial.println(rawVal);
  PORTD &= B11111011;
}

~830us with 57600:

~150us with 2Mbps

Some of this 150us is spent on converting the number into ASCII chars.

2. It is faster to convert the raw value to a string with itoa (perhaps better algorithm for conversion, than printNumber in Print.cpp), then print the string:

char number[16];
unsigned int rawVal = 0u;

void setup()
{
  Serial.begin(2000000);
  ADCSRA &= ~(bit (ADPS0) | bit (ADPS1) | bit (ADPS2)); // clear prescaler bits
  ADCSRA |= bit (ADPS2);                               //  16
  pinMode(2, OUTPUT);
}

void loop()
{
  rawVal = analogRead(PIN_A1);
  PORTD |= B00000100;
  itoa(rawVal, number, 10);
  Serial.println(number);
  PORTD &= B11111011;
}

As the ADC clock prescaler was changed, the actual analogRead takes ~16us (Low Pulse Width) and you could get a sample printed every ~90us. I omitted the micros print, because that would further limit the timing, it has to be assumed that the sampling time remains the same (apart from jitter). At this rate the analog signal output impadance has to be low.

And here I am, not knowing why I put effort into this. :slight_smile:

Perhaps of tangential interest is this article by Teensy creator Paul Stoffregen about the performance of the Arduino IDE 1.x Serial Monitor and improvements on it:

https://www.pjrc.com/improving-arduino-serial-monitor-performance/

what about Arduino Uno board...?

Arduino Uno..
Between 10us and 500us receive signal.
I am receiving optical signal. Using a photodiode I convert optical signal into a electrical signal. With the length of my fiber it takes more time ( But everything happen in us time delays). I want to measure the voltages of that electrical signal (It is a analog signal).

115200 baud rate.
How and where to add micros() in this code..

int potPen = A1;
int readValue;
float Voltage;

void setup(){
   pinMode(ponPen,INPUT);
   Serial.begin(115200);
}

void loop(){
  readValue=analogRead(potPen);
  Voltage=(5./1023)*readValue;
  Serial.println(Voltage);
  delayMicroseconds(100);

}

Blockquote