Added example of reciver
This commit is contained in:
parent
ed90612b9b
commit
cff059d952
|
|
@ -1,3 +1,8 @@
|
|||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
# ---> C++
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
|
@ -31,4 +36,3 @@
|
|||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
#### Board
|
||||
|
||||
https://www.banggood.com/2Pcs-LILYGO-TTGO-433-or-470MHz-SX1278-ESP32-LoRa-0_96-Inch-Blue-OLED-Display-bluetooth-WIFI-Module-p-1271663.html?akmClientCountry=SE&utm_design=18&utm_email=1618462506_2324&utm_source=emarsys&utm_medium=Shipoutinform190813&utm_campaign=trigger-logistics&utm_content=leander&sc_src=email_2671705&sc_eh=b89a072d6be32cd21&sc_llid=28998133&sc_lid=104858042&sc_uid=I3GU9NeuSO&cur_warehouse=CN
|
||||
|
||||
#### PINS
|
||||

|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:ttgo-lora32-v1]
|
||||
platform = espressif32
|
||||
board = ttgo-lora32-v1
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
lib_deps =
|
||||
thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.5.0
|
||||
sandeepmistry/LoRa@^0.8.0
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
|
||||
#include <WiFi.h>
|
||||
#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 SCK
|
||||
// GPIO19 SX1278 MISO
|
||||
// GPIO27 SX1278 MOSI
|
||||
// GPIO18 SX1278 CS
|
||||
// GPIO14 SX1278 RESET
|
||||
// GPIO26 SX1278 IRQ(Interrupt Request)
|
||||
|
||||
#define SS 18
|
||||
#define RST 14
|
||||
#define DI0 26
|
||||
// #define BAND 429E6 //915E6
|
||||
|
||||
// #define BAND 434500000.00
|
||||
#define BAND 434500000.00
|
||||
|
||||
#define spreadingFactor 9
|
||||
// #define SignalBandwidth 62.5E3
|
||||
#define SignalBandwidth 31.25E3
|
||||
#define preambleLength 8
|
||||
#define codingRateDenominator 8
|
||||
|
||||
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.print("LoRa Spreading Factor: ");
|
||||
Serial.println(spreadingFactor);
|
||||
LoRa.setSpreadingFactor(spreadingFactor);
|
||||
|
||||
Serial.print("LoRa Signal Bandwidth: ");
|
||||
Serial.println(SignalBandwidth);
|
||||
LoRa.setSignalBandwidth(SignalBandwidth);
|
||||
|
||||
LoRa.setCodingRate4(codingRateDenominator);
|
||||
|
||||
LoRa.setPreambleLength(preambleLength);
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
This directory is intended for PlatformIO Test Runner and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||
Loading…
Reference in New Issue