Advertisement
pleasedontcode

**LoRa Setup** rev_16

Nov 29th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **LoRa Setup**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-11-29 23:08:15
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* configure a lora gateway */
  21. /****** SYSTEM REQUIREMENT 2 *****/
  22.     /* send periodically a message to receiver. */
  23. /****** END SYSTEM REQUIREMENTS *****/
  24.  
  25. /* START CODE */
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <SPI.h>
  29. #include <LoRa.h>   //https://github.com/sandeepmistry/arduino-LoRa
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs();
  35. void sendLoRaMessage(const char* message);
  36.  
  37. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  38. const uint8_t module_SX127x_DIO0_PIN_D3     = 3;
  39.  
  40. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  41. const uint8_t module_SX127x_NRESET_PIN_D2       = 2;
  42.  
  43. /***** DEFINITION OF SPI PINS *****/
  44. const uint8_t module_SX127x_SPI_PIN_MOSI_D11        = 11;
  45. const uint8_t module_SX127x_SPI_PIN_MISO_D12        = 12;
  46. const uint8_t module_SX127x_SPI_PIN_SCLK_D13        = 13;
  47. const uint8_t module_SX127x_SPI_PIN_CS_D10      = 10;
  48.  
  49. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  50. /***** used to store raw data *****/
  51. bool    module_SX127x_NRESET_PIN_D2_rawData     = 0;
  52.  
  53. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  54. /***** used to store data after characteristic curve transformation *****/
  55. float   module_SX127x_NRESET_PIN_D2_phyData     = 0.0;
  56.  
  57. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  58.  
  59. // Instantiate LoRa object
  60. LoRaClass LoRa;
  61.  
  62. void setup(void)
  63. {
  64.     // put your setup code here, to run once:
  65.  
  66.     pinMode(module_SX127x_DIO0_PIN_D3,  INPUT);
  67.     pinMode(module_SX127x_NRESET_PIN_D2,     OUTPUT);
  68.     pinMode(module_SX127x_SPI_PIN_CS_D10,    OUTPUT);
  69.    
  70.     // start the SPI library:
  71.     SPI.begin();
  72.  
  73.     // Initialize LoRa
  74.     LoRa.setPins(module_SX127x_SPI_PIN_CS_D10, module_SX127x_NRESET_PIN_D2, module_SX127x_DIO0_PIN_D3);
  75.     if (!LoRa.begin(915E6)) { // Set frequency to 915 MHz
  76.         while (1); // if failed, do nothing
  77.     }
  78. }
  79.  
  80. void loop(void)
  81. {
  82.     // put your main code here, to run repeatedly:
  83.     updateOutputs(); // Refresh output data
  84.  
  85.     // Send a message every 5 seconds
  86.     sendLoRaMessage("Hello, LoRa!");
  87.     delay(5000);
  88. }
  89.  
  90. void updateOutputs()
  91. {
  92.     digitalWrite(module_SX127x_NRESET_PIN_D2, module_SX127x_NRESET_PIN_D2_rawData);
  93. }
  94.  
  95. void sendLoRaMessage(const char* message)
  96. {
  97.     LoRa.beginPacket();
  98.     LoRa.print(message);
  99.     LoRa.endPacket();
  100. }
  101.  
  102. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement