PCF8523 RTC Breakout board can't function

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Tejk
 
Posts: 3
Joined: Mon Nov 13, 2017 4:13 pm

PCF8523 RTC Breakout board can't function

Post by Tejk »

Hi, all,

We're using Arduino as part of a class and one of the things I am trying to do for a project is to provide a time stamp. I just bought Adafruit's PCF8523 breakout board to function as an external clock for this purpose. At first, I couldn't get it to read the time correctly, instead I kept getting "2165/165/165 165:165:85" in the serial monitor when I ran the demo code in the RTC.h library. Another forum suggested bad connections so I soldered the metal strip and used that to connect to the breadboard. When using the demo code again, I got the correct time to set (within about 30 sec). However, when I re-purposed some of the demo code into my own sketch, without changing the wiring configuration, it reverts back to really strange outputs like above. Sometimes, it will give me real values, but they will be really off, like the year is 2040 or something. This is even the case if I exclude the function for resetting the time and try to keep the time set using a battery.

I won't post the code for the demo sketch. But below is my code for my project. The goal was to read the data from two light sensors. One light sensor has a light source (laser) and one senses ambient light. It basically functions as a trip wire and outputs a message if the laser beam is broken (it is inside a loop, but set to only give message once per trip, not continuously and I'd like the same for the time stamp). It also lights up an LED. Ultimately, I want to be able to print a time stamp next to the message and save that information to an SD card to log all trips and be completely independent of a computer. Right now, there is no code for the SD card because that also will not work for me, even with demo code. I just want to be able to set the time when uploading the sketch and let everything keep running.
Please help me figure out if this is a coding error, a wiring error, or possibly just a bad board.

Code: Select all

/*Steps:
 * Read values from photoresistor 1
 * Read values from photoresistor 2
 * If values are equal, turn on LED and print "Sensor Trip" message
 * Time stamp when tripped
 * Record to SD card
 */
//Include time library
#include <Time.h>
#include <Wire.h>
#include "RTClib.h"
//Use the example sketch in library to set time. (pcf8523)
//Pins for time clock are: GND = Ground; VCC = 5V; SDA = A4; SCL = A5


//#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
  // #define Serial SerialUSB
//#endif


//Set variables

//Tripwire stuff
int Ambient = A0; //Ambient light sensor
int Laser = A1; //Laser sensor. This should be higher than P1 unless tripped. 
int ledPin = 8; //LED pin
boolean lastLED = LOW; //Previous state of LED
boolean currentLED = LOW; //Current LED state

RTC_PCF8523 rtc; 
//From demo code

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
//From demo code

void setup() {

  Serial.begin(9600);


if (! rtc.initialized()) {
    //Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
//From demo code
  
   analogReference(DEFAULT);
   pinMode(ledPin, OUTPUT);
}
//CHECKER FUNCTION
//Determines the current LED state and keeps track of 1 prior LED state
boolean checker(boolean last)
{
  boolean current = digitalRead(ledPin);
  if (last != current)
  {
    delay (1);
    current = digitalRead(ledPin);
  }
  return current;
}



void loop() {
  DateTime now = rtc.now(); //From demo code
  int amb = analogRead(Ambient);
  int Las = analogRead(Laser);
  
  if(amb>Las) 
   {
    digitalWrite(ledPin, HIGH);
    
   }
  else 
  {
    digitalWrite(ledPin, LOW);
  }


currentLED = checker(lastLED);
    if (lastLED == LOW && currentLED == HIGH)
    {
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    //From demo code
    Serial.println(" Sensor Trip");
      lastLED = HIGH;
    }
    lastLED = currentLED;
    
  

}
The output from the above ends up looking like this:
2165/165/165 (Tuesday) 165:165:85 Sensor Trip
Even though the demo code correctly yields:
2017/11/15 (Wednesday) 10:27:55
since midnight 1/1/1970 = 1510741675s = 17485d
now + 7d + 30s: 2017/11/22 22:58:1

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: PCF8523 RTC Breakout board can't function

Post by adafruit_support_mike »

Post a photo showing your hardware and connections and we'll take a look. 800x600 images usually work best.

User avatar
Tejk
 
Posts: 3
Joined: Mon Nov 13, 2017 4:13 pm

Re: PCF8523 RTC Breakout board can't function

Post by Tejk »

A couple photos below...
IMG_4258 2.jpg
IMG_4258 2.jpg (896.41 KiB) Viewed 528 times
IMG_4255 2.jpg
IMG_4255 2.jpg (925.44 KiB) Viewed 528 times
IMG_4254 2.jpg
IMG_4254 2.jpg (961.97 KiB) Viewed 528 times

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: PCF8523 RTC Breakout board can't function

Post by adafruit_support_mike »

I can't quite tell from the photo: have you soldered the pin header into the holes of the two breakout boards? It looks like they might just be tacked to the breadboard with the pins through the holes.

Tacking doesn't work. You have to solder the pins for them to make reliable electrical contact.

User avatar
Tejk
 
Posts: 3
Joined: Mon Nov 13, 2017 4:13 pm

Re: PCF8523 RTC Breakout board can't function

Post by Tejk »

Yes, they are! Prior to soldering, not even the demo sketch would work. Afterwards, demo works but other code doesn't.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: PCF8523 RTC Breakout board can't function

Post by adafruit_support_mike »

Okay, that tells us the hardware is working.

Try running the example sketch with all the other devices connected to the Arduino. Does the RTC still work?

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”