Added lora lib and script

This commit is contained in:
2025-12-25 02:57:38 +01:00
parent ec215fe4b2
commit fc30830159
2 changed files with 509 additions and 39 deletions

View File

@@ -1,42 +1,13 @@
from machine import Pin, SPI, ADC
import time
from machine import Pin, SPI
from sx127x import SX127x
# ADC setup
light_adc = ADC(Pin(1))
light_adc.atten(ADC.ATTN_11DB)
light_adc.width(ADC.WIDTH_12BIT)
# SPI bus
spi = SPI(1, baudrate=1000000, polarity=0, phase=0,
sck=Pin(18), mosi=Pin(23), miso=Pin(19))
# SPI for LoRa
spi = SPI(
1,
baudrate=5000000,
polarity=0,
phase=0,
sck=Pin(12),
mosi=Pin(11),
miso=Pin(13)
)
lora = SX127x(
spi=spi,
pins={
'cs': Pin(10),
'reset': Pin(14),
'dio0': Pin(15)
},
parameters={
'frequency': 868E6, # change if needed
'tx_power_level': 14
}
)
while True:
raw = light_adc.read()
payload = "Light: {}".format(raw)
print(payload)
lora.println(payload)
time.sleep(10)
# LoRa module
lora = SX127x(spi, cs=Pin(14), reset=Pin(26), irq=Pin(33),
freq=868E6, # or 915E6 depending on region
sf=7, # spreading factor
bw=125E3, # bandwidth
cr=5) # coding rate