Hello everybody!
This is my first post. I'm working on an altimeter for a model rocket using an arduino nano. The idea is to get altitude information and send it to my ground station using RFM9X LoRA modules.
In the ground station i'm using a raspberry pi zero W in baremetal with CircuitPython.
I'm having trouble receiving and sending packages through LoRA between both boards. As a summary:
- Ground station: Rapsberry pi zero W with CircuitPython - Adafruit RFM9X library 5V pin SPI
- Flight computer: Arduino Nano with RadioHead library 5V pin SPI
I checked that both LoRA's worked fine (wiring and initialization), but they don't exchange information!
Here's the example code for arduino nano (extracted from an example posted in another forum):
#include <SPI.h>
#include <RH_RF95.h>
#define RFM95_CS 4
#define RFM95_RST 2
#define RFM95_INT 2
// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 868.0
// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);
void setup()
{
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
while (!Serial);
Serial.begin(115200);
delay(100);
Serial.println("Feather 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!");
rf95.setPromiscuous(true);
rf95.setModemConfig(RH_RF95::Bw125Cr45Sf128); // Usa configuración estándar
rf95.setPreambleLength(8); // Coincidir con CircuitPython
// 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
Serial.println("Message received!");
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]={0};
uint8_t len = sizeof(buf);
if (rf95.recv(buf, &len))
{
RH_RF95::printBuffer("Received: ", buf, len);
Serial.print("Got: ");
Serial.print((char*)buf);
Serial.print(" RSSI: ");
Serial.println(rf95.lastRssi(), DEC);
delay(10);
// Send a reply
//delay(200); // may or may not be needed
static int count=0;
uint8_t data[50]={0};
sprintf(data, "And hello back to you %d", count++);
Serial.print("sending reply: ");
Serial.println((char *)data);
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
}
else
{
Serial.println("Receive failed");
}
}
else
{
delay(5000);
Serial.println("No messages");
}
}
This is the output:
Feather LoRa RX Test!
LoRa radio init OK!
Set Freq to: 868.00
No messages
No messages
and the code for the rpi circuitpython:
import time
import board
import busio
import digitalio
import adafruit_rfm9x
# Define radio parameters
RADIO_FREQ_MHZ = 868.0 # Frequency of the radio in MHz. 868.0 MHz in Europe, 915.0 MHz in North America.
CS = digitalio.DigitalInOut(board.CE0)
RESET = digitalio.DigitalInOut(board.D25)
print("LoRA test")
adafruit_rfm9x.enable_crc = True
adafruit_rfm9x.signal_bandwidth = 125000 # Debe coincidir con Arduino
adafruit_rfm9x.coding_rate = 5 # CR 4/5 (igual a Bw125Cr45Sf128 en RadioHead)
adafruit_rfm9x.spreading_factor = 7 # SF7 (igual a Bw125Cr45Sf128 en RadioHead)
adafruit_rfm9x.preamble_length = 8
# Initialize SPI bus
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
#spi = busio.SPI(board.D11, MOSI=board.D10, MISO=board.D9)
# Initialize RFM9x radio
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)
count=0
while True:
text='Hello world '+ str(count)
rfm9x.send(str.encode(text))
print('Sent: {0}'.format(text))
count=count+1
packet = rfm9x.receive() # Wait for a packet to be received (up to 0.5 seconds)
if packet is not None:
packet_text = str(packet, 'ascii')
print('Received: {0}'.format(packet_text))
else:
print('Received nothing!')
time.sleep(5) # Wait for some time before sending the next command
obtaining this output:
LoRA test
Sent: Hello world 0
Received nothing!
Sent: Hello world 1
Received nothing!
Sent: Hello world 2
Received nothing!
with the example I'm trying to test sending and receiving strings in both boards. Hope anyone knows what's happening and help me to fix it. Both libraries are supposed to be compatible.