Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Continuously listen for LoRa messages and echo them back out (also prints
- # them to the terminal).
- from aiolora import LoRa
- from machine import Pin, SPI
- import uasyncio as asyncio
- # SPI pins
- SCK = 2
- MOSI = 3
- MISO = 4
- # This is the NSS pin on the SX1278
- CS = 5
- # IRQ pin = the DIO0 pin on the SX1278
- IRQ = 1
- # Setup SPI
- spi = SPI(
- 0,
- baudrate=10000000,
- sck=Pin(SCK, Pin.OUT, Pin.PULL_DOWN),
- mosi=Pin(MOSI, Pin.OUT, Pin.PULL_UP),
- miso=Pin(MISO, Pin.IN, Pin.PULL_UP),
- )
- spi.init()
- # Setup LoRa
- lora = LoRa(
- spi,
- cs=Pin(CS, Pin.OUT),
- irq=Pin(IRQ, Pin.IN),
- )
- async def main():
- while True:
- # Receive data
- data = await lora.recv()
- # Print to terminal
- print(data)
- # Echo data
- #await lora.send(data)
- # Setup asyncio loop and start task
- loop = asyncio.get_event_loop()
- loop.create_task(main())
- loop.run_forever()
Advertisement
Add Comment
Please, Sign In to add comment