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;
}
What is wrong?
Thank you.