From c2f8ae7a6b14eec06b86f9119214ec1a8e196dc9 Mon Sep 17 00:00:00 2001
From: Catamine <kirsa@riseup.net>
Date: Sun, 31 Jul 2022 10:31:36 -0400
Subject: [PATCH] Added LoRa

---
 examples/lora_example.py  | 15 +++++++++++++++
 examples/lora_settings.py | 37 +++++++++++++++++++++++++++++++++++++
 libraries/sx127x.py       |  2 +-
 3 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 examples/lora_example.py
 create mode 100644 examples/lora_settings.py

diff --git a/examples/lora_example.py b/examples/lora_example.py
new file mode 100644
index 0000000..a35a5d9
--- /dev/null
+++ b/examples/lora_example.py
@@ -0,0 +1,15 @@
+import sys
+sys.path.insert(0, 'libraries')
+from libraries.sx127x import SX127x
+import machine
+from time import sleep
+import sx127x
+from lora_settings import lora1
+
+counter = 0
+while True:
+    payload = 'Hello ({0})'.format(counter)
+    print('TX: {}'.format(payload))
+    lora1.println(payload)
+    counter += 1
+    sleep(5)
diff --git a/examples/lora_settings.py b/examples/lora_settings.py
new file mode 100644
index 0000000..399e5a2
--- /dev/null
+++ b/examples/lora_settings.py
@@ -0,0 +1,37 @@
+from machine import Pin, SPI
+from sx127x import SX127x
+
+
+lora_default = {
+    'frequency': 418500000,
+    'frequency_offset':0,
+    'tx_power_level': 14,
+    'signal_bandwidth': 125e3,
+    'spreading_factor': 9,
+    'coding_rate': 5,
+    'preamble_length': 8,
+    'implicitHeader': False,
+    'sync_word': 0x33,
+    'enable_CRC': True,
+    'invert_IQ': False,
+    'debug': False,
+}
+
+lora_pins = {
+    'dio_0':26,
+    'cs':18,
+    'reset':23,
+    '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),
+)
+
+lora1 = SX127x(lora_spi, pins=lora_pins, parameters=lora_default)
\ No newline at end of file
diff --git a/libraries/sx127x.py b/libraries/sx127x.py
index 8e71756..221dfcd 100644
--- a/libraries/sx127x.py
+++ b/libraries/sx127x.py
@@ -98,7 +98,7 @@ class SX127x:
         self.pins = pins
         self.parameters = parameters
 
-        self.pin_ss = Pin(self.pins["ss"], Pin.OUT)
+        self.pin_ss = Pin(self.pins["cs"], Pin.OUT)
 
         self.lock = False
         self.implicit_header_mode = None
-- 
GitLab