-
-
Save sej7278/adb1348b986570d041f0 to your computer and use it in GitHub Desktop.
rf24network pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <iostream> | |
#include "../RF24/RF24.h" | |
#include "./RF24Network.h" | |
using namespace std; | |
RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ); | |
RF24Network network(radio); | |
const uint16_t this_node = 0; | |
const uint16_t other_node = 1; | |
const unsigned long interval = 2000; | |
unsigned long last_sent; | |
unsigned long packets_sent; | |
struct payload_t | |
{ | |
unsigned long ms; | |
unsigned long counter; | |
}; | |
int main(int argc, char** argv) | |
{ | |
radio.begin(); | |
delay(5); | |
network.begin(76, this_node); | |
radio.printDetails(); | |
while(1) | |
{ | |
cout << '1' << endl; | |
network.update(); | |
while (network.available()) | |
{ | |
cout << '2' << endl; | |
RF24NetworkHeader header; | |
payload_t payload; | |
network.read(header,&payload,sizeof(payload)); | |
cout << ':' << payload.counter << ',' << payload.ms << endl; | |
} | |
sleep(2); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <RF24Network.h> | |
#include <RF24.h> | |
RF24 radio(9,10); | |
RF24Network network(radio); | |
const uint16_t this_node = 1; | |
const uint16_t other_node = 0; | |
const unsigned long interval = 2000; | |
unsigned long last_sent; | |
unsigned long packets_sent; | |
struct payload_t { | |
unsigned long ms; | |
unsigned long counter; | |
}; | |
void setup(void) | |
{ | |
SPI.begin(); | |
radio.begin(); | |
network.begin(76, this_node); | |
} | |
void loop() | |
{ | |
network.update(); | |
unsigned long now = millis(); | |
if (now - last_sent >= interval ) | |
{ | |
last_sent = now; | |
payload_t payload = { millis(), packets_sent++ }; | |
RF24NetworkHeader header(other_node); | |
network.write(header,&payload,sizeof(payload)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
================ SPI Configuration ================ | |
CSN Pin = CE0 (PI Hardware Driven) | |
CE Pin = Custom GPIO22 | |
Clock Speed = 8 Mhz | |
================ NRF Configuration ================ | |
STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0 | |
RX_ADDR_P0-1 = 0xf0f0f0f03c 0xf0f0f0f05a | |
RX_ADDR_P2-5 = 0x69 0x96 0xa5 0xc3 | |
TX_ADDR = 0xe7e7e7e7e7 | |
RX_PW_P0-6 = 0x20 0x20 0x20 0x20 0x20 0x20 | |
EN_AA = 0x3f | |
EN_RXADDR = 0x3f | |
RF_CH = 0x4c | |
RF_SETUP = 0x07 | |
CONFIG = 0x0f | |
DYNPD/FEATURE = 0x3f 0x04 | |
Data Rate = 1MBPS | |
Model = nRF24L01+ | |
CRC Length = 16 bits | |
PA Power = PA_MAX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment