Reconstruct uint32_t from char array to RTC.set I am currently experimenting with a Digistump ATTiny85. Since it has no Serial, I use the basic DigiUSB library for communication. The RTC library used is this one: https://github.com/JChristensen/DS3232RTC/. The DigiUSB library is from Digispark.

I attached a DS3232 via TWI to the Digistump, because I want to use this construct as a USB-Realtime-Clock.

Initially setting the time in the setup method works as follows

  RTC.set(1532341020);


But I am unable to transfer the time via the pseudo serial connection and set it remotely. What I've tried so far:


Using union with char and uint32_t. Althougt the char representation is correct (tried DigiUSB.println()), the uint32_t representation of this union is not what I need.
Tried to adapt to some shifting examples, but seriously got lost here. All examples where about 4 byte streams.
atoi and some other functions with no success.


Here is my current sketch

#include &lt;DS3232RTC.h&gt;
#include &lt;DigiUSB.h&gt;

//union ArrayToInteger {
//  char array[10];
//  uint32_t integer;
//};

unsigned char foo[10];
uint32_t num;

void setup() {                
  RTC.begin();
  //RTC.set(1532341020);
  DigiUSB.begin();
}

void loop() {
  if (DigiUSB.available() &gt;= 10) {
    for (int i=0; i&lt;=10; i++) {
    foo[i] = DigiUSB.read();
  }
  RTC.set((uint32_t)foo);
  DigiUSB.delay(100);
  DigiUSB.refresh();
  //DigiUSB.println(_foo.array);
  DigiUSB.println(RTC.get());
} else {
  DigiUSB.refresh();
  DigiUSB.println(RTC.get());
  DigiUSB.refresh();
  DigiUSB.delay(1000);
  }
}


In the end I need the a char _foo 0123456789 represented as/converted to uint32_t num 0123456789

Kinda stuck here. Can anyone point me in the right direction ore provide an example?
There are several possible issues here:


can you send the number, as a string, from the PC to the ATtiny?
can you convert the string to an actual number?
can you give this number to the RTC?


The phrasing of your question sounds like your issue is with the
conversion. However that is easily handled with atol(). Here is a test
program I tried on my Uno:

void setup() {
    char time_string[] = "1532341020";
    uint32_t time_number = atol(time_string);

    Serial.begin(9600);
    Serial.print("string: \"");
    Serial.print(time_string);
    Serial.print("\", number = ");
    Serial.println(time_number);
}


The output is:

string: "1532341020", number = 1532341020