chandrawi / LoRaRF-Python

Python library for basic transmitting and receiving data using LoRa and FSK modem
MIT License
29 stars 15 forks source link

Transmitter example on Dragino LoRa Hat issue #6

Closed victorfmin66 closed 1 year ago

victorfmin66 commented 1 year ago

Hello and thank you for the work you are doing maintaining this repository.

I have the Dragino LoRa Hat version 1.0 that is based on the SX1276/SX1278 transceiver and using SPI. Here is the link of the board: https://wiki1.dragino.com/index.php?title=Lora/GPS_HAT.

I have tried to use the library with the examples you provided and I'm having difficulties on the transmitter.py script. The execution of the code stops in the line #67 LoRa.wait() function. Due to the execution can't go further, the receiver (script on another pi with the same hat) is not able to receive the transmission. The script dont crash, the script executes `LoRa.wait()' function and stays infinitely, not able to continue with the execution.

My configuration of pins on the script are the following:

busId = 0; csId = 0
resetPin = 17; irqPin = -1; txenPin = -1; rxenPin = -1

This is currently my configuration of the LoRa Hat and the raspberry pi 3b+.

Dragino Lora Hat v 1.0 RPi 2B rPi3/rpi4
3.3 3.3 3.3
5V 5V 5V
GND GND GND
Lora DIOO GPIO7 GPIO4
GPS_RX GPIO15/TY GPIO14(UART TX)
GPS_TX GPIO16/RY GPIO15 (UART RX)
Lora RESET GPIO0 GPIO17
Lora NSS GPIO6 GPIO25
Lora MISO GPT013/MISO GPIO09 MISO
Lora MOSI GP1012/MOSI GPIO10 MOSI
Lora SCK GPIO14/SCLK GPIO11 SCLK

Do I need to set up any extra SPI pins in the code? I didn't see in the wiki any documentation to update any MISO or MOSI pins, isn't it?

Any advice on how to solve this problem?

Thank you,

Victor

chandrawi commented 1 year ago

According to pinout.xyz, there is no SPI on GPIO13, GPIO12, and GPIO14. The connection on this wiki meant for wiring pi connection but the library uses broadcom pin numbering. Unfortunately, the NSS pin on this HAT connected to GPIO25. In order to work with this library, the NSS pin must be connected to GPIO8 (CE0) or GPIO7 (CE1).

There is a hardware hack you can try. Try to connect GPIO25 and GPIO8 with solder or something, both pin are adjacent. Then you must set the connection to something like the following code.

busId = 0; csId = 0
resetPin = 17; irqPin = -1; txenPin = -1; rxenPin = -1

Also you may need to set the GPIO25 to input, so it will not interfere the connection. This is done by something like following code.

import RPi.GPIO
gpio = RPi.GPIO
gpio.setmode(RPi.GPIO.BCM)
gpio.input(25);
victorfmin66 commented 1 year ago

Apologies for the late response on the testing. The "hack" worked perfectly, thank you very much for the advice and with the extra code. I had to add a new line in the code to setup the pin 25 but that was my only addition. With this modifications in hardware and software the python example works perfectly.

This is a picture of the hardware hack: IMG_0048

And here is the code I modified from the previous comment.

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(25,GPIO.IN)
GPIO.input(25)

Feel free to use either the picture or the comments for future wiki releases.

I hope this help other developers to use this library.

Thanks!