3

Please help me to solve the problem. I do not get data at Raspberry.
I have:
1. Arduino Nano + DHT11 + NRF24l01+
2. Raspberry Pi 3 + NRF24l01+
Raspberry RF24 library https://github.com/stanleyseow/RF24.git
Arduino code:

#include "DHT.h"
#include <SPI.h>
#include "RF24.h"
#define DHTPIN 2     // what digital pin we're connected to
#define DHTTYPE DHT11   // DHT 11

RF24 radio(7,8);

unsigned long count = 0;
int sensor1 = 2;

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  dht.begin();
  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setChannel(0x4c);
  radio.openWritingPipe(0xF0F0F0F0E1LL);
  radio.enableDynamicPayloads();
  radio.powerUp();
  pinMode(sensor1, INPUT);
  pinMode(3, OUTPUT);
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  float hic = dht.computeHeatIndex(t, h, false);
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.println(" *C ");

    char outBuffer[32]= "";

    char buffer[10];
    String temp = dtostrf(t,3,1,buffer);
    String hum = dtostrf(h,3,1,buffer);
    String out = temp + "; " + hum + ";"; 
    out.toCharArray(outBuffer, 32);
    radio.write(outBuffer, 32);
}

Raspberry code:

    #include <cstdlib>
#include <iostream>
#include "/home/pi/RF24/RPi/RF24/RF24.h"
#include <fstream>
using namespace std;

// spi device, spi speed, ce gpio pin
//RF24 radio("/dev/spidev0.0",8000000,25);
RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);

void setup(void)
{
    // init radio for reading
    radio.begin();
    radio.enableDynamicPayloads();
    radio.setAutoAck(1);
    radio.setRetries(15,15);
    radio.setDataRate(RF24_1MBPS);
    radio.setPALevel(RF24_PA_MAX);
    radio.setChannel(76);
    radio.setCRCLength(RF24_CRC_16);
    radio.openReadingPipe(1,0xF0F0F0F0E1LL);
    radio.startListening();
}

void loop(void)
{
char receivePayload[64];
    while (radio.available())
    {
uint8_t len = radio.getDynamicPayloadSize();
radio.read(receivePayload, len);
// Костыль для создания промежуточного файла.
//ofstream out("/dev/nrf24");
//out << receivePayload << "\n";
//out.close ();
cout<<"\n Data="<<receivePayload;
delay(200);
    }
}

int main(int argc, char** argv)
{
cout << "Driver initialized, please check values of /dev/nrf24" << endl;
    setup();
    while(1)
        loop();

    return 0;
}

Raspberry schema: enter image description here


What is wrong? Thank you.

3
  • Why not get rid of the Nano and the radio and just attach the DHT11 to the Pi?
    – joan
    Commented Jun 2, 2016 at 20:14
  • Because I want to collect sensors data from several room to one server.
    – lavAzza
    Commented Jun 3, 2016 at 9:39
  • 1
    Do you know if all of your hardware is good? Has it worked properly in other projects. You could have a dead RF24 board. Add diagnostic/debug code to help determine what your scripts are doing. On the Arduino you can use the serial monitor to view the output of "Serial.print" statements. I don't recognize the Raspberry Pi environment based on the code you provided so you'll need to look up how to display messages in that environment. If you have an Oscilloscope or Data Analyzer you should be able to troubleshoot communication issues between the computer board and RF24.
    – linhartr22
    Commented Jun 7, 2016 at 21:50

5 Answers 5

1

I found it rather confusing that the nRF24 library (at least the Arduino one from TMRh20) already configuers the module in the constructor. I could not find any documentation about it but found it in the source code and by using a logic analyzer. So it was very annoying as the configuration deviates form the devices default values. I can imagine that the RPi library does different initialization steps leading into incompatibility in communication.

I also noticed you've set the transmission level to RF24_PA_MAX. Try reducing it to RF24_PA_MIN. The modules can't read the signal if it is too strong as @Greben stated.

1

I also faced the same problem.

What I found is the data send by Arduino has difference in trigger clock when it reaches raspberry Pi. As a result we get garbage values.

To overcome this problem we can use an Arduino connected to the Pi through a USB cable and an nrf24l01 connected to the Arduino. Then use the master-slave procedure to get the receiver end reading on Pi.

For more details on this method, see https://robofever.in/

1
  • Please write proper sentences. Your answer is nearly unreadable. And please take the short Tour and visit the Help Center to get an idea how things work here.
    – Ingo
    Commented Jun 14, 2019 at 15:11
0

Try adding delay(20) before the final bracket in the RPi loop function.

0

Refer to this tutorial:

http://invent.module143.com/daskal_tutorial/rpi-3-tutorial-14-wireless-pi-to-arduino-communication-with-nrf24l01/

Follow instructions exactly, it should work.

2
0

The Suggestion by QGLV worked for me. It looks like we need to introduce a delay between successive calls of RF24::available() on the Pi. the 20 millisecond delay suggested by QGLV worked for the most part for me (I used usleep(20000) for the delay), although I still saw rare instances of corrupted payloads. Increasing the delay did not seem to help, as I still saw a few corrupted payloads with 100ms delay. I'm using a Pi Zero, so your mileage may vary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.