[SOLVED] Problem with combining NTP sketch and temperature monitoring sketch

[Setup: Arduino Uno IDE 1.8.0, Ethernet Shield 2 with PoE, 2 x DS18B20 temperature sensors non-parasitically wired to VCC, GND and DATA, with 4k7 Ω pull-up resistor between VCC and DATA]

Hi all,

I am currently having problems with combining two sketches that separately work fine. The first sketch enables me to time sync the Arduino with my Fritz!Box modem/router, that acts as a time server in the home network and that itself syncs with an internet NTP-server. To achieve this, I am using the setSyncProvider command, for which see the attachment Sketch_1.txt (MAC and IP addresses replaced by dummy values).

Running this sketch results in the time-library being synced every five minutes, as shown by the following output:

Waiting for sync with Fritz!Box…

Transmit NTP Request
Received NTP Response

Fritz!Box has set the system time!

[18:12:07 / 27-12-2016]

[18:12:17 / 27-12-2016]

[18:16:47 / 27-12-2016]

[18:16:57 / 27-12-2016]

Transmit NTP Request
Received NTP Response

[18:17:07 / 27-12-2016]

[18:17:17 / 27-12-2016]

Etc.

Etc.

The second sketch (for which see Sketch_2.txt) has two One-Wire DS18B20 sensors measure the temperature every 10 seconds, and this sketch too works without problem.

Trouble starts when I try to combine both sketches, for which see Sketch_3.txt (MAC and IP addresses again replaced by dummy values).

To illustrate the problems I am encountering, see the following output:

Waiting for sync with Fritz!Box…

Transmit NTP Request
Received NTP Response

Fritz!Box has set the system time!

-127.00 - -127.00
[18:21:46 / 27-12-2016]

-127.00 - -127.00
[18:21:57 / 27-12-2016]

-127.00 - -127.00
[18:22:08 / 27-12-2016]

-127.00 - -127.00
[18:22:19 / 27-12-2016]

-127.00 - -127.00
[18:22:29 / 27-12-2016]

-127.00 - -127.00
[18:25:54 / 27-12-2016]

-127.00 - -127.00
[18:26:04 / 27-12-2016]

-127.00 - -127.00
[18:26:15 / 27-12-2016]

-127.00 - -127.00
[18:26:26 / 27-12-2016]

-127.00 - -127.00
[18:26:37 / 27-12-2016]

Transmit NTP Request

… after which the Arduino hangs and nothing happens…

Not only aren’t the actual temperatures written to the terminal (I hope you’ll believe me when I say that room temperature in my house is substantially warmer than -127 C :wink: ), the sketch hangs indefinitely after it has run 5 minutes and for the first time tries to re-sync the time library with my modem/router. I have been tinkering to solve this problem for two days now, but here I am at a loss. A third, minor, problem I am having here is the ‘time drift’ as seen in the above output: no longer is the update frequency of the serial monitor 10 seconds, as stated in the sketch, but 11, and this is also something I’d like to solve.

I am suspecting the first two problems are caused in setup() in Sketch_3.txt, but I failed nailing the underlying problem. As to the noted time drift; I do realise there’s a time gap between reading the temperature and creating the time stamp, but as I only recently started fiddling with Arduinos and C, again, I wouldn’t know of an alternative way of coding that doesn’t result in this time drift.

I would hugely appreciate any suggestions as to how to fix the problems I am encountering with my code, and I am thanking anyone in advance for taking the time and effort to check my sketches.

With apologies for this lengthy posting, and wishing each of you well in the new year,

Simon

Sketch_1.txt (3.97 KB)

Sketch_2.txt (665 Bytes)

Sketch_3.txt (5.02 KB)

const int busPin = 10;

You can't use pin 10 for the temperature sensors when using an Ethernet shield.

Hi PaulS,

Finding your reply really made my day! This surely is something I wouldn't have found myself in a long time, if ever, but now I have connected DATA to pin 2, the sketch works like a charm!

Thanks a lot for helping me out, and with best wishes,

Simon