mirror of
https://gitlab.com/zwirbel/sprocket-device-bb1.git
synced 2025-12-16 10:04:32 +01:00
base stack
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
#include <SPI.h>
|
||||
#include <LoRa.h>
|
||||
#include "SSD1306.h"
|
||||
|
||||
SSD1306 display(0x3c, 4, 15);
|
||||
|
||||
//OLED pins to ESP32 GPIOs via this connection:
|
||||
//OLED_SDA -- GPIO4
|
||||
//OLED_SCL -- GPIO15
|
||||
//OLED_RST -- GPIO16
|
||||
|
||||
|
||||
// WIFI_LoRa_32 ports
|
||||
|
||||
// GPIO5 -- SX1278's SCK
|
||||
// GPIO19 -- SX1278's MISO
|
||||
// GPIO27 -- SX1278's MOSI
|
||||
// GPIO18 -- SX1278's CS
|
||||
// GPIO14 -- SX1278's RESET
|
||||
// GPIO26 -- SX1278's IRQ(Interrupt Request)
|
||||
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DI0 26
|
||||
#define BAND 433E6
|
||||
|
||||
|
||||
void setup() {
|
||||
pinMode(16,OUTPUT);
|
||||
digitalWrite(16, LOW); // set GPIO16 low to reset OLED
|
||||
delay(50);
|
||||
digitalWrite(16, HIGH);
|
||||
|
||||
display.init();
|
||||
display.flipScreenVertically();
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
|
||||
Serial.begin(115200);
|
||||
while (!Serial); //if just the the basic function, must connect to a computer
|
||||
delay(1000);
|
||||
|
||||
Serial.println("LoRa Receiver");
|
||||
display.drawString(5,5,"LoRa Receiver");
|
||||
display.display();
|
||||
SPI.begin(5,19,27,18);
|
||||
LoRa.setPins(SS,RST,DI0);
|
||||
|
||||
if (!LoRa.begin(BAND)) {
|
||||
display.drawString(5,25,"Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
Serial.println("LoRa Initial OK!");
|
||||
display.drawString(5,25,"LoRa Initializing OK!");
|
||||
display.display();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// try to parse packet
|
||||
int packetSize = LoRa.parsePacket();
|
||||
if (packetSize) {
|
||||
// received a packets
|
||||
Serial.print("Received packet. ");
|
||||
display.clear();
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
display.drawString(3, 0, "Received packet ");
|
||||
display.display();
|
||||
|
||||
// read packet
|
||||
while (LoRa.available()) {
|
||||
String data = LoRa.readString();
|
||||
Serial.print(data);
|
||||
display.drawString(20,22, data);
|
||||
display.display();
|
||||
}
|
||||
|
||||
// print RSSI of packet
|
||||
Serial.print(" with RSSI ");
|
||||
Serial.println(LoRa.packetRssi());
|
||||
display.drawString(20, 45, "RSSI: ");
|
||||
display.drawString(70, 45, (String)LoRa.packetRssi());
|
||||
display.display();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// This example just provide basic LoRa function test;
|
||||
// Not the LoRa's farthest distance or strongest interference immunity.
|
||||
// For more informations, please vist www.heltec.cn or mail to support@heltec.cn
|
||||
|
||||
#include <SPI.h>
|
||||
#include <LoRa.h>
|
||||
|
||||
// WIFI_LoRa_32 ports
|
||||
|
||||
// GPIO5 -- SX1278's SCK
|
||||
// GPIO19 -- SX1278's MISO
|
||||
// GPIO27 -- SX1278's MOSI
|
||||
// GPIO18 -- SX1278's CS
|
||||
// GPIO14 -- SX1278's RESET
|
||||
// GPIO26 -- SX1278's IRQ(Interrupt Request)
|
||||
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DI0 26
|
||||
#define BAND 433E6
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial); //if just the the basic function, must connect to a computer
|
||||
delay(1000);
|
||||
|
||||
Serial.println("LoRa Receiver");
|
||||
|
||||
SPI.begin(5,19,27,18);
|
||||
LoRa.setPins(SS,RST,DI0);
|
||||
|
||||
if (!LoRa.begin(BAND)) {
|
||||
Serial.println("Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// try to parse packet
|
||||
int packetSize = LoRa.parsePacket();
|
||||
if (packetSize) {
|
||||
// received a packet
|
||||
Serial.print("Received packet '");
|
||||
|
||||
// read packet
|
||||
while (LoRa.available()) {
|
||||
Serial.print((char)LoRa.read());
|
||||
}
|
||||
|
||||
// print RSSI of packet
|
||||
Serial.print("' with RSSI ");
|
||||
Serial.println(LoRa.packetRssi());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// This example just provide basic LoRa function test;
|
||||
// Not the LoRa's farthest distance or strongest interference immunity.
|
||||
// For more informations, please vist www.heltec.cn or mail to support@heltec.cn
|
||||
|
||||
#include <SPI.h>
|
||||
#include <LoRa.h>
|
||||
|
||||
// WIFI_LoRa_32 ports
|
||||
|
||||
// GPIO5 -- SX1278's SCK
|
||||
// GPIO19 -- SX1278's MISO
|
||||
// GPIO27 -- SX1278's MOSI
|
||||
// GPIO18 -- SX1278's CS
|
||||
// GPIO14 -- SX1278's RESET
|
||||
// GPIO26 -- SX1278's IRQ(Interrupt Request)
|
||||
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DI0 26
|
||||
#define BAND 433E6
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial); //if just the the basic function, must connect to a computer
|
||||
|
||||
SPI.begin(5,19,27,18);
|
||||
LoRa.setPins(SS,RST,DI0);
|
||||
|
||||
Serial.println("LoRa Receiver Callback");
|
||||
|
||||
if (!LoRa.begin(BAND)) {
|
||||
Serial.println("Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
|
||||
// register the receive callback
|
||||
LoRa.onReceive(onReceive);
|
||||
|
||||
// put the radio into receive mode
|
||||
LoRa.receive();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void onReceive(int packetSize) {
|
||||
// received a packet
|
||||
Serial.print("Received packet '");
|
||||
|
||||
// read packet
|
||||
for (int i = 0; i < packetSize; i++) {
|
||||
Serial.print((char)LoRa.read());
|
||||
}
|
||||
|
||||
// print RSSI of packet
|
||||
Serial.print("' with RSSI ");
|
||||
Serial.println(LoRa.packetRssi());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#include <SPI.h>
|
||||
#include <LoRa.h>
|
||||
#include "SSD1306.h"
|
||||
#include<Arduino.h>
|
||||
|
||||
//OLED pins to ESP32 GPIOs via this connecthin:
|
||||
//OLED_SDA -- GPIO4
|
||||
//OLED_SCL -- GPIO15
|
||||
//OLED_RST -- GPIO16
|
||||
|
||||
SSD1306 display(0x3c, 4, 15);
|
||||
|
||||
|
||||
// WIFI_LoRa_32 ports
|
||||
|
||||
// GPIO5 -- SX1278's SCK
|
||||
// GPIO19 -- SX1278's MISO
|
||||
// GPIO27 -- SX1278's MOSI
|
||||
// GPIO18 -- SX1278's CS
|
||||
// GPIO14 -- SX1278's RESET
|
||||
// GPIO26 -- SX1278's IRQ(Interrupt Request)
|
||||
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DI0 26
|
||||
#define BAND 433E6 //915E6
|
||||
|
||||
int counter = 0;
|
||||
|
||||
void setup() {
|
||||
pinMode(25,OUTPUT); //Send success, LED will bright 1 second
|
||||
|
||||
pinMode(16,OUTPUT);
|
||||
digitalWrite(16, LOW); // set GPIO16 low to reset OLED
|
||||
delay(50);
|
||||
digitalWrite(16, HIGH);
|
||||
|
||||
Serial.begin(115200);
|
||||
while (!Serial); //If just the the basic function, must connect to a computer
|
||||
|
||||
// Initialising the UI will init the display too.
|
||||
display.init();
|
||||
display.flipScreenVertically();
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display.drawString(5,5,"LoRa Sender");
|
||||
display.display();
|
||||
|
||||
SPI.begin(5,19,27,18);
|
||||
LoRa.setPins(SS,RST,DI0);
|
||||
Serial.println("LoRa Sender");
|
||||
if (!LoRa.begin(BAND)) {
|
||||
Serial.println("Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
Serial.println("LoRa Initial OK!");
|
||||
display.drawString(5,20,"LoRa Initializing OK!");
|
||||
display.display();
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print("Sending packet: ");
|
||||
Serial.println(counter);
|
||||
|
||||
display.clear();
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
display.drawString(3, 5, "Sending packet ");
|
||||
display.drawString(50, 30, String(counter));
|
||||
display.display();
|
||||
|
||||
// send packet
|
||||
LoRa.beginPacket();
|
||||
LoRa.print("Hello..");
|
||||
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
|
||||
|
||||
delay(3000);
|
||||
}
|
||||
59
lib/esp32_lora_wifi/LoRa/examples/LoRaSender/LoRaSender.ino
Normal file
59
lib/esp32_lora_wifi/LoRa/examples/LoRaSender/LoRaSender.ino
Normal file
@@ -0,0 +1,59 @@
|
||||
// This example just provide basic LoRa function test;
|
||||
// Not the LoRa's farthest distance or strongest interference immunity.
|
||||
// For more informations, please vist www.heltec.cn or mail to support@heltec.cn
|
||||
|
||||
#include <SPI.h>
|
||||
#include <LoRa.h>
|
||||
#include<Arduino.h>
|
||||
|
||||
// WIFI_LoRa_32 ports
|
||||
|
||||
// GPIO5 -- SX1278's SCK
|
||||
// GPIO19 -- SX1278's MISO
|
||||
// GPIO27 -- SX1278's MOSI
|
||||
// GPIO18 -- SX1278's CS
|
||||
// GPIO14 -- SX1278's RESET
|
||||
// GPIO26 -- SX1278's IRQ(Interrupt Request)
|
||||
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DI0 26
|
||||
#define BAND 433E6 //915E6 -- 这里的模式选择中,检查一下是否可在中国实用915这个频段
|
||||
|
||||
int counter = 0;
|
||||
|
||||
void setup() {
|
||||
pinMode(25,OUTPUT); //Send success, LED will bright 1 second
|
||||
|
||||
Serial.begin(115200);
|
||||
while (!Serial); //If just the the basic function, must connect to a computer
|
||||
|
||||
SPI.begin(5,19,27,18);
|
||||
LoRa.setPins(SS,RST,DI0);
|
||||
// Serial.println("LoRa Sender");
|
||||
|
||||
if (!LoRa.begin(BAND)) {
|
||||
Serial.println("Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
Serial.println("LoRa Initial OK!");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print("Sending packet: ");
|
||||
Serial.println(counter);
|
||||
|
||||
// send packet
|
||||
LoRa.beginPacket();
|
||||
LoRa.print("hello ");
|
||||
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
|
||||
|
||||
delay(3000);
|
||||
}
|
||||
Reference in New Issue
Block a user