nrf24L01 can't work with ds18b20

hey guys, i'm trying to send sensor data to another device with nrf24l01 module but not working.

//TX code :
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensorSuhu(&oneWire);
float suhuSekarang;

int pesan[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL; 

void setup(){
 Serial.begin(9600);
 radio.begin();
 radio.openWritingPipe(pipe);
 sensorSuhu.begin();
}

void loop(){
 pesan[0] = 111;
 radio.write(pesan, 1);
 sensorSuhu.requestTemperatures();
 float suhu = sensorSuhu.getTempCByIndex(0);
 Serial.println(suhu);
}
//RX code :
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

int pesan[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;

void setup(){
 Serial.begin(9600);
 radio.begin();
 radio.openReadingPipe(1,pipe);
 radio.startListening();
}

void loop(){
 if (radio.available()){
   bool selesai = false;
   while (!selesai){
     selesai = radio.read(pesan, 1); 
     Serial.println(pesan[0]);
     delay(10);
   }
 }
 else{
   Serial.println("no signal");
 }
}

but if i deleted this code :
sensorSuhu.requestTemperatures();
float suhu = sensorSuhu.getTempCByIndex(0);
Serial.println(suhu);

the communication working

OP's programs - to make life easier for other readers

// Tx code

#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
 
#define ONE_WIRE_BUS 2
 
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensorSuhu(&oneWire);
float suhuSekarang;
 
int pesan[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL; 
 
void setup(){
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(pipe);
  sensorSuhu.begin();
}
 
void loop(){
  pesan[0] = 111;
  radio.write(pesan, 1);
  sensorSuhu.requestTemperatures();
  float suhu = sensorSuhu.getTempCByIndex(0);
  Serial.println(suhu);
}
// RX code :

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
 
int pesan[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
 
void setup(){
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
}
 
void loop(){
  if (radio.available()){
    bool selesai = false;
    while (!selesai){
      selesai = radio.read(pesan, 1); 
      Serial.println(pesan[0]);
      delay(10);
    }
  }
  else{
    Serial.println("no signal");
  }
}

...R

I wonder if the problem is caused by the sensor interfering with the SPI communication with the nRF24 - I'm not familiar with the DallasTemperature library or hardware.

Separately, your Tx program is sending data as fast as it can. I suggest you only send data about once every 100 millisecs (or much less often if the application would be satisfied) - otherwise you are unnecessarily overcrowding the airwaves for other 2.4GHz applicances.

...R
Simple nRF24L01+ Tutorial

Robin2:
I wonder if the problem is caused by the sensor interfering with the SPI communication with the nRF24 - I'm not familiar with the DallasTemperature library or hardware.

Separately, your Tx program is sending data as fast as it can. I suggest you only send data about once every 100 millisecs (or much less often if the application would be satisfied) - otherwise you are unnecessarily overcrowding the airwaves for other 2.4GHz applicances.

...R
Simple nRF24L01+ Tutorial

i'm already add delay to my program but it still same.

Hi,
Welcome to the forum.

i'm already add delay to my program but it still same.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .

Then look down to item #7 about how to post your updated code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

fauzian:
i'm already add delay to my program but it still same.

My comment on the timing was not intended to be a solution to the problem of the sensor interfering with the wireless.

Only the first paragraph of Reply #2 was a comment intended to help with a solution.

...R

      selesai = radio.read(pesan, 1);

This only compiles with the old ManiacBug library, which has problems.

Writing and reading only one byte of integers is at least strange.

fauzian:
hey guys, i'm trying to send sensor data to another device with nrf24l01 module but not working.

That is not true, you are not even trying.

 pesan[0] = 111;
  radio.write(pesan, 1);

How should that send sensor data?

I was actually going to try the same thing in the next couple of days. I currenlty have a setup with an ATTiny85, RF24 breakout and a DHT11/DHT22 as the temp sensor and got this to work.

I have some ds18b20 as well that I was going to try next. For your setup, if you commented out the RF24 logic, and just printed the temp to Serial does it work? I'm curious to see if the loop is stuck at reading the sensor.

I just tried on my setup, and I'm able to read and send the data from the DS18b20 sensor over the RF24 module.

Add some serial prints after reading the temperature to make sure it's actually getting a temperature and not just blocking there. Some implementation of the ds18b20 library will block there until the data is read. Teh lobrary I used for the ds18b20 is from here

https://github.com/RobTillaart/Arduino/tree/master/libraries/DS18B20

and the OneWire library from Jim Studt, and Tom Pollard.

This is a non blocking implementation. Look at his example (simple example).

And as others pointed out, your current code isn't sending the sensor data. You are writing 1 byte from your pesan array of int (4 bytes depending on what device you are using).

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .

Then look down to item #7 about how to post your updated code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

Thanks for information and correction :slight_smile:

Whandall:

 pesan[0] = 111;

radio.write(pesan, 1);



How should that send sensor data?
 sensorSuhu.requestTemperatures();
 float suhu = sensorSuhu.getTempCByIndex(0);
 Serial.println(suhu);

This code for get sensor value.

  pesan[0] = suhu;
  radio.write(pesan, 1);

But, the problem is not send sensor value through nrf24L01.

fauzian:
But, the problem is not send sensor value through nrf24L01.

It would be more useful if you tell us what the problem is, rather than what it is not.

...R

Robin2:
It would be more useful if you tell us what the problem is, rather than what it is not.

...R

sorry for not more expalined that before.

the communication between nrf24L01 is error until i deleted this code

sensorSuhu.requestTemperatures();
float suhu = sensorSuhu.getTempCByIndex(0);
Serial.println(suhu);

i guess dallastemperature library block nrf25L01 communication, but i still need ds18b20 sensor.

fauzian:
i guess dallastemperature library block nrf25L01 communication, but i still need ds18b20 sensor.

If you read #8, ymeunier suggests that maybe your library is blocking period, not blocking comms specifically.

Did you try ymeunier's suggestion of some serial prints to test? He is:

able to read and send the data from the DS18b20 sensor over the RF24 module

... so perhaps you have a crap library.

12Stepper:
If you read #8, ymeunier suggests that maybe your library is blocking period, not blocking comms specifically.

Did you try ymeunier's suggestion of some serial prints to test? He is:

... so perhaps you have a crap library.

i already trying this library but the result is same.

ymeunier:
https://github.com/RobTillaart/Arduino/tree/master/libraries/DS18B20

fauzian:
sorry for not more expalined that before.

I thought your comment at the bottom of Reply #10 referred to a revised version of your program that was taking account of the advice in the earlier Replies.

Please post the latest version of your program and tell us in detail what it actually does and what you want it to do that is different.

...R