Skip to content

Commit 94abe84

Browse files
committed
make IRQ example work on Linux
1 parent 8737238 commit 94abe84

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ to the MCU via a digital input pin during the interrupt example.
172172
SCK, SCK, "GPIO11 (SCK)"
173173
MOSI, MOSI, "GPIO10 (MOSI)"
174174
MISO, MISO, "GPIO9 (MISO)"
175-
IRQ, D12, GPIO12
175+
IRQ, D12, GPIO24
176176

177177
.. tip::
178178
User reports and personal experiences have improved results if there is a capacitor of

examples/nrf24l01_interrupt_test.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,35 @@
77

88
import time
99
import board
10-
import digitalio
10+
from digitalio import DigitalInOut
1111

1212
# if running this on a ATSAMD21 M0 based board
1313
# from circuitpython_nrf24l01.rf24_lite import RF24
1414
from circuitpython_nrf24l01.rf24 import RF24
1515

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)
2226

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
2639

2740
# we'll be using the dynamic payload size feature (enabled by default)
2841
# initialize the nRF24L01 on the spi bus object
@@ -59,7 +72,7 @@ def _ping_and_prompt():
5972
nrf.ce_pin = 1 # tell the nRF24L01 to prepare sending a single packet
6073
time.sleep(0.00001) # mandatory 10 microsecond pulse starts transmission
6174
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
6376
pass
6477
print("IRQ pin went active LOW.")
6578
nrf.update() # update irq_d? status flags

0 commit comments

Comments
 (0)