import virtGPIO as GPIO from lib_nrf24 import NRF24 import time pipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]] # Comment re multiple SPIDEV devices: # Official spidev documentation is sketchy. Implementation in virtGPIO allows multiple SpiDev() objects. # This may not work on RPi? Probably RPi uses alternating open() / xfer2() /close() within one SpiDev() object??? # On virtGPIO each of multiple SpiDev() stores its own mode and cePin. Multiple RF24 used here becomes easy. # This issue affects only using MULTIPLE Spi devices. ################################################################## # SET UP RADIO1 - PTX radio1 = NRF24(GPIO, GPIO.SpiDev()) radio1.begin(9) # SPI-CE=RF24-CSN=pin9, no RF24-CE pin time.sleep(1) radio1.setRetries(15, 15) radio1.setPayloadSize(32) radio1.setChannel(0x62) radio1.setDataRate(NRF24.BR_2MBPS) radio1.setPALevel(NRF24.PA_MIN) radio1.setAutoAck(True) radio1.enableDynamicPayloads() radio1.enableAckPayload() radio1.openWritingPipe(pipes[1]) radio1.openReadingPipe(1, pipes[0]) if not radio1.isPVariant():
#!/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:
# That sends all SPI serial output (MOSI) back into the input (MISO) # (We will just pretend we have real SPI devices connected to our bus.) import time import virtGPIO as GPIO print "Read comments in source file" GPIO.setActivityLed(0) # optional # The SpiDev() will fail if all 4 needed pins are not free (11, 12, 13, plus CE pin) # Pin13 is the default activityLed. Pin13 is also the SPI clock pin. # However as "true" owner of pin13, SPI will knock off the activityLed if that is the only problem. # See example-activityLed.py and example-diagnostic.py SPI = GPIO.SpiDev(10) # Initialise one SPI channel using pin 10 as its CE pin # "CE" is variously known as SS (slave select), CS (chip select) or CE (chip enable) # and also often written with a "*" or a "N" (eg SS* or CSN) denoting -ve logic: LOW active SPI2 = GPIO.SpiDev( 8) # So let's prepare for another SPI device using pin 8 as CE while True: print "SPI xfer on CE=10", SPI.xfer2( [55, 6, 6, 6, 6, 6, 6, 6, 6, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0, 0, 8]) print "SPI xfer on CE=8", SPI2.xfer2([74]) time.sleep(8) # So? Expect to simply see those (byte) number lists as above returned from the arduino.