我尝试使用2个Arduino Unos,2个LORA芯片(SX1278 433 IDE ),2个天线和2个Arduino IDE发送和接收数据。
问题出在接收数据命令上。
下面是发送命令的代码:
#include <SPI.h>
#include <LoRa.h>
int counter = 0;
const int ss = 10;
const int reset = 9;
const int dio0 = 2;
void setup() {
Serial.begin(9600);
LoRa.begin(433E6);
LoRa.setPins(ss, reset, dio0);
while (!Serial);
Serial.println("LoRa Sender");
}
void loop() {
Serial.print("Sending packet: ");
Serial.println(counter);
// send packet
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
delay(5000);
}在串行监视器上,我成功地发送了包,但没有成功接收。这是接收代码:
#include <SPI.h>
#include <LoRa.h>
const int ss = 10;
const int reset = 9;
const int dio0 = 2;
void setup() {
Serial.begin(9600);
LoRa.begin(433E6);
LoRa.setPins(ss, reset, dio0);
while (!Serial);
Serial.println("LoRa Receiver");
}
void loop() {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet '");
// read packet
while (LoRa.available()) {
Serial.print((char)LoRa.read());
Serial.print("hello ");
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
}我使用了这个git页面中关于连接的说明:https://github.com/sandeepmistry/arduino-LoRa
发布于 2018-12-20 16:37:18
要使this board工作,我必须显式地初始化SPI
SPI.begin(/*sck*/ 5, /*miso*/ 19, /*mosi*/ 27, /*ss*/ cs);你的可能也是一样的。此外,您还应该正确初始化Lora:
while (!LoRa.begin(433E6)) {
Serial.print(".");
delay(500);
}
Serial.println("LoRa Initializing OK!");使用您发布的代码,您不能真正知道它是否正确初始化,或者它是否实际发送了任何数据。
发布于 2018-07-30 13:06:19
首先,我没有使用过Lora库。我和SX1278 libaray一起工作过。所以我可以帮你。首先,这里是指向libaray - Lora SX1278.h library的链接
现在您可能会问,为什么我不使用原始GitHub代码库中的库。我遇到了这个库的问题,问题是这样的:
修改了sx1278::getPacket()库函数以稳定Lora接收功能。有个bug使esp惊慌失措。未检查从REG_FIFO寄存器读取的有效负载长度是否有效,导致读取REG_FIFO寄存器的次数超过65000次。此外,在此函数的耗时部分中添加了yield()。
这就是我使用这个定制库的原因。无论如何,对于你:你可以使用这个函数来发送数据包:
T_packet_state = sx1278.sendPacketTimeoutACK(ControllerAddress, message); //T_packet_state is 0 if the packet data is sent successful.另外,要接收数据,请使用此函数:
R_packet_state = sx1278.receivePacketTimeoutACK(); //R_packet_state is 0 if the packet data is received successfully.在代码的开头只定义了以下几点:
//Lora SX1278:
#define LORA_MODE 10 //Add your suitable mode from the library
#define LORA_CHANNEL CH_6_BW_125 //Ch number and Bandwidth
#define LORA_ADDRESS 3 //Address of the device from which you will send data
uint8_t ControllerAddress = 5; //Address of receiving end device我在StackOverflow上的第一个不错的回答。手指交叉
https://stackoverflow.com/questions/50973512
复制相似问题