-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdaa108
commit 84f8dff
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python | ||
|
||
# | ||
# Simplest possible example of using RF24Network, | ||
# | ||
# RECEIVER NODE | ||
# Listens for messages from the transmitter and prints them out. | ||
# | ||
|
||
import time | ||
from struct import * | ||
from RF24 import * | ||
from RF24Network import * | ||
|
||
# CE Pin, CSN Pin, SPI Speed | ||
|
||
# Setup for GPIO 22 CE and GPIO 25 CSN with SPI Speed @ 1Mhz | ||
#radio = radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_18, BCM2835_SPI_SPEED_1MHZ) | ||
|
||
# Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz | ||
#radio = RF24(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ) | ||
|
||
# Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz | ||
#radio = RF24(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ) | ||
|
||
# Setup for GPIO 22 CE and CE0 CSN for RPi B+ with SPI Speed @ 8Mhz | ||
radio = RF24(RPI_BPLUS_GPIO_J8_22, RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ) | ||
|
||
network = RF24Network(radio) | ||
|
||
# Address of our node in Octal format (01,021, etc) | ||
this_node = 0o0 | ||
|
||
# Address of the other node | ||
other_node = 0o1 | ||
|
||
interval = 2000 #ms - How often to send 'hello world' to the other unit | ||
|
||
millis = lambda: int(round(time.time() * 1000)) | ||
|
||
radio.begin() | ||
time.sleep(0.1) | ||
network.begin(90, this_node) # channel 90 | ||
radio.printDetails() | ||
packets_sent = 0 | ||
last_sent = 0 | ||
|
||
while 1: | ||
network.update() | ||
while network.available(): | ||
header, payload = network.read(12) | ||
ms, number = unpack('<qi', payload) | ||
print('Received payload # ', number, ' at ', ms, ' from ', oct(header.from_node)) | ||
time.sleep(1) | ||
|