d5ec935a66823fbfdfdd0aff42b881a96d90ed4c
Board-dat/DVA/DVA1007-DAT/DVA1007-DAT.md
| ... | ... | @@ -11,6 +11,12 @@ |
| 11 | 11 | |
| 12 | 12 | - 433MHZ version [[DVA1007-DAT]] - 915Mhz version [[DVA1008-DAT]] |
| 13 | 13 | |
| 14 | +- [[lora-SDK-dat]] |
|
| 15 | + |
|
| 16 | + |
|
| 17 | + |
|
| 18 | + |
|
| 19 | + |
|
| 14 | 20 | |
| 15 | 21 | ### Board Map |
| 16 | 22 | |
| ... | ... | @@ -44,7 +50,7 @@ Pin Definitions |
| 44 | 50 | - GND (CTS) |
| 45 | 51 | - -- (GND) |
| 46 | 52 | |
| 47 | -## Functions |
|
| 53 | +## Functions and tech |
|
| 48 | 54 | |
| 49 | 55 | - [[memory-dat]] - [[low-power-dat]] - [[lora-dat]] |
| 50 | 56 | |
| ... | ... | @@ -89,6 +95,8 @@ Pins table |
| 89 | 95 | - arduino library **radiohead** - [[arduino-lib-dat]] |
| 90 | 96 | - [[spi-flash-dat]] - user lowpower lab flash arduino library |
| 91 | 97 | |
| 98 | + |
|
| 99 | + |
|
| 92 | 100 | bootloader - arduino pro mini 3.3V/8M == [[arduino-dat]] |
| 93 | 101 | |
| 94 | 102 |
Board-dat/DVA/DVA1008-dat/DVA1008-dat.md
| ... | ... | @@ -10,4 +10,7 @@ |
| 10 | 10 | |
| 11 | 11 | ## ref |
| 12 | 12 | |
| 13 | -- |
|
| ... | ... | \ No newline at end of file |
| 0 | +- [[lora-dat]] |
|
| 1 | + |
|
| 2 | + |
|
| 3 | + |
Network-dat/RF-dat/LORA-DAT/Lora-SDK-dat/Lora-SDK-dat.md
| ... | ... | @@ -38,8 +38,38 @@ Path: The UserConfig.c file in LR_driver is a common file generated when adaptin |
| 38 | 38 | |
| 39 | 39 | ## arduino library |
| 40 | 40 | |
| 41 | + |
|
| 42 | +LoRaduplex output |
|
| 43 | + |
|
| 44 | + error: message length does not match length |
|
| 45 | + Sending HeLoRa World! |
|
| 46 | + Sending HeLoRa World! |
|
| 47 | + Sending HeLoRa World! |
|
| 48 | + error: message length does not match length |
|
| 49 | + Sending HeLoRa World! |
|
| 50 | + Sending HeLoRa World! |
|
| 51 | + |
|
| 52 | + |
|
| 41 | 53 | ### sandeepmistry/arduino-LoRa |
| 42 | 54 | |
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | +reference setup |
|
| 59 | + |
|
| 60 | + const long frequency = 915E6; // LoRa Frequency |
|
| 61 | + |
|
| 62 | + const int csPin = 10; // LoRa radio chip select |
|
| 63 | + const int resetPin = 9; // LoRa radio reset |
|
| 64 | + const int irqPin = 2; // change for your board; must be a hardware interrupt pin |
|
| 65 | + |
|
| 66 | + void setup() { |
|
| 67 | + Serial.begin(9600); // initialize serial |
|
| 68 | + while (!Serial); |
|
| 69 | + |
|
| 70 | + LoRa.setPins(csPin, resetPin, irqPin); |
|
| 71 | + |
|
| 72 | + |
|
| 43 | 73 | frequency in Hz (`433E6`, `868E6`, `915E6`) |
| 44 | 74 | |
| 45 | 75 |
Network-dat/RF-dat/LORA-DAT/lora-hdk-dat/lora-modules-dat/lora-modules-dat.md
| ... | ... | @@ -26,6 +26,9 @@ classic SX127x: |
| 26 | 26 | |
| 27 | 27 | - [[NWL1074-dat]] == hole antenna CONN |
| 28 | 28 | |
| 29 | +- [[serial-dat]] output = [[NWL1079-dat]] - [[NWL1081-dat]] |
|
| 30 | + |
|
| 31 | + |
|
| 29 | 32 | |
| 30 | 33 | ## compare |
| 31 | 34 |
Tech-dat/Interface-dat/SPI-dat/spi-cmd-1.py
| ... | ... | @@ -1,10 +1,22 @@ |
| 1 | 1 | #!/usr/bin/env python3 |
| 2 | 2 | """ |
| 3 | -SX1278 SPI Demo - Raspberry Pi 3 |
|
| 3 | +SX1278 LoRa SPI Demo for Raspberry Pi |
|
| 4 | + |
|
| 5 | +This script demonstrates basic SPI communication with the SX1278 LoRa module. |
|
| 6 | +It performs the following: |
|
| 7 | +- Initializes GPIO and SPI interfaces. |
|
| 8 | +- Resets and verifies the SX1278 module. |
|
| 9 | +- Configures the module for LoRa mode at 433 MHz frequency. |
|
| 10 | +- Sets the module to RX continuous mode to receive LoRa packets. |
|
| 11 | +- Handles DIO0 interrupts for RX done events, reading and printing received data. |
|
| 12 | + |
|
| 4 | 13 | Pin mapping: |
| 5 | 14 | LORA_CS = GPIO8 |
| 6 | 15 | LORA_INT = GPIO4 (DIO0) |
| 7 | 16 | LORA_RESET = GPIO17 |
| 17 | + |
|
| 18 | +Requirements: spidev, RPi.GPIO |
|
| 19 | +Run with sudo for GPIO interrupts. |
|
| 8 | 20 | """ |
| 9 | 21 | |
| 10 | 22 | import spidev |
| ... | ... | @@ -33,6 +45,13 @@ REG_OP_MODE = 0x01 |
| 33 | 45 | REG_VERSION = 0x42 |
| 34 | 46 | REG_IRQ_FLAGS = 0x12 |
| 35 | 47 | REG_DIO_MAPPING1 = 0x40 |
| 48 | +REG_FRF_MSB = 0x06 |
|
| 49 | +REG_FRF_MID = 0x07 |
|
| 50 | +REG_FRF_LSB = 0x08 |
|
| 51 | +REG_FIFO = 0x00 |
|
| 52 | +REG_FIFO_ADDR_PTR = 0x0D |
|
| 53 | +REG_RX_NB_BYTES = 0x13 |
|
| 54 | +REG_FIFO_RX_CURRENT_ADDR = 0x10 |
|
| 36 | 55 | |
| 37 | 56 | # ========================= |
| 38 | 57 | # GPIO SETUP |
| ... | ... | @@ -59,20 +78,24 @@ spi.no_cs = True # IMPORTANT: software CS |
| 59 | 78 | def cs_low(): |
| 60 | 79 | GPIO.output(LORA_CS, GPIO.LOW) |
| 61 | 80 | |
| 81 | + |
|
| 62 | 82 | def cs_high(): |
| 63 | 83 | GPIO.output(LORA_CS, GPIO.HIGH) |
| 64 | 84 | |
| 85 | + |
|
| 65 | 86 | def read_reg(addr): |
| 66 | 87 | cs_low() |
| 67 | 88 | resp = spi.xfer2([addr & 0x7F, 0x00]) |
| 68 | 89 | cs_high() |
| 69 | 90 | return resp[1] |
| 70 | 91 | |
| 92 | + |
|
| 71 | 93 | def write_reg(addr, val): |
| 72 | 94 | cs_low() |
| 73 | 95 | spi.xfer2([addr | 0x80, val]) |
| 74 | 96 | cs_high() |
| 75 | 97 | |
| 98 | + |
|
| 76 | 99 | # ========================= |
| 77 | 100 | # SX1278 CONTROL |
| 78 | 101 | # ========================= |
| ... | ... | @@ -82,6 +105,7 @@ def lora_reset(): |
| 82 | 105 | GPIO.output(LORA_RESET, GPIO.HIGH) |
| 83 | 106 | time.sleep(0.1) |
| 84 | 107 | |
| 108 | + |
|
| 85 | 109 | def lora_set_lora_mode(): |
| 86 | 110 | # Sleep + LoRa |
| 87 | 111 | write_reg(REG_OP_MODE, 0x80) |
| ... | ... | @@ -90,29 +114,62 @@ def lora_set_lora_mode(): |
| 90 | 114 | write_reg(REG_OP_MODE, 0x81) |
| 91 | 115 | time.sleep(0.01) |
| 92 | 116 | |
| 117 | + |
|
| 93 | 118 | def lora_clear_irq(): |
| 94 | 119 | write_reg(REG_IRQ_FLAGS, 0xFF) |
| 95 | 120 | |
| 121 | + |
|
| 122 | +def lora_set_frequency(freq_hz): |
|
| 123 | + frf = int((freq_hz * (2**19)) / 32_000_000) |
|
| 124 | + msb = (frf >> 16) & 0xFF |
|
| 125 | + mid = (frf >> 8) & 0xFF |
|
| 126 | + lsb = frf & 0xFF |
|
| 127 | + write_reg(REG_FRF_MSB, msb) |
|
| 128 | + write_reg(REG_FRF_MID, mid) |
|
| 129 | + write_reg(REG_FRF_LSB, lsb) |
|
| 130 | + |
|
| 131 | + |
|
| 132 | +def lora_set_rx_mode(): |
|
| 133 | + write_reg(REG_OP_MODE, 0x85) # RXCONTINUOUS + LoRa |
|
| 134 | + |
|
| 135 | + |
|
| 96 | 136 | # ========================= |
| 97 | 137 | # INTERRUPT HANDLER |
| 98 | 138 | # ========================= |
| 99 | 139 | def dio0_handler(channel): |
| 100 | 140 | irq = read_reg(REG_IRQ_FLAGS) |
| 101 | 141 | print(f"[DIO0] IRQ FLAGS = 0x{irq:02X}") |
| 142 | + |
|
| 143 | + if irq & 0x40: # RX_DONE |
|
| 144 | + # Set FIFO pointer to current RX addr |
|
| 145 | + current_addr = read_reg(REG_FIFO_RX_CURRENT_ADDR) |
|
| 146 | + write_reg(REG_FIFO_ADDR_PTR, current_addr) |
|
| 147 | + |
|
| 148 | + # Read number of bytes |
|
| 149 | + nb_bytes = read_reg(REG_RX_NB_BYTES) |
|
| 150 | + |
|
| 151 | + # Read payload |
|
| 152 | + data = [] |
|
| 153 | + for _ in range(nb_bytes): |
|
| 154 | + data.append(read_reg(REG_FIFO)) |
|
| 155 | + |
|
| 156 | + print(f"Received {nb_bytes} bytes: {bytes(data)}") |
|
| 157 | + |
|
| 102 | 158 | lora_clear_irq() |
| 103 | 159 | |
| 160 | + |
|
| 104 | 161 | try: |
| 105 | 162 | GPIO.add_event_detect( |
| 106 | 163 | LORA_INT, |
| 107 | 164 | GPIO.RISING, |
| 108 | - callback=dio0_handler, |
|
| 109 | - bouncetime=10 |
|
| 165 | + callback=dio0_handler |
|
| 110 | 166 | ) |
| 111 | 167 | print("Interrupt detection enabled on GPIO4") |
| 112 | 168 | except RuntimeError as e: |
| 113 | 169 | print(f"Warning: Failed to add edge detection: {e}") |
| 114 | 170 | print("Note: GPIO interrupts may require running the script with sudo") |
| 115 | 171 | |
| 172 | + |
|
| 116 | 173 | # ========================= |
| 117 | 174 | # MAIN |
| 118 | 175 | # ========================= |
| ... | ... | @@ -133,11 +190,19 @@ def main(): |
| 133 | 190 | lora_set_lora_mode() |
| 134 | 191 | lora_clear_irq() |
| 135 | 192 | |
| 136 | - print("LoRa mode enabled") |
|
| 137 | - print("Waiting for DIO0 interrupt (Ctrl+C to exit)") |
|
| 193 | + lora_set_frequency(433000000) |
|
| 194 | + lora_set_rx_mode() |
|
| 138 | 195 | |
| 196 | + print("LoRa mode enabled, RX at 433 MHz") |
|
| 197 | + print("Waiting for packets (DIO0 interrupt or polling) (Ctrl+C to exit)") |
|
| 198 | + |
|
| 199 | + # Poll IRQ flags in case GPIO edge detection failed |
|
| 139 | 200 | while True: |
| 140 | - time.sleep(1) |
|
| 201 | + irq = read_reg(REG_IRQ_FLAGS) |
|
| 202 | + if irq & 0x40: # RX_DONE |
|
| 203 | + dio0_handler(LORA_INT) |
|
| 204 | + time.sleep(0.1) |
|
| 205 | + |
|
| 141 | 206 | |
| 142 | 207 | # ========================= |
| 143 | 208 | # CLEANUP |