xg590 / SX1276

MicroPython Library for SX1276 (A Long Range Radio Chip from Semtech)
Apache License 2.0
34 stars 8 forks source link

Declaring different parameters for multiple nodes #13

Closed SharathChandan closed 1 year ago

SharathChandan commented 1 year ago

https://github.com/xg590/SX1276/issues/8#issuecomment-1474805429

is there a way i could set two different spreading factor and bandwidth for two LoRa modules operating on same MCU? I mean when SF 8 500khz for one LoRa and SF 10 and BW 125khz for another. is it possible?

SharathChandan commented 1 year ago

https://github.com/xg590/SX1276/issues/8#issuecomment-1423975013 i am using an ESP32, please let me know about the above using your code since its similar to mine only the pinouts differ.

xg590 commented 1 year ago

I don't have LoRa devices at my sides so you can modify lora.py slightly for yourself so that the SX1276 class can accept new parameters. Lines 5, 104, 106 and 109 are interesting to you. This modification would only take you minutes.

SharathChandan commented 1 year ago

Sure. I was unsure whether two SX1276 class can function simultaneously. i mean to use two LoRa modules with different parameters on the same MCU. will get it done and post.

xg590 commented 1 year ago

Sure. I was unsure whether two SX1276 class can function simultaneously. i mean to use two LoRa modules with different parameters on the same MCU. will get it done and post.

Actually, there will be two instances of the same SX1276 class, which takes different modulation parameters during the initialization. Each instance has unique Pin specification and radio wave modulation parameters.

SharathChandan commented 1 year ago

lora1 = SX1276(RST_Pin1, CS_Pin1, SPI_CH, SCK_Pin1, MOSI_Pin1, MISO_Pin1, DIO0_Pin1, DIO1_Pin1, LoRa_id, channelsHopping, Bandwidth, SF, CR ) lora2 = SX1276(RST_Pin2, CS_Pin2, SPI_CH2, SCK_Pin2, MOSI_Pin2, MISO_Pin2, DIO0_Pin2, DIO1_Pin2, LoRa_id2, channels2Hopping, Bandwidth2, SF, CR)

should i be calling the function like this self.Bw = Bandwidth self.CR = CodingRate self.SF = SpreadingFactor

after this i'll remove the register mapped dictionary so in self.spi_write('RegModemConfig1', Bw << 4 | CR << 1 | ImplicitHeaderModeOn['Explicit']) self.spi_write('RegModemConfig2', SF << 4 | TxContinuousMode['normal'] << 3 | RxPayloadCrcOn['enable'] << 2 | 0x00)

is this right?

xg590 commented 1 year ago

is this right?

Let's say we want to set Coding Rate to 4/5 and 4/8, so we need made the following changes to lora.py

line 005    def __init__(self, RST_Pin, CS_Pin, SPI_CH, SCK_Pin, MOSI_Pin, MISO_Pin, DIO0_Pin, DIO1_Pin, SRC_Id, FHSS_list, plus20dBm=False, debug=False, CR=5):
line 104            self.spi_write('RegModemConfig1', Bw['125KHz'] << 4 | CodingRate[CR] << 1 | ImplicitHeaderModeOn['Explicit'])

following changes to receiver/receiver_1.py

line 20    lora_1 = SX1276(LoRa_RST_Pin, LoRa_CS_Pin, SPI_CH, LoRa_SCK_Pin, LoRa_MOSI_Pin, LoRa_MISO_Pin,
line 21                  LoRa_DIO0_Pin, LoRa_DIO1_Pin, LoRa_id, channels2Hopping, debug=False, CR=5)

and following changes to receiver/receiver_2.py

line 20    lora_2 = SX1276(LoRa_RST_Pin, LoRa_CS_Pin, SPI_CH, LoRa_SCK_Pin, LoRa_MOSI_Pin, LoRa_MISO_Pin,
line 21                  LoRa_DIO0_Pin, LoRa_DIO1_Pin, LoRa_id, channels2Hopping, debug=False, CR=8)
SharathChandan commented 1 year ago

Thanks a lot! I'll try it on my setup asap.

xg590 commented 1 year ago

Thanks a lot! I'll try it on my setup asap.

Out of curiosity, may I know what is your grade, university student? high schooler?

SharathChandan commented 1 year ago

I am university undergrad student in ECE. I wanted to explore a new technology hoping to use it for my university projects and i found your repo.

xg590 commented 1 year ago

I am university undergrad student in ECE. I wanted to explore a new technology hoping to use it for my university projects and i found your repo.

Since you are not a high schooler anymore, I would assume supportive information is better than actual code. ^_^ It is really cool to study engineering.

SharathChandan commented 1 year ago

True. I sorted out the code

class SX1276: def init(self, RST_Pin, CS_Pin, SPI_CH, SCK_Pin, MOSI_Pin, MISO_Pin, DIO0_Pin, DIO1_Pin, SRC_Id, FHSS_list,plus20dBm=False, debug=False, CR = 5, SF = 12, Bandwidth = '125KHz'): now i'm able to pass this parameters in my code itself.

SharathChandan commented 1 year ago

is it possible to store the received data. it usually gets printed in the console. should i be altering the brd_packet_handler?

xg590 commented 1 year ago

Yes, you can find an example in the sample code, where I named a variable, modified it in an overridden function (you already figured this out) and printed out the variable in main thread.

On Mon, Apr 10, 2023 at 03:53 Sharath Chandan @.***> wrote:

is it possible to store the received data. it usually gets printed in the console. should i be altering the brd_packet_handler?

— Reply to this email directly, view it on GitHub https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_xg590_SX1276_issues_13-23issuecomment-2D1501516899&d=DwMCaQ&c=slrrB7dE8n7gBJbeO0g-IQ&r=68-jaezqLTx9tGFv4ExwCQ&m=WoRuyOhk_77GAYoP227GBfGLumsTqbtp70pfd3Yzv-5Hr4bhwwbXYwf6zWzz8NqN&s=81T8qExdKofbBciZ9bKQS5xiD8R70DNNhVuoAmC9usI&e=, or unsubscribe https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AKJHY6AFZ3NO675H54E3WCDXAO4APANCNFSM6AAAAAAWLWCW4M&d=DwMCaQ&c=slrrB7dE8n7gBJbeO0g-IQ&r=68-jaezqLTx9tGFv4ExwCQ&m=WoRuyOhk_77GAYoP227GBfGLumsTqbtp70pfd3Yzv-5Hr4bhwwbXYwf6zWzz8NqN&s=hw3YE4K9z_yPh9EZRtixavuc4chcNS29NaJ8PdnEvPI&e= . You are receiving this because you commented.Message ID: @.***>