Go Down

Topic: Who needs a Software Real Time Clock? (Read 12 times) previous topic - next topic

daveparker

Greetings! I'm just starting to mess around with the Arduino and I ran into a problem with the SetArduinoClock example from the DateTime library. Specifically, the Processing part of the example that reads a time code back from the Arduino to display a small analog clock on screen seems to be mangling the timecode header byte. The byte is sent from the board as 255 but ends up getting mangled by the call to myPort.readStringUntil(LF);

I came up with some alternate code that works and I wanted to share it.

[font=Courier New]void serialEvent(Serial p) {
 byte[] inBuffer = myPort.readBytesUntil(LF);
 if(inBuffer == null || inBuffer.length == 0) {
  return;
 }
 if(inBuffer[0] == byte(TIME_HEADER)) {
   int val = 0;
   long time = 0;
   for(int i = 1; i <= 10; i++)        
     time = time * 10 + (inBuffer - '0');
   UpdateClock(time);
 } else {
   print(new String(inBuffer));
 }        
}[/font]

I'm running Processing V. 1.03 on a Mac. I'm posing this here as the DateTime wiki page linked to this forum. I also couldn't send a direct message to the PM contact as I have a posting count of 0...until I click Post in 3, 2 , 1.... :)

mem

Hi Dave, what symptoms are you seeing? I am running processing 1.01 (on windows) and the playground code works fine for me.  But I am happy to make the change from strings to a char array if it fixes the problem for you. I am curious however to know what exactly is the problem.

alokme

i'm working on arduino severino
it have serial input, so i changed baud rate to 9600
i'm able to upload successfully, but no output from serial port is coming

mem

You don't say if you get output with other sketches.

Try adding a print statement in setup to see if you can get that output
 Serial.println("Setup Complete");

If you see that but nothing else then your Arduino is detecting the message to set the time. Make sure both sides are using 9600 baud and that you have selected the correct com port in Processing

Todd Houstein

I'm still waiting for my first Arduino in the post, so excuse my ignorance...

I'm looking to use the software real time clock in my first project as I need to trigger a function twice a day at certain times. I'm also looking at using the watchdog timer and sleep functions to save energy (http://interface.khm.de/index.php/lab/experiments/sleep_watchdog_battery/).

Are the two compatible, or is there some way to make them compatible? I realise that I might need to use a different sleep mode than that used in the example linked to above (maybe "power save" mode instead of "power down" mode).

Any help would be appreciated!

Go Up