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.

  • Why not get rid of the Nano and the radio and just attach the DHT11 to the Pi? – joan Jun 2 '16 at 20:14
  • Because I want to collect sensors data from several room to one server. – lavAzza Jun 3 '16 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 Jun 7 '16 at 21:50
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.

| improve this answer | |
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/

| improve this answer | |
  • 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 Jun 14 '19 at 15:11
0

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

| improve this answer | |
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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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