-
Notifications
You must be signed in to change notification settings - Fork 423
/
Copy pathmain.cpp
70 lines (56 loc) · 1.78 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
RadioLib Non-Arduino Raspberry Pi Example
This example shows how to use RadioLib without Arduino.
In this case, a Raspberry Pi with WaveShare SX1302 LoRaWAN Hat
using the lgpio library
https://abyz.me.uk/lg/lgpio.html
Can be used as a starting point to port RadioLib to any platform!
See this API reference page for details on the RadioLib hardware abstraction
https://jgromes.github.io/RadioLib/class_hal.html
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// include the hardware abstraction layer
#include "hal/RPi/PiHal.h"
// create a new instance of the HAL class
// use SPI channel 1, because on Waveshare LoRaWAN Hat,
// the SX1261 CS is connected to CE1
PiHal* hal = new PiHal(1);
// now we can create the radio module
// pinout corresponds to the Waveshare LoRaWAN Hat
// NSS pin: 7
// DIO1 pin: 17
// NRST pin: 22
// BUSY pin: not connected
SX1261 radio = new Module(hal, 7, 17, 22, RADIOLIB_NC);
// the entry point for the program
int main(int argc, char** argv) {
// initialize just like with Arduino
printf("[SX1261] Initializing ... ");
int state = radio.begin();
if (state != RADIOLIB_ERR_NONE) {
printf("failed, code %d\n", state);
return(1);
}
printf("success!\n");
// loop forever
int count = 0;
for(;;) {
// send a packet
printf("[SX1261] Transmitting packet ... ");
char str[64];
sprintf(str, "Hello World! #%d", count++);
state = radio.transmit(str);
if(state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
printf("success!\n");
// wait for a second before transmitting again
hal->delay(1000);
} else {
printf("failed, code %d\n", state);
}
}
return(0);
}