-
Notifications
You must be signed in to change notification settings - Fork 27
/
Basic_RX.ino
71 lines (58 loc) · 2.08 KB
/
Basic_RX.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
66
67
68
69
70
71
/*
Demonstrates simple RX and TX operation.
Any of the Basic_TX examples can be used as a transmitter.
Please read through 'NRFLite.h' for a description of all the methods available in the library.
Radio Arduino
CE -> 9
CSN -> 10 (Hardware SPI SS)
MOSI -> 11 (Hardware SPI MOSI)
MISO -> 12 (Hardware SPI MISO)
SCK -> 13 (Hardware SPI SCK)
IRQ -> No connection
VCC -> No more than 3.6 volts
GND -> GND
*/
#include "SPI.h"
#include "NRFLite.h"
const static uint8_t RADIO_ID = 0; // Our radio's id. The transmitter will send to this id.
const static uint8_t PIN_RADIO_CE = 9;
const static uint8_t PIN_RADIO_CSN = 10;
struct RadioPacket // Any packet up to 32 bytes can be sent.
{
uint8_t FromRadioId;
uint32_t OnTimeMillis;
uint32_t FailedTxCount;
};
NRFLite _radio;
RadioPacket _radioData;
void setup()
{
Serial.begin(115200);
// By default, 'init' configures the radio to use a 2MBPS bitrate on channel 100 (channels 0-125 are valid).
// Both the RX and TX radios must have the same bitrate and channel to communicate with each other.
// You can run the 'ChannelScanner' example to help select the best channel for your environment.
// You can assign a different bitrate and channel as shown below.
// _radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN, NRFLite::BITRATE2MBPS, 100) // THE DEFAULT
// _radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN, NRFLite::BITRATE1MBPS, 75)
// _radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN, NRFLite::BITRATE250KBPS, 0)
if (!_radio.init(RADIO_ID, PIN_RADIO_CE, PIN_RADIO_CSN))
{
Serial.println("Cannot communicate with radio");
while (1); // Wait here forever.
}
}
void loop()
{
while (_radio.hasData())
{
_radio.readData(&_radioData); // Note how '&' must be placed in front of the variable name.
String msg = "Radio ";
msg += _radioData.FromRadioId;
msg += ", ";
msg += _radioData.OnTimeMillis;
msg += " ms, ";
msg += _radioData.FailedTxCount;
msg += " Failed TX";
Serial.println(msg);
}
}