├── .gitignore ├── 1.png ├── LoRa ├── LoRa.ino ├── board_def.h ├── ds3231.cpp └── ds3231.h ├── README.MD ├── ReceiverBin ├── Receiver_V1_0_868.bin ├── Receiver_V1_2_433.bin ├── Receiver_V1_2_868.bin └── Recv.png └── SenderBin ├── Sender.png ├── Sender_V1_0_868.bin ├── Sender_V1_2_433.bin └── Sender_V1_2_868.bin /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | build 3 | .vscode 4 | _temp_by_dltool 5 | bin -------------------------------------------------------------------------------- /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewisxhe/TTGO-LoRa-Series/80e59c6779aca08641e0a00b2f1375dd035dd35b/1.png -------------------------------------------------------------------------------- /LoRa/LoRa.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "ds3231.h" 4 | #include 5 | #include 6 | #include 7 | 8 | OLED_CLASS_OBJ display(OLED_ADDRESS, OLED_SDA, OLED_SCL); 9 | 10 | #define WIFI_SSID "" 11 | #define WIFI_PASSWORD "" 12 | 13 | #if defined(BUTTON_1) 14 | Button2 btn(BUTTON_1); 15 | #endif 16 | 17 | #if defined(BUTTON_1) 18 | void pressHander(Button2 &b) 19 | { 20 | Serial.println("press BUTTON 0 goto sleep\n"); 21 | display.displayOff(); 22 | LoRa.sleep(); 23 | delay(1000); 24 | esp_sleep_enable_ext0_wakeup((gpio_num_t )BUTTON_1, LOW); 25 | esp_deep_sleep_start(); 26 | } 27 | #endif 28 | 29 | #include 30 | Ticker tick; 31 | 32 | void btmloop() 33 | { 34 | btn.loop(); 35 | } 36 | 37 | void setup() 38 | { 39 | Serial.begin(115200); 40 | while (!Serial); 41 | 42 | #if defined(BUTTON_1) 43 | btn.setLongClickHandler(pressHander); 44 | tick.attach_ms(30,btmloop); 45 | #endif 46 | 47 | if (OLED_RST > 0) { 48 | pinMode(OLED_RST, OUTPUT); 49 | digitalWrite(OLED_RST, HIGH); 50 | delay(100); 51 | digitalWrite(OLED_RST, LOW); 52 | delay(100); 53 | digitalWrite(OLED_RST, HIGH); 54 | } 55 | 56 | display.init(); 57 | display.flipScreenVertically(); 58 | display.clear(); 59 | display.setFont(ArialMT_Plain_16); 60 | display.setTextAlignment(TEXT_ALIGN_CENTER); 61 | display.drawString(display.getWidth() / 2, display.getHeight() / 2, LORA_SENDER ? "LoRa Sender" : "LoRa Receiver"); 62 | display.display(); 63 | delay(2000); 64 | 65 | if (SDCARD_CS > 0) { 66 | display.clear(); 67 | SPIClass sdSPI(VSPI); 68 | sdSPI.begin(SDCARD_SCLK, SDCARD_MISO, SDCARD_MOSI, SDCARD_CS); 69 | if (!SD.begin(SDCARD_CS, sdSPI)) { 70 | display.drawString(display.getWidth() / 2, display.getHeight() / 2, "SDCard FAIL"); 71 | } else { 72 | display.drawString(display.getWidth() / 2, display.getHeight() / 2 - 16, "SDCard PASS"); 73 | uint32_t cardSize = SD.cardSize() / (1024 * 1024); 74 | display.drawString(display.getWidth() / 2, display.getHeight() / 2, "Size: " + String(cardSize) + "MB"); 75 | } 76 | display.display(); 77 | delay(2000); 78 | } 79 | 80 | 81 | String info = ds3231_test(); 82 | if (info != "") { 83 | display.clear(); 84 | display.setFont(ArialMT_Plain_16); 85 | display.setTextAlignment(TEXT_ALIGN_CENTER); 86 | display.drawString(display.getWidth() / 2, display.getHeight() / 2, info); 87 | display.display(); 88 | delay(2000); 89 | } 90 | 91 | WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 92 | if (WiFi.waitForConnectResult() != WL_CONNECTED) { 93 | display.clear(); 94 | Serial.println("WiFi Connect Fail"); 95 | display.drawString(display.getWidth() / 2, display.getHeight() / 2, "WiFi Connect Fail"); 96 | display.display(); 97 | delay(2000); 98 | esp_restart(); 99 | } 100 | Serial.print("Connected : "); 101 | Serial.println(WiFi.SSID()); 102 | Serial.print("IP:"); 103 | Serial.println(WiFi.localIP().toString()); 104 | display.clear(); 105 | display.drawString(display.getWidth() / 2, display.getHeight() / 2, "IP:" + WiFi.localIP().toString()); 106 | display.display(); 107 | delay(2000); 108 | 109 | SPI.begin(CONFIG_CLK, CONFIG_MISO, CONFIG_MOSI, CONFIG_NSS); 110 | LoRa.setPins(CONFIG_NSS, CONFIG_RST, CONFIG_DIO0); 111 | if (!LoRa.begin(BAND)) { 112 | Serial.println("Starting LoRa failed!"); 113 | while (1); 114 | } 115 | if (!LORA_SENDER) { 116 | display.clear(); 117 | display.drawString(display.getWidth() / 2, display.getHeight() / 2, "LoraRecv Ready"); 118 | display.display(); 119 | } 120 | } 121 | 122 | int count = 0; 123 | 124 | void loop() 125 | { 126 | static uint64_t timestamp = 0; 127 | // #if defined(BUTTON_1) 128 | // btn.loop(); 129 | // #endif 130 | #if LORA_SENDER 131 | if (millis() - timestamp > 2500) { 132 | timestamp = millis(); 133 | int32_t rssi; 134 | if (WiFi.status() == WL_CONNECTED) { 135 | rssi = WiFi.RSSI(); 136 | display.clear(); 137 | display.setTextAlignment(TEXT_ALIGN_CENTER); 138 | display.drawString(display.getWidth() / 2, display.getHeight() / 2, "Send RSSI:" + String(rssi)); 139 | display.display(); 140 | LoRa.beginPacket(); 141 | LoRa.print("WiFi RSSI: "); 142 | LoRa.print(rssi); 143 | LoRa.endPacket(); 144 | } else { 145 | Serial.println("WiFi Connect lost ..."); 146 | } 147 | } 148 | #else 149 | if (LoRa.parsePacket()) { 150 | String recv = ""; 151 | while (LoRa.available()) { 152 | recv += (char)LoRa.read(); 153 | } 154 | count++; 155 | display.clear(); 156 | display.drawString(display.getWidth() / 2, display.getHeight() / 2, recv); 157 | String info = "[" + String(count) + "]" + "RSSI " + String(LoRa.packetRssi()); 158 | display.drawString(display.getWidth() / 2, display.getHeight() / 2 - 16, info); 159 | display.display(); 160 | } 161 | #endif 162 | } 163 | -------------------------------------------------------------------------------- /LoRa/board_def.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // #define LORA_V1_0_OLED 4 | // #define LORA_V1_2_OLED 5 | // #define LORA_V1_6_OLED 6 | // #define LORA_V2_0_OLED 7 | // #define LORA_V1_3_OLED 8 | 9 | #define LORA_SENDER 0 10 | // #define LORA_SENDER 1 11 | 12 | #define LORA_PERIOD 868 13 | // #define LORA_PERIOD 915 14 | // #define LORA_PERIOD 433 15 | 16 | #if defined(LORA_V1_0_OLED) 17 | #include 18 | #include "SSD1306Wire.h" 19 | #define OLED_CLASS_OBJ SSD1306Wire 20 | #define OLED_ADDRESS 0x3C 21 | #define OLED_SDA 4 22 | #define OLED_SCL 15 23 | #define OLED_RST 16 24 | #define CONFIG_MOSI 27 25 | #define CONFIG_MISO 19 26 | #define CONFIG_CLK 5 27 | #define CONFIG_NSS 18 28 | #define CONFIG_RST 14 29 | #define CONFIG_DIO0 26 30 | // ! There are two versions of TTGO LoRa V1.0, 31 | // ! the 868 version uses the 3D WiFi antenna, and the 433 version uses the PCB antenna. 32 | // ! You need to change the frequency according to the board. 33 | 34 | #define SDCARD_MOSI -1 35 | #define SDCARD_MISO -1 36 | #define SDCARD_SCLK -1 37 | #define SDCARD_CS -1 38 | #define BUTTON_1 0 39 | 40 | #elif defined(LORA_V1_2_OLED) 41 | //Lora V1.2 ds3231 42 | #include 43 | #include "SSD1306Wire.h" 44 | #define OLED_CLASS_OBJ SSD1306Wire 45 | #define OLED_ADDRESS 0x3C 46 | #define OLED_SDA 21 47 | #define OLED_SCL 22 48 | #define OLED_RST -1 49 | #define CONFIG_MOSI 27 50 | #define CONFIG_MISO 19 51 | #define CONFIG_CLK 5 52 | #define CONFIG_NSS 18 53 | #define CONFIG_RST 23 54 | #define CONFIG_DIO0 26 55 | 56 | #define SDCARD_MOSI -1 57 | #define SDCARD_MISO -1 58 | #define SDCARD_SCLK -1 59 | #define SDCARD_CS -1 60 | 61 | #define ENABLE_DS3231 62 | 63 | #elif defined(LORA_V1_6_OLED) 64 | #include 65 | #include "SSD1306Wire.h" 66 | #define OLED_CLASS_OBJ SSD1306Wire 67 | #define OLED_ADDRESS 0x3C 68 | #define OLED_SDA 21 69 | #define OLED_SCL 22 70 | #define OLED_RST -1 71 | 72 | #define CONFIG_MOSI 27 73 | #define CONFIG_MISO 19 74 | #define CONFIG_CLK 5 75 | #define CONFIG_NSS 18 76 | #define CONFIG_RST 23 77 | #define CONFIG_DIO0 26 78 | 79 | #define SDCARD_MOSI 15 80 | #define SDCARD_MISO 2 81 | #define SDCARD_SCLK 14 82 | #define SDCARD_CS 13 83 | 84 | #elif defined(LORA_V2_0_OLED) 85 | #include 86 | #include "SSD1306Wire.h" 87 | #define OLED_CLASS_OBJ SSD1306Wire 88 | #define OLED_ADDRESS 0x3C 89 | #define OLED_SDA 21 90 | #define OLED_SCL 22 91 | #define OLED_RST -1 92 | 93 | #define CONFIG_MOSI 19//27 94 | #define CONFIG_MISO 27//19 95 | #define CONFIG_CLK 5 96 | #define CONFIG_NSS 18 97 | #define CONFIG_RST 14//23 98 | #define CONFIG_DIO0 26 99 | 100 | #define SDCARD_MOSI 15 101 | #define SDCARD_MISO 2 102 | #define SDCARD_SCLK 14 103 | #define SDCARD_CS 13 104 | 105 | #elif defined(LORA_V1_3_OLED) 106 | 107 | #include 108 | #include "SSD1306Wire.h" 109 | #define OLED_CLASS_OBJ SSD1306Wire 110 | #define OLED_ADDRESS 0x3C 111 | #define OLED_SDA 21 112 | #define OLED_SCL 22 113 | #define OLED_RST 16 114 | #define CONFIG_MOSI 27 115 | #define CONFIG_MISO 19 116 | #define CONFIG_CLK 5 117 | #define CONFIG_NSS 18 118 | #define CONFIG_RST 14 119 | #define CONFIG_DIO0 26 120 | 121 | #define SDCARD_MOSI -1 122 | #define SDCARD_MISO -1 123 | #define SDCARD_SCLK -1 124 | #define SDCARD_CS -1 125 | #define BUTTON_1 36 126 | 127 | #else 128 | #error "please select board" 129 | #endif 130 | 131 | 132 | #if LORA_PERIOD == 433 133 | #define BAND 433E6 134 | #elif LORA_PERIOD == 868 135 | #define BAND 868E6 136 | #elif LORA_PERIOD == 915 137 | #define BAND 915E6 138 | #else 139 | #error "Please select the correct lora frequency" 140 | #endif 141 | -------------------------------------------------------------------------------- /LoRa/ds3231.cpp: -------------------------------------------------------------------------------- 1 | #include "ds3231.h" 2 | 3 | #ifdef ENABLE_DS3231 4 | #include 5 | 6 | RtcDS3231 rtc(Wire); 7 | 8 | String ds3231_test() 9 | { 10 | rtc.Begin(); 11 | RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__); 12 | if (!rtc.IsDateTimeValid()) { 13 | rtc.SetDateTime(compiled); 14 | } 15 | if (!rtc.GetIsRunning()) { 16 | Serial.println("RTC was not actively running, starting now"); 17 | rtc.SetIsRunning(true); 18 | } 19 | RtcDateTime now = rtc.GetDateTime(); 20 | if (now < compiled) { 21 | Serial.println("RTC is older than compile time! (Updating DateTime)"); 22 | rtc.SetDateTime(compiled); 23 | } 24 | 25 | rtc.Enable32kHzPin(false); 26 | 27 | rtc.SetSquareWavePin(DS3231SquareWavePin_ModeAlarmOne); 28 | 29 | rtc.LatchAlarmsTriggeredFlags(); 30 | 31 | RtcTemperature temp = rtc.GetTemperature(); 32 | Serial.print("RTC Temp : "); 33 | temp.Print(Serial); 34 | Serial.println(); 35 | 36 | now = rtc.GetDateTime(); 37 | char datestring[20]; 38 | Serial.print("RTC Date : "); 39 | 40 | snprintf_P(datestring, 41 | sizeof(datestring) / sizeof(datestring[0]), 42 | PSTR("%02u/%02u/%04u"), 43 | now.Month(), 44 | now.Day(), 45 | now.Year()); 46 | 47 | return String(datestring); 48 | } 49 | #endif -------------------------------------------------------------------------------- /LoRa/ds3231.h: -------------------------------------------------------------------------------- 1 | #pragma onec 2 | #include "board_def.h" 3 | #ifdef ENABLE_DS3231 4 | String ds3231_test(); 5 | #else 6 | #define ds3231_test() "" 7 | #endif -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | TTGO LORA Series 2 | ============================== 3 | ![](1.png) 4 | 5 | ## BOARD PINS 6 | | Name | V1.0 | V1.2(T-Fox) | V1.3 | V1.6 | V2.0 | 7 | | ----------- | ---- | ----------- | ---- | ---- | ---- | 8 | | OLED RST | 16 | N/A | 16 | N/A | N/A | 9 | | OLED SDA | 4 | 21 | 21 | 21 | 21 | 10 | | OLED SCL | 15 | 22 | 22 | 22 | 22 | 11 | | SDCard CS | N/A | N/A | N/A | 13 | 13 | 12 | | SDCard MOSI | N/A | N/A | N/A | 15 | 15 | 13 | | SDCard MISO | N/A | N/A | N/A | 2 | 2 | 14 | | SDCard SCLK | N/A | N/A | N/A | 14 | 14 | 15 | | DS3231 SDA | N/A | 21 | N/A | N/A | N/A | 16 | | DS3231 SCL | N/A | 22 | N/A | N/A | N/A | 17 | | LORA MOSI | 27 | 27 | 27 | 27 | 27 | 18 | | LORA MISO | 19 | 19 | 19 | 19 | 19 | 19 | | LORA SCLK | 5 | 5 | 5 | 5 | 5 | 20 | | LORA CS | 18 | 18 | 18 | 18 | 18 | 21 | | LORA RST | 14 | 23 | 14 | 23 | 23 | 22 | | LORA DIO0 | 26 | 26 | 26 | 26 | 26 | 23 | 24 | 25 | ## First 26 | 27 | - For the first time, change the macro definition in `board_def.h` according to the corresponding layout and screen, and change the version to be used 28 | ``` 29 | #define LORA_V1_0_OLED 30 | #define LORA_V1_2_OLED 31 | #define LORA_V1_6_OLED 32 | #define LORA_V2_0_OLED 33 | #define LORA_V1_3_OLED 34 | ``` 35 | 36 | - Set the corresponding macro definition according to the lora frequency of the actual module 37 | ``` 38 | #define LORA_PERIOD 433 39 | // #define LORA_PERIOD 868 40 | // #define LORA_PERIOD 915 41 | 42 | ``` 43 | 44 | - Sender definition `LORA_SENDER` is 1, 0 is receiving 45 | 46 | ## Install the following dependency library files: 47 | - [arduino-LoRa](https://github.com/sandeepmistry/arduino-LoRa) 48 | - [oled-ssd1306](https://github.com/ThingPulse/esp8266-oled-ssd1306) 49 | 50 | -------------------------------------------------------------------------------- /ReceiverBin/Receiver_V1_0_868.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewisxhe/TTGO-LoRa-Series/80e59c6779aca08641e0a00b2f1375dd035dd35b/ReceiverBin/Receiver_V1_0_868.bin -------------------------------------------------------------------------------- /ReceiverBin/Receiver_V1_2_433.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewisxhe/TTGO-LoRa-Series/80e59c6779aca08641e0a00b2f1375dd035dd35b/ReceiverBin/Receiver_V1_2_433.bin -------------------------------------------------------------------------------- /ReceiverBin/Receiver_V1_2_868.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewisxhe/TTGO-LoRa-Series/80e59c6779aca08641e0a00b2f1375dd035dd35b/ReceiverBin/Receiver_V1_2_868.bin -------------------------------------------------------------------------------- /ReceiverBin/Recv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewisxhe/TTGO-LoRa-Series/80e59c6779aca08641e0a00b2f1375dd035dd35b/ReceiverBin/Recv.png -------------------------------------------------------------------------------- /SenderBin/Sender.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewisxhe/TTGO-LoRa-Series/80e59c6779aca08641e0a00b2f1375dd035dd35b/SenderBin/Sender.png -------------------------------------------------------------------------------- /SenderBin/Sender_V1_0_868.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewisxhe/TTGO-LoRa-Series/80e59c6779aca08641e0a00b2f1375dd035dd35b/SenderBin/Sender_V1_0_868.bin -------------------------------------------------------------------------------- /SenderBin/Sender_V1_2_433.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewisxhe/TTGO-LoRa-Series/80e59c6779aca08641e0a00b2f1375dd035dd35b/SenderBin/Sender_V1_2_433.bin -------------------------------------------------------------------------------- /SenderBin/Sender_V1_2_868.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lewisxhe/TTGO-LoRa-Series/80e59c6779aca08641e0a00b2f1375dd035dd35b/SenderBin/Sender_V1_2_868.bin --------------------------------------------------------------------------------