Skip to content

Commit 435a482

Browse files
authored
Merge pull request #15 from brentru/single-channel-example
adding example for single-channel sends
2 parents 68b7c66 + 3784258 commit 435a482

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import time
2+
import busio
3+
import digitalio
4+
import board
5+
from adafruit_tinylora.adafruit_tinylora import TTN, TinyLoRa
6+
7+
# Board LED
8+
led = digitalio.DigitalInOut(board.D13)
9+
led.direction = digitalio.Direction.OUTPUT
10+
11+
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
12+
13+
# RFM9x Breakout Pinouts
14+
cs = digitalio.DigitalInOut(board.D5)
15+
irq = digitalio.DigitalInOut(board.D6)
16+
17+
# Feather M0 RFM9x Pinouts
18+
# cs = digitalio.DigitalInOut(board.RFM9X_CS)
19+
# irq = digitalio.DigitalInOut(board.RFM9X_D0)
20+
21+
# TTN Device Address, 4 Bytes, MSB
22+
devaddr = bytearray([0x00, 0x00, 0x00, 0x00])
23+
24+
# TTN Network Key, 16 Bytes, MSB
25+
nwkey = bytearray([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
26+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
27+
28+
# TTN Application Key, 16 Bytess, MSB
29+
app = bytearray([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
31+
32+
ttn_config = TTN(devaddr, nwkey, app, country='US')
33+
34+
# Broadcasting on channel 0 in US Region - 903.9 MHz
35+
lora = TinyLoRa(spi, cs, irq, ttn_config, channel=0)
36+
37+
while True:
38+
data = bytearray(b"\x43\x57\x54\x46")
39+
print('Sending packet...')
40+
lora.send_data(data, len(data), lora.frame_counter)
41+
print('Packet sent!')
42+
led.value = True
43+
lora.frame_counter += 1
44+
time.sleep(1)
45+
led.value = False

0 commit comments

Comments
 (0)