Guest User

Untitled

a guest
Oct 1st, 2023
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. # Continuously listen for LoRa messages and echo them back out (also prints
  2. # them to the terminal).
  3.  
  4. from aiolora import LoRa
  5. from machine import Pin, SPI
  6. import uasyncio as asyncio
  7.  
  8. # SPI pins
  9. SCK = 2
  10. MOSI = 3
  11. MISO = 4
  12. # This is the NSS pin on the SX1278
  13. CS = 5
  14. # IRQ pin = the DIO0 pin on the SX1278
  15. IRQ = 1
  16.  
  17. # Setup SPI
  18. spi = SPI(
  19. 0,
  20. baudrate=10000000,
  21. sck=Pin(SCK, Pin.OUT, Pin.PULL_DOWN),
  22. mosi=Pin(MOSI, Pin.OUT, Pin.PULL_UP),
  23. miso=Pin(MISO, Pin.IN, Pin.PULL_UP),
  24. )
  25. spi.init()
  26.  
  27. # Setup LoRa
  28. lora = LoRa(
  29. spi,
  30. cs=Pin(CS, Pin.OUT),
  31. irq=Pin(IRQ, Pin.IN),
  32. )
  33.  
  34. async def main():
  35. while True:
  36. # Receive data
  37. data = await lora.recv()
  38. # Print to terminal
  39. print(data)
  40. # Echo data
  41. #await lora.send(data)
  42.  
  43. # Setup asyncio loop and start task
  44. loop = asyncio.get_event_loop()
  45. loop.create_task(main())
  46. loop.run_forever()
  47.  
Advertisement
Add Comment
Please, Sign In to add comment