11 Commits
Author SHA1 Message Date
caternuson 313472d7c3 misc fixes 2021-11-02 13:59:04 -07:00
Colin Grant 5011b2d520 Ensure serial message printed and proper termination when RTC not found.
3f379ab (PR #166) added connection verification for the PCF8523 and DS1307 matching that of the DS3231. For each RTC, if begin() returns false, the intended behavior is to print a message, "Couldn't find RTC" to an attached serial terminal and then terminate.

This change is a follow-on that corrects two issues which were not seen as long as begin() always returned true, across all RTClib examples:
1) The method of termination in place was an endless loop: `while(1)`
However, as pointed out in PR #168, the behavior of such a loop is undefined. (See PR for interesting reading!) The `abort()` command effectively starts an endless loop, but without any side effects. It also makes clear to new users what the program is doing. H/T to contributor @edgar-bonet for this advice.

2) The message text "Couldn't find RTC" was not guaranteed to actually print on screen before the processor entered the endless loop.
This has to do with the way serial data is actually buffered and transfered down the line. On some boards, serial data is processed using interrupts. On others, such as the Feather nRF52840 which uses the TinyUSB stack, interrupts are not used at all, and serial processing waits for the CPU to become available. Whatever the case, `Serial.flush()` allows serial processing to finish before terminating with the endless loop.

An alternate way of handling 1 and 2, recommended by the TinyUSB author, is to enter the endless loop immediately, but call `yield()` inside to instruct the processor to go ahead and handle any latent requests that come in. This also makes the loop have defined behavior. E.g.:

```
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1) {
      yield();  // delay(1) would also suffice
    }
  }
```

A fuller discussion of termination methods can be viewed in PR #166.
2020-05-18 19:52:40 -07:00
Colin Grant eb805c49ed Fix examples to start Serial before checking for USB connection.
Prompted by RTClib issue #137 for PCF8523.ino, but upon inspection, all of the RTClib examples that waited for a native USB connection were checking Serial status before it was actually started.

Further, some examples exempted ESP8266 from the Serial check, others did not have a check at all.

This change standardizes the Serial opening steps across all RTClib examples.

Tested on:
Feather M4 Express w/DS1307
Feather M4 Express w/PCF8523
Feather nRF52840 Sense w/DS1307
Feather nRF52840 Sense w/PCF8523

(in the case of the DS1307, 5v power was supplied, with SDA/SCL pulled up to Feather's 3v supply)

Unfortunately, I do not have an ESP8266 or DS3231 to test with. However, all examples connected to the Arduino IDE built-in Serial monitor without issue.

Useful reference: https://www.arduino.cc/reference/en/language/functions/communication/serial/ifserial

Resolves #137
2020-04-23 00:24:21 -07:00
Matt Goodrich 0534b4cf36 Remove SerialUSB from examples 2019-07-12 10:26:33 -04:00
Matt Goodrich d501cb47d5 Cleaned up example includes 2019-07-12 10:07:52 -04:00
Andy Doro 973be093df formatiing Zero Serial if statement
clearer commenting on Zero Serial if statement
2015-11-23 10:33:24 -05:00
Andy Doro b05bfa7753 changed ESP8266 to i2C pin defaults
ESP8266 i2c defaults to pins 4 and 5.
2015-11-02 14:07:17 -05:00
Andy Doro 4943de0d5a removed whitespace edits
removed whitespace edits
2015-10-12 22:33:01 -04:00
Andy Doro af39c840b1 edits made to examples to work on other Arduino boards
edits made to examples for compatibility with Leonardo, M0 Pro, Due,
ESP8266
2015-10-12 17:09:47 -04:00
ladyada 0779f1fa0e Wire.begin is now in library 2015-10-06 00:18:26 -04:00
Tony DiCola 87624ede67 Add NVRAM functions from mabarnett0's pull #20. Also add example of using NVRAM functions. 2014-06-10 14:37:38 -07:00