-
-
Save 5Volt-Junkie/e4f9e1c885bbcc63356a354608674178 to your computer and use it in GitHub Desktop.
Simple LoRaNicator test sketch for LCD and radio rx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LoRaNicator simple LCD and radio RX test | |
#include <SPI.h> | |
#include <RH_RF95.h> | |
#include <U8g2lib.h> | |
#define RFM95_CS 14 | |
#define RFM95_RST 13 | |
#define RFM95_INT 6 | |
#define RF95_FREQ 868.0 | |
const int hold = A2; | |
RH_RF95 rf95(RFM95_CS, RFM95_INT); | |
U8G2_ST7565_NHD_C12864_F_4W_HW_SPI u8g2(U8G2_R2, /* cs=*/ A4, /* dc=*/ A6, /* reset=*/ A5); | |
void setup() | |
{ | |
pinMode(LED_BUILTIN, OUTPUT); | |
digitalWrite(LED_BUILTIN, HIGH); | |
pinMode(hold, OUTPUT); | |
digitalWrite(hold, HIGH); | |
pinMode(RFM95_RST, OUTPUT); | |
digitalWrite(RFM95_RST, HIGH); | |
Serial.begin(9600); | |
delay(100); | |
Serial.println("Arduino LoRa RX Test!"); | |
// reset RFM95 | |
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 868.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); | |
rf95.setTxPower(23, false); | |
u8g2.begin(); | |
u8g2.setContrast(150); | |
delay(1000); | |
u8g2.clearBuffer(); | |
u8g2.drawRFrame(0, 0, 128, 10, 3); | |
u8g2.drawRFrame(0, 11, 128, 53, 3); | |
u8g2.setFont(u8g2_font_5x7_tr); | |
u8g2.drawStr(2,8, "LoRaNicator"); | |
u8g2.sendBuffer(); | |
} | |
void loop() | |
{ | |
if (rf95.available()) | |
{ | |
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; | |
uint8_t len = sizeof(buf); | |
if (rf95.recv(buf, &len)) | |
{ | |
digitalWrite(LED_BUILTIN, LOW); | |
RH_RF95::printBuffer("Received: ", buf, len); | |
Serial.print("Got: "); | |
Serial.println((char*)buf); | |
u8g2.clearBuffer(); | |
u8g2.drawStr(2,22,((char*)buf)); | |
u8g2.drawRFrame(0, 0, 128, 10, 3); | |
u8g2.drawRFrame(0, 11, 128, 53, 3); | |
u8g2.drawStr(2,8, "LoRaNicator"); | |
u8g2.sendBuffer(); | |
Serial.print("RSSI: "); | |
Serial.println(rf95.lastRssi(), DEC); | |
} | |
else | |
{ | |
Serial.println("Receive failed"); | |
} | |
} | |
digitalWrite(LED_BUILTIN, HIGH); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment