I want the RAK3172 module to communicate between UART2 and Arduino UNO using the Software.Serial library and to set the module as a transmitter when the button connected to the Arduino UNO board is pressed. I’m new to Lora and the embedded field. First, I send message 1 from my Arduino UNO card, but the lora module does not receive this message. The messages sent by the Lora module can be received by Arduino UNO. In this case, since Serial is used, I wrote simple codes in case the Lora module is a receiver. I’m adding it below. Please tell me where I’m doing wrong? Thank you.
Arduino UNO code:
#include <SoftwareSerial.h>
const int buttonPin = 2;
const int loraRxPin = 10; // LoRa RX pini
const int loraTxPin = 11; // LoRa TX pini
const int ledPin = 13;
SoftwareSerial loraSerial(loraRxPin, loraTxPin);
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Ana seri portu başlat
loraSerial.begin(9600); // LoRa modülü seri portunu başlat
}
void loop() {
if (digitalRead(buttonPin) == HIGH) {
loraSerial.println("1");
Serial.println("1 değeri gönderildi");
// LoRa wait response
long timeout = millis() + 5000; // 5 saniye zaman aşımı süresi
bool ackReceived = false;
while (millis() < timeout) {
if (loraSerial.available() > 0) {
String response = loraSerial.readString();
if (response.indexOf("ACK") != -1) {
ackReceived = true;
break;
}
}
}
if (ackReceived) {
Serial.println("ACK are taken, message are sent successfully");
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
} else {
Serial.println("ACK are not taken, message are not send");
}
delay(1000);
}
}
RAK3172 code:
#include <stdint.h>
#include <string.h>
void setup()
{
Serial.begin(9600);
delay(1000);
}
void loop()
{
// Read messages from Arduino Uno
if (Serial.available() > 0) {
char received = Serial.read();
delay(100);
Serial.print("Incoming message: ");
Serial.println(received);
// If the incoming message is '1', send 'ACK' message
if (received == '1') {
Serial.println("ACK");
Serial.println("ACK are sent");
}
}
delay(500);
}