英国CanSat竞赛LoRa接收消息出现乱码符号的解决求助
CanSat竞赛LoRa通信乱码问题排查求助
我正在参加英国CanSat竞赛,当前调试CanSat与地面站的LoRa通信:
- 发射端:Raspberry Pi Pico
- 接收端:Arduino Nano
- LoRa模块:Adafruit RFM95W
目前遇到的核心问题:地面站接收消息时出现大量乱码,截图如下:
Arduino接收端代码
// Arduino9x_RX // -*- mode: C++ -*- // Example sketch showing how to create a simple messaging client (receiver) // with the RH_RF95 class. RH_RF95 class does not provide for addressing or // reliability, so you should only use RH_RF95 if you do not need the higher // level messaging abilities. // It is designed to work with the other example Arduino9x_TX #include <SPI.h> #include <RH_RF95.h> #define RFM95_CS 10 #define RFM95_RST 9 #define RFM95_INT 2 // Change to .0 or other frequency, must match RX's freq! #define RF95_FREQ 433.0 // Singleton instance of the radio driver RH_RF95 rf95(RFM95_CS, RFM95_INT); // Blinky on receipt #define LED 13 void setup() { pinMode(LED, OUTPUT); pinMode(RFM95_RST, OUTPUT); digitalWrite(RFM95_RST, HIGH); while (!Serial); Serial.begin(9600); delay(100); Serial.println("Arduino LoRa RX Test!"); // manual reset digitalWrite(RFM95_RST, LOW); delay(10); digitalWrite(RFM95_RST, HIGH); delay(10); while (!rf95.init()) { Serial.println("LoRa radio init failed"); while (1); } Serial.println("LoRa radio init OK!"); // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM if (!rf95.setFrequency(RF95_FREQ)) { Serial.println("setFrequency failed"); while (1); } Serial.print("Set Freq to: "); Serial.println(RF95_FREQ); // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on // The default transmitter power is 13dBm, using PA_BOOST. // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then // you can set transmitter powers from 5 to 23 dBm: rf95.setTxPower(23, false); } void loop() { if (rf95.available()) { // Should be a message for us now uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; //char buf = (char*)buf; uint8_t len = sizeof(buf); if (rf95.recv(buf, &len)) { digitalWrite(LED, HIGH); Serial.print("Got: "); Serial.println((char*)buf); Serial.print("RSSI: "); Serial.println(rf95.lastRssi(), DEC); } else { return; } } }
注:代码来自Arduino社区论坛示例。
Raspberry Pi Pico发射端代码
import board import busio import time import digitalio import adafruit_rfm9x import adafruit_bmp280 "Led configuration" # Led amarillo ledambar = digitalio.DigitalInOut(board.GP16) ledambar.direction = digitalio.Direction.OUTPUT # Led azul ledazul = digitalio.DigitalInOut(board.GP17) ledazul.direction = digitalio.Direction.OUTPUT "LoRa" # LoRa radio setup spi = busio.SPI(clock=board.GP2, MOSI=board.GP3, MISO=board.GP4) cs = digitalio.DigitalInOut(board.GP6) reset = digitalio.DigitalInOut(board.GP7) rfm9x = adafruit_rfm9x.RFM9x(spi, cs, reset, 433.0) print("RFM9x radio ready") "Not LoRa from here" "BMP280 Sensor" # BMP280 comunication start up i2c = busio.I2C(scl=board.GP15, sda=board.GP14) bmp280_sensor = adafruit_bmp280.Adafruit_BMP280_I2C(i2c, address=0x76) # BMP280 sensor readings def read_temperature(): return bmp280_sensor.temperature def read_pressure(): return bmp280_sensor.pressure while True: ledazul.value = True "LoRa" rfm9x.send("Hello World, this is a test, why does this not work? im going mad!!!!") print("Radio mensage sent") "Not LoRa from here" ledazul.value = False cansat_temperature = read_temperature() print("TEMPERATURE:") print(cansat_temperature) cansat_pressure = read_pressure() print("PRESSURE:") print(cansat_pressure) print(" ") time.sleep(2.5)
注:代码除LoRa通信外包含BMP280传感器读取功能,LoRa相关代码位于"LoRa"标记下方。
已尝试的排查措施:
- 焊接天线、更换不同天线
- 修改两端代码(未解决问题)
寻求帮助:
- 解决接收消息乱码的具体方法
- 对现有代码的优化建议
内容的提问来源于stack exchange,提问作者Enrique G C
相关产品推荐
相关产品推荐

