-
hello everyone, I have been trying to create a basic communication using two rfm95w modules on raspbery picos for quite a while. First of all I am sorry but I have little to no experience doing things like that so this whole topic could be something I don't undderstand correctly. Now, I have successfully a transmitter and I was able to send messages from it pretty easily but on the receiver side my luck was not that good. I was stuck trying to receive any of the messages using the "available" method of the library to check if there is anything to be received but, this was always returning "0" and the "if" statement never met my conditions. After trying to get this to work for almost a week I ended up trying other ways to receive my message, so far the only way I found that I could accomplish my goal, is using DIO0 pin to trigger an interupt. Is the available method used for something else and not what I am trying to do? In the example I saw that the "setPacketReceivedAction" method was used, that inspired me to create this so I can check if there is an error with the module. To start over creating my receiver since using DIO0 as interupt isn't a good way to check for messages should I follow the example? Is there actualy something similar to "Serial.available" in the library or am I just confused? My current code that was able to receive messages. #include <RadioLib.h>
#include <SPI.h>
#define DIO1_PIN 16 // NSS
#define DIO0_PIN 15 // DIO0
#define RESET_PIN 14 // RESET
#define SCK_PIN 10 // SCK for SPI1
#define MOSI_PIN 11 // MOSI for SPI1
#define MISO_PIN 8 // MISO for SPI1
#define CS_PIN 9 // CS for SPI1
RFM95 radio = new Module(CS_PIN, DIO0_PIN, RESET_PIN, DIO1_PIN, SPI1);
void handleDio0Interrupt() {
String received = "";
// This function will be called when DIO0 changes state, potentially indicating a message is received
Serial.println("DIO0 interrupt triggered");
radio.receive(received);
Serial.print("Received message: ");
Serial.println(received);
radio.startReceive();
}
void setup() {
SPI1.setSCK(SCK_PIN);
SPI1.setTX(MOSI_PIN);
SPI1.setRX(MISO_PIN);
SPI1.setCS(CS_PIN);
SPI1.begin();
delay(2000);
Serial.begin(9600);
while (!Serial);
Serial.println("Initializing RFM95W module...");
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println("RFM95W initialized successfully.");
radio.setFrequency(868.0);
radio.setCurrentLimit(100);
radio.setOutputPower(13);
radio.setSpreadingFactor(9);
radio.setBandwidth(125.0);
radio.setCodingRate(4/7);
radio.setPreambleLength(8);
radio.setSyncWord(RADIOLIB_SX127X_SYNC_WORD);
radio.startReceive(); // Start listening for incoming messages
// Attach the ISR to DIO0
attachInterrupt(digitalPinToInterrupt(DIO0_PIN), handleDio0Interrupt, CHANGE);
} else {
Serial.print("RFM95W initialization failed, code ");
Serial.println(state);
while(true);
}
}
void loop() {
Serial.print("RSSI: ");
Serial.println(radio.getRSSI());
delay(100);
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Yes, in fact I would suggest starting with that. Modify them as little as possible, usually just the pins need to be changed.
That's not how that method works or what it's for. Again, start with the examples.
If it did, I am very surprised, you are calling the blocking |
Beta Was this translation helpful? Give feedback.
-
using the examples I was also able to receive messages but my main problem is that I wasnt able to combine the two sketches so I can send and receive messages from the same module, is there any example for a transceiver I could follow to achieve this? |
Beta Was this translation helpful? Give feedback.
There's the SX127x ping pong example that shows how to send messages back and forth between two radios.