forked from sergio303/micropython-sx127x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (52 loc) · 1.4 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from machine import Pin,SPI
from sx127x import SX127x
from examples import LoRaSender
from examples import LoRaReceiver
from examples import LoRaPing
from examples import LoRaReceiverCallback
lora_default = {
'frequency': 869525000,
'frequency_offset':0,
'tx_power_level': 14,
'signal_bandwidth': 125e3,
'spreading_factor': 9,
'coding_rate': 5,
'preamble_length': 8,
'implicitHeader': False,
'sync_word': 0x12,
'enable_CRC': True,
'invert_IQ': False,
'debug': False,
}
lora_pins = {
'dio_0':26,
'ss':18,
'reset':16,
'sck':5,
'miso':19,
'mosi':27,
}
lora_spi = SPI(
baudrate=10000000, polarity=0, phase=0,
bits=8, firstbit=SPI.MSB,
sck=Pin(lora_pins['sck'], Pin.OUT, Pin.PULL_DOWN),
mosi=Pin(lora_pins['mosi'], Pin.OUT, Pin.PULL_UP),
miso=Pin(lora_pins['miso'], Pin.IN, Pin.PULL_UP),
)
lora = SX127x(lora_spi, pins=lora_pins, parameters=lora_default)
# type = 'sender'
# type = 'receiver'
# type = 'ping_master'
# type = 'ping_slave'
type = 'receiver_callback'
if __name__ == '__main__':
if type == 'sender':
LoRaSender.send(lora)
if type == 'receiver':
LoRaReceiver.receive(lora)
if type == 'ping_master':
LoRaPing.ping(lora, master=True)
if type == 'ping_slave':
LoRaPing.ping(lora, master=False)
if type == 'receiver_callback':
LoRaReceiverCallback.receiveCallback(lora)