I have a an arduino NANO 33 BLE and I'm trying to get the current time and date. Based on the documentation, the arduino has nRF52840 microcontroller which comes with a 24 RTC timer It is listed in the nordic documentation as well. However, I'm not sure exactly how to use it to get the current time; Based on the MbedOS documentation for Time I wrote out the code to print out the current time and date in conjunction with reading the data:
#include "mbed.h"
#include <Time.h>
#include <RTClib.h>
time_t rawtime;
struct tm *info;
void setup() {
Serial.begin(9600);
}
//resistor val = 100K
void loop() {
rawtime = time(NULL);
time(&rawtime);
info = localtime(&rawtime);
int val = analogRead(A1);
Serial.print(val);
Serial.print('-');
Serial.print(asctime(info) );
delay(5);
}
However it just prints out this:
XX-Thu Jan 1 00:08:30 1970
Where the XX is the correct sensor data. Why is the time not the current time but the beginning unix epoch ? This code was run in the Desktop Arduino IDE in Win10
rawtime = time(NULL); time(&rawtime);acts like setting the time ? Or am I misinterpreting that line of code ?