nRF24L01 & DS18B20

Hello,

I try to use the nRF24L01 node and a DS18B20 onewire sensor with a Arduino Nano.

Regarding the hardware, the Nano is connected with the node and the sensor.

I found with the librairies and on internet:

  • 1 example to use the node and it works well
  • 1 example to use the DS18B20 and it works well

When I try to merge the software, the measure of the sensor is incorrect (-127) and it looks the sensor is not reachable...

Here is the code:

// Library for SPI
#include <SPI.h>

// Library for nRF24L01+
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>

// Library for DS18B20
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 10 on the Arduino
#define ONE_WIRE_BUS 10

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Last time data has been sent via nRF (ms)
long lastSend = 0;

// Delay between each sent (ms)
int sendDelay = 5*1000; // 5sec

// ID of the prob
int probeId = 0;

// SETUP
void setup(void)
{
// Serial monitor init
Serial.begin(9600);
Serial.println("Demarrage setup");

// MIRF init
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.setRADDR((byte )"prob1"); // Name of the probe
Mirf.payload = 2; // Length
Mirf.config();
Mirf.setTADDR((byte
)"serv0"); // Name of the server

// Start of the Dallas library
sensors.begin();
}

// MAIN
void loop()
{
// If the delay betwwen each sent has been reached
if(lastSend+sendDelay <= millis())
{
Serial.println("Sending...");

// If we are currently sending, we wait
while(Mirf.isSending()){
}

// update of the temperature
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.println("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
// After we got the temperatures, we can print them here.
// We use the function ByIndex, and as an example get the temperature from the first sensor only.
Serial.println("Temperature for the device 1 (index 0) is: ");
Serial.println(sensors.getTempCByIndex(0));

// Create a packet with 2 octet
byte packet[2];

// ID of the sensor
packet[0] = probeId;

// Temperature
packet[1] = sensors.getTempCByIndex(0);

// We send
Mirf.send(packet);

// Display of the temperature
Serial.println("Temp:");
Serial.println(packet[1]);

// update of the "date" of the last sent
lastSend = millis();
}
}

I read all the information I found but I cannot find what is wrong.

Thanks for your help !

Try another pin for the 1-Wire bus. Pin 10 is not a good idea when using SPI and NRF24L01P. Cheers!

For instance;

// Data wire is plugged into pin 7 on the Arduino
#define ONE_WIRE_BUS 7

Perfect, it works with Pin 2 as the Pin 7 is already used by the nRF24 node

Thanks for the quick reply