From 008059386f2529166a96dfc354b776e61fe5bd2b Mon Sep 17 00:00:00 2001 From: BLavery Date: Fri, 28 Nov 2014 15:01:46 +1000 Subject: [PATCH] Added rpi-rcv --- example-nrf24-recv-rpi.py | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 example-nrf24-recv-rpi.py diff --git a/example-nrf24-recv-rpi.py b/example-nrf24-recv-rpi.py new file mode 100644 index 0000000..70233a1 --- /dev/null +++ b/example-nrf24-recv-rpi.py @@ -0,0 +1,58 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Example program to receive packets from the radio link +# + +import RPi.GPIO as GPIO +GPIO.setmode(GPIO.BCM) +from lib_nrf24 import NRF24 +import time +import spidev + + + +pipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]] + +radio2 = NRF24(GPIO, spidev.SpiDev()) +radio2.begin(0, 17) + +radio2.setRetries(15,15) + +radio2.setPayloadSize(32) +radio2.setChannel(0x60) +radio2.setDataRate(NRF24.BR_2MBPS) +radio2.setPALevel(NRF24.PA_MIN) + +radio2.setAutoAck(True) +radio2.enableDynamicPayloads() +radio2.enableAckPayload() + +radio2.openWritingPipe(pipes[0]) +radio2.openReadingPipe(1, pipes[1]) + +radio2.startListening() +radio2.stopListening() + +radio2.printDetails() + +radio2.startListening() + +c=1 +while True: + akpl_buf = [c,1, 2, 3,4,5,6,7,8,9,0,1, 2, 3,4,5,6,7,8] + pipe = [0] + while not radio2.available(pipe): + time.sleep(10000/1000000.0) + + recv_buffer = [] + radio2.read(recv_buffer, radio2.getDynamicPayloadSize()) + print ("Received:") , + print (recv_buffer) + c = c + 1 + if (c&1) == 0: + radio2.writeAckPayload(1, akpl_buf, len(akpl_buf)) + print ("Loaded payload reply:"), + print (akpl_buf) + else: + print ("(No return payload)")