Different sort of time stamp needed

Hello All.

An Arduino newbie here, hope u all r well.

I am reading the 'z' axis value from my accelerometer.
Everything is fine and running normally.

As you can see, the timestamp is basically my local geographic time that is probably being taken from my windows OS clock.

Anyway, I would like the local time replaced by some sort of 'milliseconds-elapsed-since-the-sketch-begin' kind of a time stamp.

Right now, my terminal displays this:

20:15:53.414 -> 420
20:15:55.501 -> 419
20:15:57.612 -> 419
20:15:59.710 -> 419
20:16:01.806 -> 420
20:16:03.893 -> 421
20:16:06.014 -> 421
20:16:08.117 -> 420

I would like it instead display something like this:

1 -> 420
2 -> 419
3 -> 419
4 -> 419
5 -> 420
6 -> 421
7 -> 421
8 -> 420

Where 1 thru 8 are the number of milliseconds or microseconds or whatever that have elapsed since the code began. ( It can be any arbitrary start point in time )

All I am looking for is a way to measure the amount of milli seconds or micro seconds that have elapsed between the 'z' axis readings.

This will help me later when I graph this data in excel where I can have a 'milliseconds-elapsed-since-the-sketch-begin' versus 'z' axis output graph.

Ty for the help and replies!

( Excel's Data Streamer is not working for me. When I click on 'Connect a Device', it is asking me to check if the device is connected to the computer. The Arduino is definitely connected and I plugged and unplugged the Arduino a few times! )

#include "ADXL335.h"
ADXL335 accelerometer;

void setup() {
  Serial.begin(9600);
  accelerometer.begin();
}

void loop() {
  int x, y, z;
  accelerometer.getXYZ(&x, &y, &z);
  Serial.println(z);
  delay(2000);
}

How about something like this:

void loop() {
  int x, y, z;
  accelerometer.getXYZ(&x, &y, &z);
  Serial.print(millis());
  Serial.print(" -> ");
  Serial.println(z);
  delay(2000);
}

You are in luck! That is exactly what the millis() function does.

Be sure to use unsigned long integer constants and variables with millis().

This is the OP. Ty all 4 the feedback. I will use the following code. It works.
Ty again.

#include "ADXL335.h"
ADXL335 accelerometer;
unsigned long startMicros; // Variable to store the start time in microseconds

void setup() {
  Serial.begin(9600);
  accelerometer.begin();
  startMicros = micros(); // Record the start time
}

void loop() {
  unsigned long elapsedTime = micros() - startMicros; // Calculate elapsed time
  
  int x, y, z;
  accelerometer.getXYZ(&x, &y, &z);
  
  //Serial.print("Elapsed Time (microseconds): ");
  Serial.print(elapsedTime);
  Serial.print(" ");
  Serial.println(z);
  
  //delay(2000);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.