time values sometimes incorrect...

Hello all,

In a project I have a very strange problem. Sometimes (couple times a week) I get very strange values when reading the time from a DS1307.

This is a peace of the code I’m using:

int uur, minuut;

int TijdUurZonOpkomst = 7;
int TijdMinZonOpkomst = 30;

int TijdUurZonOndergang = 20;
int TijdMinZonOndergang = 45;


int OnTime = (TijdUurZonOpkomst * 60) + TijdMinZonOpkomst; //Zon opkomst om 7:30 uur
int OffTime = (TijdUurZonOndergang * 60) + TijdMinZonOndergang; //Zon ondergang om 20:45 uur

DateTime now = rtc.now();

uur = now.hour();
minuut = now.minute();
int NowTotal = (uur * 60) + minuut;


    if (NowTotal >= OnTime && NowTotal <= OffTime){
      if (MegaRay == false){
        digitalWrite(relais_1, LOW); //MegaRAY aan
        MegaRay = true;
        Serial.println("MegaRAY_aan");
        upload_text("MegaRAY_aan");
      }
    }else{
      if (MegaRay == true){ 
        digitalWrite(relais_1, HIGH); //MegaRAY uit
        MegaRay = false;
        Serial.println("MegaRAY_uit");
        upload_text("MegaRAY_uit");
      }
    }



void upload_text(String message)
{ 
   if (client.connect(server, 80)) {
    //Serial.println("connected");
    
    String StrUur = floatToString(buffer, uur, 0);
    String StrMinuut = floatToString(buffer, minuut, 0);
    
    String message2 = StrUur + "_" + StrMinuut + "x" + message;
    
    client.println("GET /~someServer/Atmoz/test.php?temp=" + message2 + " HTTP/1.0");    
    client.println();
    client.stop();
  } 
  else {
    Serial.println("connection failed");
  } 
}

Most of the time everything works great. But then, once in a while I get strange values in

StrUur and in StrMinuut. They are: 165 at that moment.
In the logging (from the PHP script) it looks like:

“165_165xMegaRAY_uit”

While normally, if everything works fine it says something like

“20_45xMegaRAY_uit”

Does anyone know what the fault can be?
Is it an non accurate output from the DS1307 RTC?

Thanks in advance for the help 8)

Atmoz

Is it possible you could be getting noise on the I2C bus?

What value pull-up resistors are on SCL and SDA?

MarkT:
Is it possible you could be getting noise on the I2C bus?

What value pull-up resistors are on SCL and SDA?

Maybe that's possible :slight_smile:

I don't use (external) resistors because I thought they were already on the shield I use:
http://www.ebay.com/itm/I2C-DS1307-Real-Time-Clock-Module-For-Arduino-Tiny-RTC-2560-UNO-R3-New-/351100788809?pt=LH_DefaultDomain_0&hash=item51bf3ce049

Are'nt they?

[edit]
And if not: shouldn't they? ]:smiley:

[edit2]
I use VERY short wires from the DS1307 shield to the Arduino. Let's say 5cm each...

Regards,

Atmoz

Hmzzz, there are more people with the "165" problem:

But it's not clear WHY this problem exists...

Anyone more ideas?

I suggest you write a test sketch that only reads the time from the RTC at regular intervals and logs it with as little manipulation of the time values as possible. Don't use the String class to do it.

Once you have some logs showing the error, you can see whether there is any pattern to when the errors happen, or any pattern to the spurious values the errors give you.

PeterH:
I suggest you write a test sketch that only reads the time from the RTC at regular intervals and logs it with as little manipulation of the time values as possible. Don't use the String class to do it.

Once you have some logs showing the error, you can see whether there is any pattern to when the errors happen, or any pattern to the spurious values the errors give you.

Thanks for your reply PeterH.

In the meantime I found lots and lots of topics around this problem.
It's all about the pullup resistors like MarkT already said in this topic.

But the question is:

Does the board not already HAVE pullup resistors? I use this board:

I looks like it already has some, right?

Thanks for the help!!

Atmoz

Do you have an application circuit for that board? If not, you could ask your supplier for one. This ought to tell you how the designer intended the board to be used.

PeterH:
Do you have an application circuit for that board? If not, you could ask your supplier for one. This ought to tell you how the designer intended the board to be used.

No, I don't have that.
And I bought it more then a year ago from Ebay.
The seller now sells newer models, so great chance that he doesn't know about the one I have XD

But I can place an (extra) pullup in the circuit, right?
Let's say a 4K7 or so?

Thanks,

Atmoz

It is usual practice to not include pullup resistors on the breakout boards. If several boards have pullups then the resulting pullup value could be too low and hard to pull down. Can't hurt to add the, around 4.7K, resistors recommended by the I2C spec.

groundfungus:
It is usual practice to not include pullup resistors on the breakout boards. If several boards have pullups then the resulting pullup value could be too low and hard to pull down. Can’t hurt to add the, around 4.7K, resistors recommended by the I2C spec.

Ahhhh Thanks 8) 8)

That would be very nice, then the problem is fixed (I hope, can’t test it right now :))

I’ll give it a try later today!

Thanks / regards,

Atmoz