-
Notifications
You must be signed in to change notification settings - Fork 56
/
example-nrf24-send.py
51 lines (40 loc) · 1.08 KB
/
example-nrf24-send.py
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Example program to send packets to the radio link
#
import virtGPIO as GPIO
from lib_nrf24 import NRF24
import time
pipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]]
radio = NRF24(GPIO, GPIO.SpiDev())
radio.begin(10, 8) #Set spi-ce pin10, and rf24-CE pin 8
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)