Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple nodes failing on ESP32 resolved and FHSS Turned off #8

Closed
SharathChandan opened this issue Feb 1, 2023 · 34 comments
Closed

Comments

@SharathChandan
Copy link

I have connected multiple nodes to the ESP32 and Lora isn't getting initialized. The interfaces are working fine.

@xg590
Copy link
Owner

xg590 commented Feb 1, 2023

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?

@SharathChandan
Copy link
Author

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

@xg590
Copy link
Owner

xg590 commented Feb 1, 2023 via email

@SharathChandan
Copy link
Author

71kEWzr29bL AC_SL1001
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.

@SharathChandan
Copy link
Author

good evening! have you tried the script on your setups?

@xg590
Copy link
Owner

xg590 commented Feb 2, 2023

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.

@SharathChandan
Copy link
Author

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.

@xg590
Copy link
Owner

xg590 commented Feb 3, 2023

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.

@SharathChandan
Copy link
Author

Thanks. I will look into the library in detail.

@xg590
Copy link
Owner

xg590 commented Feb 3, 2023

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.

@SharathChandan
Copy link
Author

what is the significance of the RST_Pin in the scheme? kindly explain

@xg590
Copy link
Owner

xg590 commented Feb 4, 2023

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.

@xg590
Copy link
Owner

xg590 commented Feb 4, 2023

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.

@SharathChandan
Copy link
Author

Sure. kindly let me know once you are able to run it.

@SharathChandan
Copy link
Author

is it possible to drive two spi devices simultaneously without multithreading in micropython?

@xg590
Copy link
Owner

xg590 commented Feb 6, 2023 via email

@SharathChandan
Copy link
Author

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?

@SharathChandan
Copy link
Author

i mean sending without ack simultaneously

@xg590
Copy link
Owner

xg590 commented Feb 9, 2023

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

# 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

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)

# 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

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

# Heltec WiFi LoRa 32 V2
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)

@xg590
Copy link
Owner

xg590 commented Feb 9, 2023

i mean sending without ack simultaneously

  • As you can see from my last comment, we can use two SPI interfaces of the same MCU. That is the whole point of your initial question.
  • Other than this, for example, can you use two threads (two cores) to send two messages at the exact same time? Yes if your hardware (MCU) and software allow you to do so. AFAIK, port for Pico allows an additional thread. FYI, you cannot use the second core of ESP32 in the pre-built micropython. See this discussion #7258.
  • Will you succeed to receive two messages on the same receiver at the exact same time? Of course not. How about receiving two messages from different frequency hopping sequences (so that no interference) on two receivers. Yes. All in all, This kind of question depends on your own hardware and you coding. That are unrelated to the library.

@xg590
Copy link
Owner

xg590 commented Feb 9, 2023

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.

@xg590
Copy link
Owner

xg590 commented Feb 9, 2023

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.

@SharathChandan
Copy link
Author

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.

@SharathChandan
Copy link
Author

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.

@xg590
Copy link
Owner

xg590 commented Feb 9, 2023

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.

@xg590
Copy link
Owner

xg590 commented Feb 9, 2023

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

@SharathChandan
Copy link
Author

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.

@SharathChandan
Copy link
Author

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.

@SharathChandan SharathChandan changed the title Multiple nodes failing on ESP32 Multiple nodes failing on ESP32 resolved and FHSS Turned off Feb 10, 2023
@xg590 xg590 mentioned this issue Feb 15, 2023
@SharathChandan
Copy link
Author

,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.

@xg590 xg590 reopened this Mar 15, 2023
@xg590
Copy link
Owner

xg590 commented Mar 16, 2023

,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.

@SharathChandan
Copy link
Author

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.

@xg590 xg590 closed this as completed Mar 17, 2023
@SharathChandan
Copy link
Author

Can you let know how can i modify the spreading factor in my code itself?

@xg590
Copy link
Owner

xg590 commented Mar 18, 2023

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'])

@xg590 xg590 reopened this Mar 18, 2023
@SharathChandan
Copy link
Author

sure i'll continue this on a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants