Skip to content

Instantly share code, notes, and snippets.

@GSE-UP
Last active November 22, 2018 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GSE-UP/a57bb0991d99d2a4f3305c1e5b351475 to your computer and use it in GitHub Desktop.
Save GSE-UP/a57bb0991d99d2a4f3305c1e5b351475 to your computer and use it in GitHub Desktop.
LoRa 32 WIFI Receiver
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h> //responsible for i2c communication
#include "SSD1306Wire.h"
#define SS 18
#define RST 14
#define DI0 26
SSD1306Wire display(0x3c, 4, 15);
void setup() {
//battery
pinMode(32, INPUT);
//set pin as output
pinMode(16,OUTPUT); //OLED RST
pinMode(25,OUTPUT);
digitalWrite(16, LOW); //resets OLED
delay(50);
digitalWrite(16, HIGH); //while OLED is on, GPIO might be HIGH
//Starts LoRa's display
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
SPI.begin(5, 19, 27, 18);
LoRa.setPins(SS, RST, DI0);
Serial.begin(4800);
while (!Serial);
//433E6, 868E6, 915E6
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
//clear LoRa's display
display.clear();
display.drawString(0, 0, "LoRa Initial success!");
display.display();//showcase the string on LoRa's display
}
void loop() {
String packet="", rssi;
float bat=analogRead(32);//reads battery value
int packetSize = LoRa.parsePacket();
if(packetSize){
//while there's something on LoRa's packet
while (LoRa.available())
packet += (char)LoRa.read();//reads and save the string
//sends string to Serial
for(int i=0;i<packet.length();i++)
Serial.write(packet[i]);
rssi = (String)LoRa.packetRssi();
//clear LoRa's display
display.clear();
display.drawString(0, 0, "GSE - RECEIVER");
display.drawString(0, 10, "RSSI:");
display.drawString(50, 10, rssi);
display.drawString(0, 20, "Packet:");
display.drawString(50, 20, packet);
display.drawString(0, 30, "Battery:");
display.drawString(50, 30, (String)bat);
display.display();//showcase the string on LoRa's display
}
//pause for 1 second for each byte
delay(1000*packet.length());
//clear other packets
LoRa.flush();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment