Created
October 14, 2021 21:45
-
-
Save ikeating/100a211f7dbb616e0a1c4678d6b7b059 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //Keating | |
| #include <SPI.h> | |
| #include <RH_RF95.h> | |
| #include <Adafruit_GFX.h> | |
| #include <Adafruit_ILI9341.h> | |
| // for Feather32u4 RFM9x | |
| #define RFM95_CS 8 | |
| #define RFM95_RST 4 | |
| #define RFM95_INT 7 | |
| // for TFT Screen | |
| #if defined (__AVR_ATmega32U4__) || defined(ARDUINO_SAMD_FEATHER_M0) || defined (__AVR_ATmega328P__) || \ | |
| defined(ARDUINO_SAMD_ZERO) || defined(__SAMD51__) || defined(__SAM3X8E__) || defined(ARDUINO_NRF52840_FEATHER) | |
| #define STMPE_CS 6 | |
| #define TFT_CS 9 | |
| #define TFT_DC 10 | |
| #define SD_CS 5 | |
| #endif | |
| // Pallete - Where you assign names to colors you like | |
| #define BACKCOLOR 0x001F | |
| #define PRINTCOL 0x07E0 | |
| #define CHARBACK 0x001F | |
| // Color definitions | |
| #define BLACK 0x0000 | |
| #define BLUE 0x001F | |
| #define RED 0xF800 | |
| #define GREEN 0x07E0 | |
| #define CYAN 0x07FF | |
| #define MAGENTA 0xF81F | |
| #define YELLOW 0xFFE0 | |
| #define WHITE 0xFFFF | |
| Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); | |
| #define RF95_FREQ 436.703 //Norby | |
| //#define RF95_FREQ 437.200 //FEES | |
| //#define RF95_FREQ 435.500 //Satish | |
| // Singleton instance of the radio driver | |
| RH_RF95 rf95; | |
| void setup() | |
| { | |
| pinMode(RFM95_RST, OUTPUT); | |
| digitalWrite(RFM95_RST, HIGH); | |
| Serial.begin(9600); | |
| delay(100); | |
| digitalWrite(RFM95_RST, LOW); | |
| delay(10); | |
| digitalWrite(RFM95_RST, HIGH); | |
| delay(10); | |
| while (!rf95.init()) { | |
| Serial.println("LoRa radio init failed"); | |
| Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info"); | |
| while (1); | |
| } | |
| Serial.println("LoRa radio init OK!"); | |
| // 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); | |
| // setup gfx | |
| tft.begin(); | |
| tft.fillScreen(BACKCOLOR); | |
| tft.setCursor(0,0); | |
| tft.setTextWrap(true); | |
| tft.setTextColor(PRINTCOL,CHARBACK); | |
| tft.setTextSize(3); | |
| } | |
| void loop() | |
| { | |
| // Should be a message for us now | |
| uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; | |
| uint8_t len = sizeof(buf); | |
| uint8_t from; | |
| if (rf95.recv(buf, &len)) | |
| { | |
| RH_RF95::printBuffer("Received: ", buf, len); | |
| Serial.println(""); | |
| Serial.print("got transmission from : 0x"); | |
| Serial.print(from, HEX); | |
| Serial.println(": "); | |
| Serial.println((char*)buf); | |
| Serial.print("RSSI: "); | |
| Serial.println(rf95.lastRssi(), DEC); | |
| // gfx | |
| tft.setCursor(0,0); | |
| tft.println((char*)buf); | |
| } | |
| else | |
| { | |
| Serial.println("Receive failed"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment