【发布时间】:2018-02-22 11:47:56
【问题描述】:
这些为 nRF24L01 模块开发的 Arduino 代码。它是一个射频模块,提供两点之间的无线通信。而我的目的是测量这两个点之间的数据传输速率。
这是发射器代码的示例:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
const char text[] = "Hello World";
radio.write(&text, sizeof(text));
}
这段代码基本上是通过通道发送一个字符串“Hello World”。首先,我调用了一些与模块相关的库。比我定义模块使用的引脚号。比我命名模块。之后设置一些属性,如监听模式和模块的功率级别。最后通过循环发送消息。下面还提供了接收器代码:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7,8);
const byte address[6] = "00001";
void setup() {
radio.begin();
radio.openReadingPipe(0,address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
Serial.begin(9600);
// put your setup code here, to run once:
}
void loop() {
if (radio.available()){
char text[32] = "";
radio.read(&text,sizeof(text));
Serial.println(text);
}
// put your main code here, to run repeatedly:
}
接收器逻辑与发送器相同。
总而言之,问题是我们如何测量这种无线通信的数据速率(比特/秒)?
【问题讨论】:
标签: arduino wireless telecommunication