Closed SharathChandan closed 1 year ago
I have connected multiple nodes to the ESP32 and Lora isn't getting initialized. The interfaces are working fine.
Do you mind share you whole script here?
from machine import Pin, SPI import time, urandom as random from lora import SX1276
RST_Pin1 = 26 CS_Pin1 = 5 SCK_Pin1 = 18 MOSI_Pin1 = 23 MISO_Pin1 = 19 DIO0_Pin1 = 2 DIO1_Pin1 = 35 SPI_CH = 1
RST_Pin2 = 27 CS_Pin2 = 15 SCK_Pin2 = 14 MOSI_Pin2 = 13 MISO_Pin2 = 12 DIO0_Pin2 = 0 DIO1_Pin2 = 34 SPI_CH2 = 2
LoRa_id = 1
random.seed(11)
channels2Hopping = [866_000_000+200_000 * random.randint(0,10) for i in range(128)] # 914~916 MHz
lora = SX1276(RST_Pin1, CS_Pin1, SPI_CH, SCK_Pin1, MOSI_Pin1, MISO_Pin1, DIO0_Pin1, DIO1_Pin1, LoRa_id, channels2Hopping)
payload = str(random.randint(100,65536))+ "I am Sharath 1" print(payload) lora.send(dst_id=3, msg=payload, pkt_type=lora.PKT_TYPE['REQ']) # Sender's lora_id is 1 and receiver's is 0
LoRa_id2 = 2
random.seed(11)
channels2Hopping2 = [866_000_000+200_000 * random.randint(0,10) for i in range(128)] # 914~916 MHz
lora2 = SX1276(RST_Pin2, CS_Pin2, SPI_CH2, SCK_Pin2, MOSI_Pin2, MISO_Pin2, DIO0_Pin2, DIO1_Pin2, LoRa_id2, channels2Hopping2)
payload2 = str(random.randint(100,65536))+" I am Sharath 2" print(payload2) lora2.send(dst_id=4, msg=payload2, pkt_type=lora2.PKT_TYPE['REQ']) # Sender's lora_id is 1 and receiver's is 0
A simple question, may I have your MCU’s pin out map or the eBay/aliexpress link you bought the MCU? meanwhile I am going to try your code on my setups tonight.
On Wed, Feb 1, 2023 at 1:26 AM SharathChandan @.***> wrote:
from machine import Pin, SPI import time, urandom as random from lora import SX1276
LoRa Pinout
RST_Pin1 = 26 CS_Pin1 = 5 SCK_Pin1 = 18 MOSI_Pin1 = 23 MISO_Pin1 = 19 DIO0_Pin1 = 2 DIO1_Pin1 = 35 SPI_CH = 1
LoRa2 Pinout
RST_Pin2 = 27 CS_Pin2 = 15 SCK_Pin2 = 14 MOSI_Pin2 = 13 MISO_Pin2 = 12 DIO0_Pin2 = 0 DIO1_Pin2 = 34 SPI_CH2 = 2
LoRa_id = 1 random.seed(11) channels2Hopping = [866_000_000+200_000 * random.randint(0,10) for i in range(128)] # 914~916 MHz lora = SX1276(RST_Pin1, CS_Pin1, SPI_CH, SCK_Pin1, MOSI_Pin1, MISO_Pin1, DIO0_Pin1, DIO1_Pin1, LoRa_id, channels2Hopping)
payload = str(random.randint(100,65536))+ "I am Sharath 1" print(payload) lora.send(dst_id=3, msg=payload, pkt_type=lora.PKT_TYPE['REQ']) # Sender's lora_id is 1 and receiver's is 0
LoRa_id2 = 2 random.seed(11) channels2Hopping2 = [866_000_000+200_000 * random.randint(0,10) for i in range(128)] # 914~916 MHz lora2 = SX1276(RST_Pin2, CS_Pin2, SPI_CH2, SCK_Pin2, MOSI_Pin2, MISO_Pin2, DIO0_Pin2, DIO1_Pin2, LoRa_id2, channels2Hopping2)
payload2 = str(random.randint(100,65536))+" I am Sharath 2" print(payload2) lora2.send(dst_id=4, msg=payload2, pkt_type=lora2.PKT_TYPE['REQ']) # Sender's lora_id is 1 and receiver's is 0
— Reply to this email directly, view it on GitHub https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_xg590_SX1276_issues_8-23issuecomment-2D1411530912&d=DwMCaQ&c=slrrB7dE8n7gBJbeO0g-IQ&r=68-jaezqLTx9tGFv4ExwCQ&m=EaPgsd3KkiiqvBdzIrYFChwnpgGuv_dYa_v6Uz88Qe9vnNeFxI22xuCVSwBpe7j3&s=juVUrVJ5MYp_W9r8rc_c62n0DZqvj0e_5WljaaoiLNo&e=, or unsubscribe https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AKJHY6HMMJLGVX75I6SCUZDWVH6YRANCNFSM6AAAAAAUNJKP5U&d=DwMCaQ&c=slrrB7dE8n7gBJbeO0g-IQ&r=68-jaezqLTx9tGFv4ExwCQ&m=EaPgsd3KkiiqvBdzIrYFChwnpgGuv_dYa_v6Uz88Qe9vnNeFxI22xuCVSwBpe7j3&s=6Y7rxsBf6FM1tlJ9FKaq9j5zwc9Tp6yAuIEix10_TnM&e= . You are receiving this because you commented.Message ID: @.***>
I have attached the Pin out for reference. It would be of great help if you could let me know the issue with the script.
good evening! have you tried the script on your setups?
good evening! have you tried the script on your setups?
Hi, I got hardware problem to setup my development environment. I ordered a new RAM moments ago. Will try it tomorrow night. Sorry for the delay.
It's fine. do it at your convenience. I have a doubt regarding the library. For class SX1276 can i remove a few arguments such as the DIO0 or DIO1 since i can accommodate more hardware on my MCU? kindly help in this regard.
It's fine. do it at your convenience. I have a doubt regarding the library. For class SX1276 can i remove a few arguments such as the DIO0 or DIO1 since i can accommodate more hardware on my MCU? kindly help in this regard.
TLDR: you should not. Long explain. DIO0 and DIO1 are for interrupt. For example, how do your MCU knows SX1276 has sent out the REQ message so it should start listening for ACK packet? The SX1276 will interrupt MCU via DIO0 and DIO1 so MCU runs “interrupt service routine” to set off the Tx->Rx transition.
Thanks. I will look into the library in detail.
Thanks. I will look into the library in detail.
I made many comments about the interrupt at Section 4 of the library. _irq_handler (interrupt service routine) is also worthy of digging in.
what is the significance of the RST_Pin in the scheme? kindly explain
what is the significance of the RST_Pin in the scheme? kindly explain
For example, during the code development, you may change the SX1276 class and need to re-instantiate this class (kill micropython script and re-run it). You use rst_pin to reset SX1276 chip at every time.
If you can physically change the pin connection, you can repurpose the pin after SX1276 initiation. It is highly unlikely you want to mess with RST_PIN.
what is the significance of the RST_Pin in the scheme? kindly explain
Cannot run the second sx1276 because the software SPI is not working. Will try it later or use another MCU to test.
Sure. kindly let me know once you are able to run it.
is it possible to drive two spi devices simultaneously without multithreading in micropython?
To the best of my knowledge, the short answer is yes. Each device would interrupt the MCU if something happened (RxDone or TxDone or FHSSchangeChannel) independently. Then the MCU will try to finish ISR as soon as possible before the running of the main thread resumes.
I believe it can print out a received message via one SX1276 while it is sending out a message through another SX1276. You cannot send two messages via two interfaces simultaneously for obvious reasons.
On Mon, Feb 6, 2023 at 4:05 AM SharathChandan @.***> wrote:
is it possible to drive two spi devices simultaneously without multithreading in micropython?
— Reply to this email directly, view it on GitHub https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_xg590_SX1276_issues_8-23issuecomment-2D1418738324&d=DwMCaQ&c=slrrB7dE8n7gBJbeO0g-IQ&r=68-jaezqLTx9tGFv4ExwCQ&m=HmIKCiqt7vxz31MJggzXEJbLEUE3tZ8ZKHBaWEL6LCr0uK86enbdoQjFePQ6b0k1&s=Jp0OwjlQ7nhmqKCE6mgAhwJkVHVeonIQEtlr_PKs71o&e=, or unsubscribe https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_AKJHY6GCC2CACDF2XEMQ46DWWC5GDANCNFSM6AAAAAAUNJKP5U&d=DwMCaQ&c=slrrB7dE8n7gBJbeO0g-IQ&r=68-jaezqLTx9tGFv4ExwCQ&m=HmIKCiqt7vxz31MJggzXEJbLEUE3tZ8ZKHBaWEL6LCr0uK86enbdoQjFePQ6b0k1&s=eLcekI0auCg9IkSBUGHO_6qFrgrAV68X_b8ryJDd1M4&e= . You are receiving this because you commented.Message ID: @.***>
from machine import Pin, SPI import time, urandom as random from lora import SX1276
LoRa Pinout
RST_Pin1 = 26 CS_Pin1 = 5 SCK_Pin1 = 18 MOSI_Pin1 = 23 MISO_Pin1 = 19 DIO0_Pin1 = 2 DIO1_Pin1 = 35 SPI_CH = 1
LoRa2 Pinout
RST_Pin2 = 27 CS_Pin2 = 15 SCK_Pin2 = 14 MOSI_Pin2 = 13 MISO_Pin2 = 12 DIO0_Pin2 = 0 DIO1_Pin2 = 34 SPI_CH2 = 2
LoRa_id = 1 random.seed(11)
channels2Hopping = [866_000_000+200_000 * random.randint(0,10) for i in range(128)] # 914~916 MHz
lora = SX1276(RST_Pin1, CS_Pin1, SPI_CH, SCK_Pin1, MOSI_Pin1, MISO_Pin1, DIO0_Pin1, DIO1_Pin1, LoRa_id, channels2Hopping)payload = str(random.randint(100,65536))+ "I am Sharath 1" print(payload) lora.send(dst_id=3, msg=payload, pkt_type=lora.PKT_TYPE['REQ']) # Sender's lora_id is 1 and receiver's is 0
LoRa_id2 = 2 random.seed(11)
channels2Hopping2 = [866_000_000+200_000 * random.randint(0,10) for i in range(128)] # 914~916 MHz
lora2 = SX1276(RST_Pin2, CS_Pin2, SPI_CH2, SCK_Pin2, MOSI_Pin2, MISO_Pin2, DIO0_Pin2, DIO1_Pin2, LoRa_id2, channels2Hopping2)payload2 = str(random.randint(100,65536))+" I am Sharath 2" print(payload2) lora2.send(dst_id=4, msg=payload2, pkt_type=lora2.PKT_TYPE['REQ']) # Sender's lora_id is 1 and receiver's is 0
then will multi-threading using micropython achieve simultaneous transmission in the context of the above script?
i mean sending without ack simultaneously
i mean sending without ack simultaneously
I finally setup the right testing environment and now can confirm two SX1276 works perfectly on one MCU.
Here is my testing environment.
Sender: I hooked 1st and 2nd SX1276 chips (RFM95W) up to a Raspberry Pi Pico (which has two on-chip SPI controllers)
Receiver: I use the third SX1276 (Heltec WiFi LoRa 32 V2 / ESP32 MCU).
Sender:
from machine import Pin
import time, urandom as random
from lora import SX1276
random.seed(11) channels2Hopping = [914_000_000+200_000 * random.randint(0,10) for i in range(128)] # 914~916 MHz
SPI_CH = 0 LoRa_DIO1_Pin = 26 LoRa_En_Pin = 21 LoRa_DIO0_Pin = 20 LoRa_SCK_Pin = 18 LoRa_MISO_Pin = 16 LoRa_MOSI_Pin = 19 LoRa_CS_Pin = 17 LoRa_RST_Pin = 22 LoRa_id = 0
lora_0_en = Pin(LoRa_En_Pin, Pin.OUT) # create output pin on GPIO0 lora_0_en.on() lora_0 = SX1276(LoRa_RST_Pin, LoRa_CS_Pin, SPI_CH, LoRa_SCK_Pin, LoRa_MOSI_Pin, LoRa_MISO_Pin, LoRa_DIO0_Pin, LoRa_DIO1_Pin, LoRa_id, channels2Hopping, debug=False)
SPI_CH = 1 LoRa_DIO1_Pin = 7 LoRa_En_Pin = 8 LoRa_DIO0_Pin = 9 LoRa_SCK_Pin = 10 LoRa_MISO_Pin = 12 LoRa_MOSI_Pin = 11 LoRa_CS_Pin = 13 LoRa_RST_Pin = 15 LoRa_id = 1
lora_1_en = Pin(LoRa_En_Pin, Pin.OUT) # create output pin on GPIO0 lora_1_en.on() lora_1 = SX1276(LoRa_RST_Pin, LoRa_CS_Pin, SPI_CH, LoRa_SCK_Pin, LoRa_MOSI_Pin, LoRa_MISO_Pin, LoRa_DIO0_Pin, LoRa_DIO1_Pin, LoRa_id, channels2Hopping, debug=False)
payload = str(random.randint(100,65536))+") [LoRa 0] This long BRD packet will be received" # Broadcast a large packet so many hops are generated~ print('[Sending]', payload) lora_0.send(dst_id=2, msg=payload, pkt_type=lora_0.PKT_TYPE['BRD']) # A broadcast request. Do not expect respond.
time.sleep(3) payload = str(random.randint(100,65536))+") [LoRa 1] This long BRD packet will also be received even though a wrong dst_id is specified. It is BRD, dst_id does not matter~" print('[Sending]', payload) lora_1.send(dst_id=3, msg=payload, pkt_type=lora_1.PKT_TYPE['BRD']) # A broadcast request. Do not expect respond.
* Receiver
from machine import Pin import time, urandom as random from lora import SX1276
LoRa_MISO_Pin = 19 LoRa_MOSI_Pin = 27 LoRa_SCK_Pin = 5 LoRa_CS_Pin = 18 LoRa_RST_Pin = 14 LoRa_DIO0_Pin = 26 LoRa_DIO1_Pin = 35 LoRa_DIO2_Pin = 34 SPI_CH = 1
random.seed(11) channels2Hopping = [914_000_000+200_000 * random.randint(0,10) for i in range(128)] # Both sender and receiver need to know the sequence of frequences they are hopping on before the first hopping operation.
LoRa_id = 2 lora = SX1276(LoRa_RST_Pin, LoRa_CS_Pin, SPI_CH, LoRa_SCK_Pin, LoRa_MOSI_Pin, LoRa_MISO_Pin, LoRa_DIO0_Pin, LoRa_DIO1_Pin, LoRa_id, channels2Hopping, debug=False)
lora.brd_packet_handler = lambda self, data, SNR, RSSI: print("[BRD]", data)
received_payload = None lora.mode = 'RXCONTINUOUS' count = 0 while not lora.is_available: count += 3 print("waiting", count, 'second') time.sleep(count)
i mean sending without ack simultaneously
then will multi-threading using micropython achieve simultaneous transmission in the context of the above scri
Your coding is not for "simultaneous transmission", it is for sequential Tx. You send out one message via one SX1276 chip and send out another message via another SX1276 chip. I assume two chips working on difference frequencies.
At this point, I suggest you to use Pico as the MCU to operate two SX1276 chips at the same time. You can find that two SPI interfaces are clearly marked on the pinout map of Pico. Meanwhile, ESP32 is a mess to me. There are many variants. The code might works for me but not works for you. We don't even know which pins are for hardware SPI interfaces.
Great. It has cleared me all of my doubts. But i don't require frequency hopping can i let go FHSS and set a single frequency say 866.40 for a pair of transceivers and do simultaneous transmission on my SX1276. btw thank you once again for your efforts.
Yeah but it works fine on my esp32s devkit and i will try it on Pico after a while. Please let me know if its possible to use specific frequencies on my LoRa.
Great. It has cleared me all of my doubts. But i don't require frequency hopping can i let go FHSS and set a single frequency say 866.40 for a pair of transceivers and do simultaneous transmission on my SX1276. btw thank you once again for your efforts.
OK, I will update the library so that SX1276 will stay on one freq forever.
Yeah but it works fine on my esp32s devkit and i will try it on Pico after a while. Please let me know if its possible to use specific frequencies on my LoRa.
Done. FHSS can be turned off by only specifying one Freq.
channels2Hopping = [915_000_000]
or
channels2Hopping = [914_000_000+200_000 * random.randint(0,10) for i in range(1)]
BTW, can you elaborate on "it works fine on my esp32s devkit"? Does two SX1276 chips works on your single esp32s? If so, may I have your pin mapping? I mean this is my pin mapping. What is yours?
# First SX1276
SPI_CH = 0
LoRa_DIO1_Pin = 26
LoRa_En_Pin = 21
LoRa_DIO0_Pin = 20
LoRa_SCK_Pin = 18
LoRa_MISO_Pin = 16
LoRa_MOSI_Pin = 19
LoRa_CS_Pin = 17
LoRa_RST_Pin = 22
LoRa_id = 0
# Second SX1276
SPI_CH = 1
LoRa_DIO1_Pin = 7
LoRa_En_Pin = 8
LoRa_DIO0_Pin = 9
LoRa_SCK_Pin = 10
LoRa_MISO_Pin = 12
LoRa_MOSI_Pin = 11
LoRa_CS_Pin = 13
LoRa_RST_Pin = 15
LoRa_id = 1
Great. It has cleared me all of my doubts. But i don't require frequency hopping can i let go FHSS and set a single frequency say 866.40 for a pair of transceivers and do simultaneous transmission on my SX1276. btw thank you once again for your efforts.
OK, I will update the library so that SX1276 will stay on one freq forever.
Thank you for updating the library. I'll let you know after trying it on my setup.
Yeah but it works fine on my esp32s devkit and i will try it on Pico after a while. Please let me know if its possible to use specific frequencies on my LoRa.
Done. FHSS can be turned off by only specifying one Freq.
channels2Hopping = [915_000_000] or channels2Hopping = [914_000_000+200_000 * random.randint(0,10) for i in range(1)]
BTW, can you elaborate on "it works fine on my esp32s devkit"? Does two SX1276 chips works on your single esp32s? If so, may I have your pin mapping? I mean this is my pin mapping. What is yours?
# First SX1276 SPI_CH = 0 LoRa_DIO1_Pin = 26 LoRa_En_Pin = 21 LoRa_DIO0_Pin = 20 LoRa_SCK_Pin = 18 LoRa_MISO_Pin = 16 LoRa_MOSI_Pin = 19 LoRa_CS_Pin = 17 LoRa_RST_Pin = 22 LoRa_id = 0 # Second SX1276 SPI_CH = 1 LoRa_DIO1_Pin = 7 LoRa_En_Pin = 8 LoRa_DIO0_Pin = 9 LoRa_SCK_Pin = 10 LoRa_MISO_Pin = 12 LoRa_MOSI_Pin = 11 LoRa_CS_Pin = 13 LoRa_RST_Pin = 15 LoRa_id = 1
Yeah two SX1276 are working well now. I have figured out the hspi and vspi of my esp32 and it usually differs with different esp32 boards.
It;'s the the code which i previously shared with you. The DI0 pin was the problem i swapped it from GPI0 to a GPI04. There are few GPIOs which are not supposed to be used on the ESP32 i think GPIO0 was related to flash.
,Hello! Can you elaborate on the coding rates you have adopted in the library..is the CR 5,6,7 and 8 correspond to 4/5, 4/6, 4/7 and 4/8 in LoRa or have you used a different way. is it possible to send data with lesser cr. is it possible to code it in my program or should i modify the library each time.
,Hello! Can you elaborate on the coding rates you have adopted in the library..is the CR 5,6,7 and 8 correspond to 4/5, 4/6, 4/7 and 4/8 in LoRa or have you used a different way. is it possible to send data with lesser cr. is it possible to code it in my program or should i modify the library each time.
Your guess is correct. In addition, you can choose any configuration (CR, SF, Freq) but there are [state] regulation or regional norms you better to follow. For example, you can ask the same chip to run on 433MHz in US or 915MHz in Europe but it is illegal. I mean, really, your 868MHz chip can run at 100MHz but the output signal is much weaker (even you use 100MHz antenna). Any configuration is possible.
Great. I am planning to experiment different modulation on LoRa. while doing that the coding rate can be replaced with that of the respective modulation right. I just want to try out some stuff on LoRa.
Can you let know how can i modify the spreading factor in my code itself?
Can you let know how can i modify the spreading factor in my code itself?
If you got another new problem, please reopen the issue or open a new one. I just noticed your question.
Yes, it is very easy to choose another value for those radio parameters. Please refer to lines 101 ~ 106 of lora.py. For example, you can change both CR from 4/5 to 4/7 and bandwidth from 125KHz to 500kHz by modifying line 104 of https://github.com/xg590/SX1276/blob/8a0d7c4dda34454a5fadb04330c810e2b1990308/lora.py.
From
self.spi_write('RegModemConfig1', Bw['125KHz'] << 4 | CodingRate[5] << 1 | ImplicitHeaderModeOn['Explicit'])
to
self.spi_write('RegModemConfig1', Bw['500kHz'] << 4 | CodingRate[7] << 1 | ImplicitHeaderModeOn['Explicit'])
sure i'll continue this on a new issue.
I have connected multiple nodes to the ESP32 and Lora isn't getting initialized. The interfaces are working fine.