|
7 | 7 |
|
8 | 8 | import time |
9 | 9 | import board |
10 | | -import digitalio |
| 10 | +from digitalio import DigitalInOut |
11 | 11 |
|
12 | 12 | # if running this on a ATSAMD21 M0 based board |
13 | 13 | # from circuitpython_nrf24l01.rf24_lite import RF24 |
14 | 14 | from circuitpython_nrf24l01.rf24 import RF24 |
15 | 15 |
|
16 | | -# select your digital input pin that's connected to the IRQ pin on the nRF4L01 |
17 | | -irq_pin = digitalio.DigitalInOut(board.D12) |
18 | | -irq_pin.switch_to_input() # make sure its an input object |
19 | | -# change these (digital output) pins accordingly |
20 | | -CE_PIN = digitalio.DigitalInOut(board.D4) |
21 | | -CSN_PIN = digitalio.DigitalInOut(board.D5) |
| 16 | +# invalid default values for scoping |
| 17 | +SPI_BUS, CSN_PIN, CE_PIN = (None, None, None) |
| 18 | + |
| 19 | +try: # on Linux |
| 20 | + import spidev |
| 21 | + |
| 22 | + SPI_BUS = spidev.SpiDev() # for a faster interface on linux |
| 23 | + CSN_PIN = 0 # use CE0 on default bus (even faster than using any pin) |
| 24 | + CE_PIN = DigitalInOut(board.D22) # using pin gpio22 (BCM numbering) |
| 25 | + IRQ_PIN = DigitalInOut(board.D24) # using gpio24 (BCM numbering) |
22 | 26 |
|
23 | | -# using board.SPI() automatically selects the MCU's |
24 | | -# available SPI pins, board.SCK, board.MOSI, board.MISO |
25 | | -SPI_BUS = board.SPI() # init spi bus object |
| 27 | +except ImportError: # on CircuitPython only |
| 28 | + # using board.SPI() automatically selects the MCU's |
| 29 | + # available SPI pins, board.SCK, board.MOSI, board.MISO |
| 30 | + SPI_BUS = board.SPI() # init spi bus object |
| 31 | + |
| 32 | + # change these (GPIO) pins accordingly |
| 33 | + CE_PIN = DigitalInOut(board.D4) |
| 34 | + CSN_PIN = DigitalInOut(board.D5) |
| 35 | + IRQ_PIN = DigitalInOut(board.D12) |
| 36 | + |
| 37 | +# select your digital input pin that's connected to the IRQ pin on the nRF4L01 |
| 38 | +IRQ_PIN.switch_to_input() # make sure its an input object |
26 | 39 |
|
27 | 40 | # we'll be using the dynamic payload size feature (enabled by default) |
28 | 41 | # initialize the nRF24L01 on the spi bus object |
@@ -59,7 +72,7 @@ def _ping_and_prompt(): |
59 | 72 | nrf.ce_pin = 1 # tell the nRF24L01 to prepare sending a single packet |
60 | 73 | time.sleep(0.00001) # mandatory 10 microsecond pulse starts transmission |
61 | 74 | nrf.ce_pin = 0 # end 10 us pulse; use only 1 buffer from TX FIFO |
62 | | - while irq_pin.value: # IRQ pin is active when LOW |
| 75 | + while IRQ_PIN.value: # IRQ pin is active when LOW |
63 | 76 | pass |
64 | 77 | print("IRQ pin went active LOW.") |
65 | 78 | nrf.update() # update irq_d? status flags |
|
0 commit comments