Skip to content

Commit b300772

Browse files
committed
blink LED to show whether a packet has been received
1 parent c22fc0d commit b300772

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

examples/rfm9x_simpletest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
# CS = digitalio.DigitalInOut(board.RFM9X_CS)
2020
# RESET = digitalio.DigitalInOut(board.RFM9X_RST)
2121

22+
# Define the onboard LED
23+
LED = digitalio.DigitalInOut(board.D13)
24+
LED.direction = digitalio.Direction.OUTPUT
25+
2226
# Initialize SPI bus.
2327
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
2428

@@ -32,6 +36,9 @@
3236
# high power radios like the RFM95 can go up to 23 dB:
3337
rfm9x.tx_power = 23
3438

39+
# Packet counter, incremented per tx
40+
packetNum = 0
41+
3542
# Send a packet. Note you can only send a packet up to 252 bytes in length.
3643
# This is a limitation of the radio packet size, so if you need to send larger
3744
# amounts of data you will need to break it into smaller send calls. Each send
@@ -44,15 +51,19 @@
4451
# This means you should only use this for low bandwidth scenarios, like sending
4552
# and receiving a single message at a time.
4653
print('Waiting for packets...')
54+
4755
while True:
56+
4857
packet = rfm9x.receive()
4958
# Optionally change the receive timeout from its default of 0.5 seconds:
5059
#packet = rfm9x.receive(timeout=5.0)
5160
# If no packet was received during the timeout then None is returned.
5261
if packet is None:
62+
LED.value = False
5363
print('Received nothing! Listening again...')
5464
else:
5565
# Received a packet!
66+
LED.value = True
5667
# Print out the raw bytes of the packet:
5768
print('Received (raw bytes): {0}'.format(packet))
5869
# And decode to ASCII text and print it too. Note that you always

0 commit comments

Comments
 (0)