Created
February 8, 2018 23:05
-
-
Save YongHuax/f7f9928d1c75f0f04e7c32eb0cee9d52 to your computer and use it in GitHub Desktop.
FYP_Final_LoRa_Sender
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
/* | |
This is a simple example show the LoRa sended data in OLED. | |
The onboard OLED display is SSD1306 driver and I2C interface. In order to make the | |
OLED correctly operation, you should output a high-low-high(1-0-1) signal by soft- | |
ware to OLED's reset pin, the low-level signal at least 5ms. | |
OLED pins to ESP32 GPIOs via this connecthin: | |
OLED_SDA -- GPIO4 | |
OLED_SCL -- GPIO15 | |
OLED_RST -- GPIO16 | |
by Aaron.Lee from HelTec AutoMation, ChengDu, China | |
成都惠利特自动化科技有限公司 | |
*/ | |
#include <SPI.h> | |
#include <LoRa.h> | |
#include <Wire.h> | |
#include "SSD1306.h" | |
#include "images.h" | |
// Pin definetion of WIFI LoRa 32 | |
// HelTec AutoMation 2017 support@heltec.cn | |
#define SCK 5 // GPIO5 -- SX127x's SCK | |
#define MISO 19 // GPIO19 -- SX127x's MISO | |
#define MOSI 27 // GPIO27 -- SX127x's MOSI | |
#define SS 18 // GPIO18 -- SX127x's CS | |
#define RST 14 // GPIO14 -- SX127x's RESET | |
#define DI00 26 // GPIO26 -- SX127x's IRQ(Interrupt Request) | |
#define BAND 433E6 //you can set band here directly,e.g. 868E6,915E6 | |
#define PABOOST true | |
unsigned int counter = 0; | |
SSD1306 display(0x3c, 4, 15); | |
String rssi = "RSSI --"; | |
String packSize = "--"; | |
String packet ; | |
String payload = | |
www.heltec.cn | |
this project also realess in GitHub: | |
https://github.com/Heltec-Aaron-Lee/WiFi_Kit_series ; | |
void logo() | |
{ | |
display.clear(); | |
display.drawXbm(0,5,logo_width,logo_height,logo_bits); | |
display.display(); | |
} | |
void setup() | |
{ | |
pinMode(16,OUTPUT); | |
pinMode(25,OUTPUT); | |
digitalWrite(16, LOW); // set GPIO16 low to reset OLED | |
delay(50); | |
digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high | |
display.init(); | |
display.flipScreenVertically(); | |
display.setFont(ArialMT_Plain_10); | |
logo(); | |
delay(1500); | |
display.clear(); | |
SPI.begin(SCK,MISO,MOSI,SS); | |
LoRa.setPins(SS,RST,DI00); | |
if (!LoRa.begin(BAND,PABOOST)) | |
{ | |
display.drawString(0, 0, "Starting LoRa failed!"); | |
display.display(); | |
while (1); | |
} | |
display.drawString(0, 0, "LoRa Initial success!"); | |
display.display(); | |
delay(1000); | |
} | |
void loop() | |
{ | |
display.clear(); | |
display.setTextAlignment(TEXT_ALIGN_LEFT); | |
display.setFont(ArialMT_Plain_10); | |
display.drawString(0, 0, "Sending packet: "); | |
//display.drawString(90, 0, String(counter)); | |
display.drawString(0, 20, String("message")); | |
display.drawString(70, 20, String(payload)); | |
display.display(); | |
// send packet | |
LoRa.beginPacket(); | |
LoRa.print(payload); | |
// LoRa.print(counter); | |
LoRa.endPacket(); | |
counter++; | |
digitalWrite(25, HIGH); // turn the LED on (HIGH is the voltage level) | |
delay(1000); // wait for a second | |
digitalWrite(25, LOW); // turn the LED off by making the voltage LOW | |
delay(1000); // wait for a second | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment