├── ESP32_LoRaReceiver_Simple.ino ├── ESP32_LoRa_BME280_Sender_Sleep_01.ino ├── ESP32_TTGO_LORA_OLED_Receiver.ino ├── Licence.txt └── README.md /ESP32_LoRaReceiver_Simple.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include //https://github.com/sandeepmistry/arduino-LoRa 3 | 4 | void setup() { 5 | Serial.begin(115200); 6 | Serial.println("LoRa Receiver"); 7 | LoRa.setPins(18, 14, 26); 8 | if (!LoRa.begin(433E6)) { 9 | Serial.println("Starting LoRa failed!"); 10 | while (1); 11 | } 12 | } 13 | 14 | void loop() { 15 | // try to parse packet 16 | int packetSize = LoRa.parsePacket(); 17 | if (packetSize) { 18 | // received a packet 19 | // Serial.print("Received packet "); 20 | 21 | // read packet 22 | while (LoRa.available()) { 23 | Serial.print((char)LoRa.read()); 24 | } 25 | 26 | // print RSSI of packet 27 | Serial.print(" RSSI was: "); 28 | Serial.println(LoRa.packetRssi()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ESP32_LoRa_BME280_Sender_Sleep_01.ino: -------------------------------------------------------------------------------- 1 | /*This software, the ideas and concepts is Copyright (c) David Bird 2014 and beyond. 2 | All rights to this software are reserved. 3 | It is prohibited to redistribute or reproduce of any part or all of the software contents in any form other than the following: 4 | 1. You may print or download to a local hard disk extracts for your personal and non-commercial use only. 5 | 2. You may copy the content to individual third parties for their personal use, but only if you acknowledge the author David Bird as the source of the material. 6 | 3. You may not, except with my express written permission, distribute or commercially exploit the content. 7 | 4. You may not transmit it or store it in any other website or other form of electronic retrieval system for commercial purposes. 8 | 5. You MUST include all of this copyright and permission notice ('as annotated') and this shall be included in all copies or substantial portions of the software and where the software use is visible to an end-user. 9 | THE SOFTWARE IS PROVIDED "AS IS" FOR PRIVATE USE ONLY, IT IS NOT FOR COMMERCIAL USE IN WHOLE OR PART OR CONCEPT. 10 | FOR PERSONAL USE IT IS SUPPLIED WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 11 | IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | #include 14 | #include //https://github.com/sandeepmistry/arduino-LoRa 15 | #include 16 | #include 17 | 18 | Adafruit_BME280 bme; // I2C 19 | 20 | const unsigned long UpdateInterval = 0.25 * (60L * 1000000L); // Update delay in microseconds, currently 15-secs (1/4 of minute) 21 | 22 | void setup() { 23 | Serial.begin(115200); 24 | Serial.println("LoRa Sender starting..."); 25 | LoRa.setPins(18, 14, 26); // LoRa.setPins(CS, RESET, IRQ); 26 | if (!LoRa.begin(868E6)) { // Set frequency to 433, 868 or 915MHz 27 | Serial.println("Could not find a valid LoRa transceiver, check pins used and wiring!"); 28 | delay(1000); 29 | } 30 | bool status = bme.begin(); 31 | if (!status) { 32 | Serial.println("Could not find a valid BME280 sensor, check wiring!"); 33 | delay(1000); 34 | } 35 | Serial.println("Sending data packet..."); 36 | Send_and_Display_Sensor_Data(); 37 | start_sleep(); 38 | } 39 | 40 | void start_sleep(){ 41 | esp_sleep_enable_timer_wakeup(UpdateInterval); 42 | pinMode(BUILTIN_LED,INPUT); // Set pin-5 to an input as sometimes PIN-5 is used for SPI-SS 43 | digitalWrite(BUILTIN_LED,HIGH); // In case it's on, turn LED off, as sometimes PIN-5 on some boards is used for SPI-SS and can be left low 44 | Serial.println("Starting deep-sleep period... awake for "+String(millis())+"mS"); 45 | delay(8); // Enough time for the serial port to finish at 115,200 baud 46 | esp_deep_sleep_start(); // Sleep for the prescribed time 47 | } 48 | 49 | void loop() { 50 | } 51 | 52 | void Send_and_Display_Sensor_Data(){ 53 | LoRa.beginPacket(); // Start LoRa transceiver 54 | LoRa.print("Temp: "+String(bme.readTemperature(),1)+"°C\n"); // Send BME280 temperature reading 55 | LoRa.print("Humi: "+String(bme.readHumidity(),1)+"%\n"); // Send BME280 humidity reading 56 | LoRa.print("Pres: "+String(bme.readPressure()/100+3.7,1)+"hP "); // Send BME280 pressure reading, addition of 3.7 is for calibration purposes 57 | LoRa.endPacket(); // Confirm end of LoRa data packet 58 | LoRa.sleep(); // Send LoRa transceiver to sleep 59 | Serial.print("Temperature : "+String(bme.readTemperature(),1)+"°C\n"); 60 | Serial.print("Humidity : "+String(bme.readHumidity(),1)+"%\n"); 61 | Serial.print("Pressure : "+String(bme.readPressure()/100+3.7,1)+"hP\n"); // 3.7 is added for calibration purposes 62 | } 63 | -------------------------------------------------------------------------------- /ESP32_TTGO_LORA_OLED_Receiver.ino: -------------------------------------------------------------------------------- 1 | /*This software, the ideas and concepts is Copyright (c) David Bird 2014 and beyond. 2 | All rights to this software are reserved. 3 | It is prohibited to redistribute or reproduce of any part or all of the software contents in any form other than the following: 4 | 1. You may print or download to a local hard disk extracts for your personal and non-commercial use only. 5 | 2. You may copy the content to individual third parties for their personal use, but only if you acknowledge the author David Bird as the source of the material. 6 | 3. You may not, except with my express written permission, distribute or commercially exploit the content. 7 | 4. You may not transmit it or store it in any other website or other form of electronic retrieval system for commercial purposes. 8 | 5. You MUST include all of this copyright and permission notice ('as annotated') and this shall be included in all copies or substantial portions of the software and where the software use is visible to an end-user. 9 | THE SOFTWARE IS PROVIDED "AS IS" FOR PRIVATE USE ONLY, IT IS NOT FOR COMMERCIAL USE IN WHOLE OR PART OR CONCEPT. 10 | FOR PERSONAL USE IT IS SUPPLIED WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 11 | IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | */ 13 | 14 | #include "SSD1306Wire.h" 15 | #include //https://github.com/sandeepmistry/arduino-LoRa 16 | 17 | #define SCK 5 // GPIO5 - SX1278's SCK 18 | #define MISO 19 // GPIO19 - SX1278's MISO 19 | #define MOSI 27 // GPIO27 - SX1278's MOSI 20 | #define SS 18 // GPIO18 - SX1278's CS 21 | #define RST 14 // GPIO14 - SX1278's RESET 22 | #define DI0 26 // GPIO26 - SX1278's IRQ (interrupt request) 23 | #define BAND 868E6 // 915E6 24 | 25 | SSD1306Wire display (0x3c, 4, 15); 26 | String rssi = "RSSI "; 27 | String packSize = "-"; 28 | String packet; 29 | 30 | void setup () { 31 | pinMode(2, OUTPUT); 32 | pinMode(16, OUTPUT); 33 | digitalWrite(16, LOW); // set GPIO16 low to reset OLED 34 | delay (50); 35 | digitalWrite(16, HIGH); // while OLED is running, GPIO16 must go high, 36 | 37 | Serial.begin(115200); 38 | Serial.println("LoRa Receiver Callback"); 39 | SPI.begin(SCK, MISO, MOSI, SS); 40 | LoRa.setPins(SS, RST, DI0); 41 | if (! LoRa.begin(BAND)) { 42 | Serial.println("Starting LoRa failed!"); 43 | while (1); 44 | } 45 | //LoRa.onReceive(cbk); 46 | LoRa.receive(); 47 | Serial.println("init ok"); 48 | display.init(); 49 | display.flipScreenVertically (); 50 | display.setFont(ArialMT_Plain_16); 51 | delay (1500); 52 | } 53 | 54 | void loop () { 55 | // try to parse packet 56 | int packetSize = LoRa.parsePacket(); 57 | if (packetSize) { // received a packet 58 | Serial.print("Received packet '"); 59 | while (LoRa.available()) { // read packet 60 | packet = LoRa.readString(); 61 | Serial.print(packet); 62 | } 63 | Serial.print("' with RSSI "); 64 | Serial.println(LoRa.packetRssi()); // print RSSI of packet 65 | display.clear(); 66 | display.setTextAlignment (TEXT_ALIGN_LEFT); 67 | display.setFont(ArialMT_Plain_10); 68 | display.drawString(0, 0, rssi+String(LoRa.packetRssi())+ "Rx: " + String(packetSize) + " Bytes"); 69 | display.drawString(0, 20, packet); 70 | Serial.println(packet); 71 | packet = ""; 72 | display.display (); 73 | digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level) 74 | delay (500); // wait for a second 75 | digitalWrite(2, LOW); // turn the LED off by making the voltage LOW 76 | delay (500); // wait for a second 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Licence.txt: -------------------------------------------------------------------------------- 1 | This software, the ideas and concepts is Copyright (c) David Bird 2014 and beyond. 2 | 3 | All rights to this software are reserved. 4 | 5 | It is prohibited to redistribute or reproduce of any part or all of the software contents in any form other than the following: 6 | 7 | 1. You may print or download to a local hard disk extracts for your personal and non-commercial use only. 8 | 9 | 2. You may copy the content to individual third parties for their personal use, but only if you acknowledge the author David Bird as the source of the material. 10 | 11 | 3. You may not, except with my express written permission, distribute or commercially exploit the content. 12 | 13 | 4. You may not transmit it or store it in any other website or other form of electronic retrieval system for commercial purposes. 14 | 15 | 5. You MUST include all of this copyright and permission notice ('as annotated') and this shall be included in all copies or substantial portions of the software and where the software use is visible to an end-user. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS" FOR PRIVATE USE ONLY, IT IS NOT FOR COMMERCIAL USE IN WHOLE OR PART OR CONCEPT. 18 | 19 | FOR PERSONAL USE IT IS SUPPLIED WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | 21 | IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP32_LoRa_Examples 2 | Using an ESP32 plus LoRa module to send data over long distances 3 | 4 | Set your frequency according to your country e.g. 433, 868 or 914Mhz 5 | 6 | Programme the ESP32 in the normal way, choose the exatc board type or a default ESP32 unit, in general it does not matter. 7 | 8 | --------------------------------------------------------------------------------