Skip to content

Commit ad2f4eb

Browse files
committed
tested LoRa modules up to 500metres
fixes fossasia#62
1 parent 7df2c3f commit ad2f4eb

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

PSL/SENSORS/Sx1276.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,39 @@ def getRaw(self):
294294
return val
295295

296296

297+
298+
if __name__ == "__main__":
299+
'''
300+
Example code to test LoRa modules.
301+
Set mode = 0 to enable receiver , or mode = 1 to enable a periodic transmitter
302+
303+
Frequency = 434MHz #Use the frequency specified by the module being used
304+
transmission is at 17db
305+
BW = 125KHz
306+
Spreading Factor (SF) = 12
307+
Coding rate(CR) = 4/5 #The numerator is always 4, and the argument passed to the init function is the denominator
308+
'''
309+
RX = 0; TX=1
310+
mode = RX
311+
from PSL import sciencelab
312+
I= sciencelab.connect()
313+
lora = SX1276(I.SPI,434e6,boost=True,power=17,BW=125e3,SF=12,CR=5)
314+
lora.crc() #Enable CRC
315+
cntr=0 #Incrementing counter for TX mode
316+
while 1:
317+
time.sleep(0.01)
318+
if mode==TX:
319+
lora.beginPacket() #Enable writing mode
320+
lora.write([ord(a) for a in ":"]+[cntr]) #write some bytes
321+
print (time.ctime(),cntr, hex(lora.SPIRead(lora.REG_OP_MODE)[0]))
322+
lora.endPacket() #Switch to transmit mode, and send the data
323+
cntr+=1
324+
if cntr==255:cntr=0
325+
else:
326+
packet_size = lora.parsePacket()
327+
if packet_size: #If some data was received
328+
print ('got packet')
329+
print 'data',lora.readAll() #Print the data
330+
print ('Rssi',lora.packetRssi(),lora.packetSnr()) #Print signal strength and signal to noise ratio
331+
332+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy