arduino在省电模式用nrf24l01发送温湿度数据代码
时间: 2023-03-10 21:00:49 浏览: 84
可以使用Arduino来使用NRF24L01发送温湿度数据,可以使用下面的代码:#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };// Create an RF24 object
RF24 radio(9,10);float temperature = 0;
float humidity = 0;void setup() {
Serial.begin(115200);
Serial.println("NRF24L01 Receiver");
// Setup and configure rf radio
radio.begin();
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}void loop() {
float data[2];
if ( radio.available() )
{
// Dump the payloads until we've gotten everything
bool done = false;
while (!done)
{
// Fetch the payload, and see if this was the last one.
done = radio.read( data, sizeof(data) );
// Spew it
Serial.print(data[0]);
Serial.print(" ");
Serial.println(data[1]);
}
temperature = data[0];
humidity = data[1];
}
}