Files
hopper_traps/lora_baudchange/lora_baudchange.ino
Thaddeus Hughes 9bc81a9ebf init
2025-08-24 07:39:06 -05:00

56 lines
1.9 KiB
C++

void setup() {
Serial.begin(115200); // Serial Monitor for debugging
Serial1.begin(115200); // Start at default RYLR998 baud rate
delay(1000); // Wait for RYLR998 to stabilize
Serial.println("Starting RYLR998 baud rate reprogramming...");
// Test communication at 115200 baud
sendATCommand("AT", "+OK", 115200); // Verify module responsiveness
sendATCommand("AT+RESET", "+RESET", 115200); // Reset module
sendATCommand("AT+IPR=9600", "+OK", 115200); // Set baud rate to 9600
// Switch to 9600 baud
Serial1.end(); // Close Serial1 at 115200
delay(500);
Serial1.begin(9600); // Reopen at 9600
delay(1000); // Wait for stabilization
// Verify communication at 9600 baud
sendATCommand("AT", "+OK", 9600); // Test at new baud rate
sendATCommand("AT+UART?", "+UART", 9600); // Confirm baud rate
Serial.println("RYLR998 reprogrammed to 9600 baud. Configuration complete.");
}
void loop() {
// No loop actions needed; script runs once
}
// Helper function to send AT command and print response
void sendATCommand(String command, String expected, int baudRate) {
Serial1.println(command);
Serial.print("Sent AT (");
Serial.print(baudRate);
Serial.print(" baud): ");
Serial.println(command);
String response = waitForResponse(2000);
Serial.print("Response: ");
Serial.println(response);
if (!response.startsWith(expected)) {
Serial.println("Warning: Unexpected response for " + command);
}
}
// Helper function to read response from RYLR998
String waitForResponse(unsigned long timeout) {
unsigned long start = millis();
String response = "";
while (millis() - start < timeout) {
if (Serial1.available()) {
response += Serial1.readStringUntil('\n');
if (response.length() > 0) return response; // Return on first complete response
}
delay(10); // Small delay to prevent tight loop
}
return response; // Return empty or partial response if timeout
}