From 1c1569c2fc0719e93f84006cafaa2a4ef8ab72cf Mon Sep 17 00:00:00 2001 From: BLavery Date: Thu, 6 Nov 2014 08:46:20 +1000 Subject: [PATCH] rpi example added --- example-nrf24-send-rpi.py | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 example-nrf24-send-rpi.py diff --git a/example-nrf24-send-rpi.py b/example-nrf24-send-rpi.py new file mode 100644 index 0000000..50c6944 --- /dev/null +++ b/example-nrf24-send-rpi.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Example program to send packets to 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]] + +radio = NRF24(GPIO, spidev.SpiDev()) +radio.begin(0, 17) +time.sleep(1) +radio.setRetries(15,15) +radio.setPayloadSize(32) +radio.setChannel(0x60) + +radio.setDataRate(NRF24.BR_2MBPS) +radio.setPALevel(NRF24.PA_MIN) +radio.setAutoAck(True) +radio.enableDynamicPayloads() +radio.enableAckPayload() + + +radio.openWritingPipe(pipes[1]) +radio.openReadingPipe(1, pipes[0]) +radio.printDetails() + + +c=1 +while True: + buf = ['H', 'E', 'L', 'O',c] + c = (c + 1) & 255 + # send a packet to receiver + radio.write(buf) + print ("Sent:"), + print (buf) + # did it return with a payload? + if radio.isAckPayloadAvailable(): + pl_buffer=[] + radio.read(pl_buffer, radio.getDynamicPayloadSize()) + print ("Received back:"), + print (pl_buffer) + else: + print ("Received: Ack only, no payload") + time.sleep(10)