RadioLib/examples/NonArduino/Raspberry/main.cpp

67 wiersze
1.6 KiB
C++
Czysty Zwykły widok Historia

/*
RadioLib Non-Arduino Raspberry Pi Example
2023-04-30 20:10:48 +00:00
This example shows how to use RadioLib without Arduino.
2023-04-30 20:10:48 +00:00
In this case, a Raspberry Pi with WaveShare SX1302 LoRaWAN Hat
using the pigpio library.
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
2023-05-16 16:12:45 +00:00
#include <RadioLib.h>
2023-05-06 17:34:41 +00:00
// include the hardware abstraction layer
#include "PiHal.h"
2023-04-18 17:21:01 +00:00
2023-04-30 20:10:48 +00:00
// 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
2023-04-30 20:10:48 +00:00
// pinout corresponds to the Waveshare LoRaWAN Hat
// NSS pin: 7
// DIO1 pin: 17
// NRST pin: 22
// BUSY pin: 4
SX1261 radio = new Module(hal, 7, 17, 22, 4);
// the entry point for the program
int main(int argc, char** argv) {
// initialize just like with Arduino
2023-04-30 20:10:48 +00:00
printf("[SX1261] Initializing ... ");
int state = radio.begin();
if (state != RADIOLIB_ERR_NONE) {
2023-04-30 20:10:48 +00:00
printf("failed, code %d\n", state);
return(1);
}
2023-04-30 20:10:48 +00:00
printf("success!\n");
2023-04-30 20:10:48 +00:00
// loop forever
for(;;) {
// send a packet
printf("[SX1261] Transmitting packet ... ");
state = radio.transmit("Hello World!");
if(state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
printf("success!");
2023-04-18 17:21:01 +00:00
2023-04-30 20:10:48 +00:00
// wait for a second before transmitting again
hal->delay(1000);
2023-05-06 17:34:41 +00:00
2023-04-30 20:10:48 +00:00
} else {
printf("failed, code %d\n", state);
2023-04-18 17:21:01 +00:00
}
2023-05-06 17:34:41 +00:00
2023-04-18 17:21:01 +00:00
}
2023-04-30 20:10:48 +00:00
return(0);
2023-04-18 17:21:01 +00:00
}