Reputation: 5
I have 2 LoRa-02s set up on 2 different computers, and they are both on 433 MHz and it seems like one of them isn't working and I am quite certain it's the receiver.
Transmitter code:
import machine
import utime
import time
import _thread
import ustruct
import sys
import uLoRa as lora
cspin = machine.Pin(5,machine.Pin.OUT)
dio0 = machine.Pin(6,machine.Pin.IN)
rst = machine.Pin(7,machine.Pin.OUT)
spi = machine.SPI(0,
baudrate=2000000,
polarity=1,
phase=1,
bits=8,
firstbit=machine.SPI.MSB,
sck=machine.Pin(2),
mosi=machine.Pin(3),
miso=machine.Pin(4))
led = machine.Pin(25,machine.Pin.OUT)
lora_init = lora.begin(spi,cspin,rst,dio0,433)
if lora_init:
print("LoRa OK")
else:
print("LoRa Failed!!")
while True:
if lora_init:
lora.beginPacket()
data = "Hello!!"
enc_data = data.encode()
packet = bytearray(enc_data)
es = lora.dataPacket(packet)
lora.endPacket()
print("Packet Sent")
led.value(1)
time.sleep(0.25)
led.value(0)
time.sleep(10)
Receiver:
import machine
import utime
import time
import _thread
import ustruct
import sys
import uLoRa as lora
cspin = machine.Pin(5,machine.Pin.OUT)
dio0 = machine.Pin(6,machine.Pin.IN)
rst = machine.Pin(7,machine.Pin.OUT)
#rst = None # uncomment if you are not using reset pin
spi = machine.SPI(0,
baudrate=1000000,
polarity=1,
phase=1,
bits=8,
firstbit=machine.SPI.MSB,
sck=machine.Pin(2),
mosi=machine.Pin(3),
miso=machine.Pin(4))
cspin.value(1)
lora_init = lora.begin(spi,cspin,rst,dio0,433)
if lora_init:
print("LoRa OK")
else:
print("LoRa Failed!!")
while True:
if lora_init:
packet_size = lora.parsePacket()
if packet_size > 0:
print("Received Packet")
while lora.available() > 0:
print(chr(lora.read()))
print(" with RSSI ")
print(lora.packetRssi())
#time.sleep(1)
It is all connected as follows:
VCC: 3.3V
GND: GND
SCK: GPIO2
MISO: GPIO4
MOSI: GPIO3
NSS: GPIO5
RST: GPIO7
DIO0: GPIO6
Thanks in advance!
I have tried putting the baudrate
the same, and still did not work.
Upvotes: 0
Views: 138