-
Notifications
You must be signed in to change notification settings - Fork 2
/
Arduino_Receive.ino
65 lines (52 loc) · 1.19 KB
/
Arduino_Receive.ino
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
/*
Hafidh Satyanto
Arduino Groundstation Code
Receives over-the-air serial character arrays via LoRa from another transceiver and then converts to string
to groundstation Raspberry Pi, of which it would then be parsed and processed.
*/
#include <SPI.h>
#include <RH_RF95.h>
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 3
#define RF95_FREQ 915.0
RH_RF95 rf95(RFM95_CS, RFM95_INT);
void setup()
{
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
Serial.begin(9600);
while (!Serial) {
delay(1);
}
delay(500);
digitalWrite(RFM95_RST, LOW);
delay(100);
digitalWrite(RFM95_RST, HIGH);
delay(100);
while(!rf95.init()) {
Serial.println("LoRa radio initialization failed.");
while(1);
}
Serial.println("LoRa radio initialization OK!");
rf95.setTxPower(23, false);
}
void loop()
{
if (rf95.available())
{
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.recv(buf, &len))
{
Serial.print("Received: ");
Serial.write((char*)buf);
Serial.print("\n RSSI: ");
Serial.println(rf95.lastRssi(), DEC);
}
else
{
Serial.println("Receive failed.");
}
}
}