MCPcopy Create free account
hub / github.com/antirez/freakwan / SX1276Example

Class SX1276Example

example.py:10–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8from machine import Pin, SoftI2C
9
10class SX1276Example:
11 def __init__(self):
12 LYLIGO_216_pinconfig = {
13 'miso': 19,
14 'mosi': 27,
15 'clock': 5,
16 'chipselect': 18,
17 'reset': 23,
18 'dio0': 26
19 }
20
21 # Init display
22 i2c = SoftI2C(sda=Pin(21), scl=Pin(22))
23 self.display = ssd1306.SSD1306_I2C(128, 64, i2c)
24 self.display.poweron()
25 self.display.text('Receiving...', 0, 0, 1)
26 self.display.show()
27
28 # Init LoRa chip
29 self.lora = sx1276.SX1276(LYLIGO_216_pinconfig,self.receive_callback)
30 self.lora.begin()
31 self.lora.configure(869500000,500000,8,12)
32
33 # Start receiving. This will just install the IRQ
34 # handler, without blocking the program.
35 self.lora.receive()
36
37 def receive_callback(self,lora_instance,packet,RSSI):
38 self.display.fill(0)
39 self.display.text(packet, 0, 0, 1)
40 self.display.text(str(RSSI), 0, 15, 1)
41 self.display.show()
42
43 def run(self):
44 # Other than receiving, every 5 seconds send a packet.
45 while True:
46 payload = "Test "+str(urandom.randint(0,1000000))
47 self.display.fill(0)
48 self.display.text(payload, 0, 0, 1)
49 self.display.show()
50 self.lora.send(payload)
51 time.sleep(5)
52
53example = SX1276Example()
54example.run()

Callers 1

example.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected