Conflict with DS1307,Time, Wire and RF24 library NRF24L01 and DS1307 RTC

Hi all

I wonder if someone could please assist me with how to solve what I suspect is a conflict somewhere between libraries or hardware (????) I'm really not sure at the moment :frowning: and could use a little help.

I current have an Arduino UNO , a DS1307 and an NRF24L01 module connected.

All work perfectly well individually as well as in the following combinations:
Arduino on its own = Working

Arduino + DS1307 = Working
In the current code I would normally see the time and date displayed every second. I can also run most of the examples just fine.

The libraries I am using here are:

#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>

Arduino + NRF24L01 = Working
Also working great when using the RF24 library and I am able to run a simple continuous send and transmit without issues. As well as the examples
The libraries I am using here are:

#include <SPI.h> 
#include "RF24.h"

When I connect both the DS1307 and the NRF24L01 it looks like all is good in terms of hardware until I run the code.

I set the code to do a clock update every second as well as a simple transmit of a message on every loop of the ""void loop"".
The code compiles just fine without issues.
The problem is that when I open the serial monitor I see absolutely nothing. It's just blank :frowning:
and the receiving NRF24L01 receives nothing.

//for NRF
#include <SPI.h> 
#include "RF24.h"

// Your chosen radio CE,CS pins
RF24 radio(9,10);

uint64_t addresses[] = {
  0xABABABABABLL, 0xC3C3C3C3C3LL};

/****** Configure this for sender or receiver *****/
boolean sender = 1; // Change this from 0 to 1 to switch between sending or receiving sketch

//for DS1307 RTC 
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>  

void setup() {
  Serial.begin(9600);
  //DS1307
  while (!Serial) ; 
  setSyncProvider(RTC.get);   
  if(timeStatus()!= timeSet) 
    Serial.println("Unable to sync with the RTC");
  else
    Serial.println("RTC has set the system time");
  //test field for setTime
  Serial.println("Time is now set using setTime");
  setTime(21,30,50,12,4,2015);
  RTC.set(now());

  //NRF24L01
  radio.begin(); 

  if(sender == 0){
    radio.openWritingPipe(addresses[1]);
    radio.openReadingPipe(1,addresses[0]);
    radio.startListening();
  }
  else{
    radio.openWritingPipe(addresses[0]);    //*Edit to correct address assignments
    radio.openReadingPipe(1,addresses[1]);
    radio.stopListening(); 
  }
}
char myArray[] = "This is not a test";
  //*****ALL WORKING UP TO HERE !!

void loop() {
  if (timeStatus() == timeSet) {
    digitalClockDisplay();
  } 
  else { //add or change later
    Serial.println("The time has not been set.  Please run the Time");
    Serial.println("TimeRTCSet example, or DS1307RTC SetTime example.");
    Serial.println();
    delay(1000);
  }
  //*****ALL WORKING UP TO HERE 

  //BUT WHEN I ADD THIS IN THE COMPILE IS FINE BUT NOTHING APPEARS 
  //IN THE SERIAL MONITOR :-( 

  //NRF 24L01
  
  if(sender == 0){

    if(radio.available()){
      char tmpArray[19];                                               
      radio.read(&tmpArray,sizeof(tmpArray));  
      Serial.println(tmpArray);                  
      delay(200);              

    }

  }
  else{

    bool ok = radio.write(&myArray,sizeof(myArray));

    if(ok){ 
      Serial.println("Transfer OK");
    }
    else { 
      Serial.println("Transfer Fail"); 
    }
    delay(500);
  }
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 

}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

I would appreciate and look forward to any help or advice.

D

din4444:
HThe problem is that when I open the serial monitor I see absolutely nothing. It's just blank :frowning:

One possibility would by: OUT OF RAM!

You really waste so much RAM in your sketch, that maybe the 2 KB (2048 bytes) of an UNO might not be enough to handle all the wasted RAM.

At a first step you should use the F-macro for all print commands that have a constant text as parameter.

Instead of wasting RAM:

Serial.println("Unable to sync with the RTC");

Use F-macro to save RAM:

Serial.println(F("Unable to sync with the RTC"));

After changing that in your code: Any difference?

Hi Jurs

Thanks a million for your reply.

I appreciate the tip to minimize resource usage so I followed all your advise and definitely gave it a bash.
Initially the used memory after compile was 10,984 bytes.
After making the changes it was 11.058 bytes.
It honest had zero effect on the problem though, so I resorted back to what I had posted.
I re-checked my code, chopped and changed things around and then attacked the hardware side.
I clipped the power leads feeding the DS1307, to check if it was a possible power drain, tested it again and no difference.
Then noticed what looked like a dry joint on the incoming power feed to the DS1307 ... I re-soldered it , plugged it all in and tested....
WHAMMO it's working ...YAY. Even seems faster than time itself :slight_smile: LOL

@ Jurs .... is your suggestion the same as printf() ?

Where exactly is there a saving ? is it in running memory or compiled footprint ?

Thank you once again .. you know when you're at wits end it's always a plus getting a different set of eyes and mind in on things and forces a person to review ones work and thinking.

Take care

And if you enjoy the code example as simple as it is, I would love some feedback from whomever.

D

din4444:
@ Jurs .... is your suggestion the same as printf() ?

No, the F-macro prints strings directly from flash (program) memory.

If you print string constants without using the F-macro, all the constant strings will be copied from flash memory to RAM memory before the program starts, and will reside there while the program is running.

Especially when printing a lot of text constants, each use of the F-macro can save some bytes of RAM.
The only disadvantage is, that every usage of the F-macro will add a few bytes to the flash/program size.

But as all AVR controllers have much more flash memory (UNO: 32 KB) than RAM memory (UNO: 2 KB), you typically will benefit from the F-macro when your application tends to be short of RAM.

See: Arduino Playground - HomePage