sandeepmistry / arduino-LoRa

An Arduino library for sending and receiving data using LoRa radios.
MIT License
1.63k stars 626 forks source link

Starting LoRa failed #352

Closed MariaDan closed 4 years ago

MariaDan commented 4 years ago

I am receiving Starting LoRa failed while using the demo code. Hardware used: Adafruit ItsyBitsy 32u4 - 3V 8MHz and LoRa SX1278 433MHz. Library used: https://github.com/sandeepmistry/arduino-LoRa Connections: http://www.electronoobs.com/eng_arduino_tut97.php?fbclid=IwAR16EaaTZf3wA0j9nHODxx-9tqBVvVFJPsZ0sz7rHZG99tS_dYMdQxYfTFA Arduino IDE Setup: https://learn.adafruit.com/introducting-itsy-bitsy-32u4/arduino-ide-setup

I verified everything and seems to be fine, I don't understand why I get this error. Would you mind helping me, please?

Thank you so much!

IoTThinks commented 4 years ago

No one can do a blind guess with insufficient information. Likely a pin mapping error to wrong SPI pin. And wrong SS pin.

MariaDan commented 4 years ago

Please tell me what kind of information is missing, so I can give it to you. I left the connections link above, a screenshot from the links above is here: Screenshot_20200328_052104

IoTThinks commented 4 years ago

Your physical pin connection is right to me.

Do this to make sure the pins are right in software. Of course you need to replace the correct pins to those LORA_... And make sure you choose the correct board.

And normally Arduino Uno will not have enough current to send LoRa packets far.

99.99% of "Starting LoRa failed" is wrong pin mapping.

  SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI);
  LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO012);

  while (!LoRa.begin(433E6)) {
   Serial.println("Starting LoRa failed");
    delay(1000);
  }

View more at https://github.com/sandeepmistry/arduino-LoRa/blob/master/API.md#set-pins. Good luck.

MariaDan commented 4 years ago

Thank you for your answer. When I compile, I get this error: no matching function for call to 'SPIClass::begin(int, int, int)'

The entire error is here: "C:\Users\User\AppData\Local\Temp\arduino_modified_sketch_150590\LoRaSender.ino: In function 'void setup()': LoRaSender:8:23: error: no matching function for call to 'SPIClass::begin(int, int, int)'

SPI.begin(13, 12, 11); ^ In file included from C:\Users\User\AppData\Local\Temp\arduino_modified_sketch_150590\LoRaSender.ino:1:0:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SPI\src/SPI.h:159:15: note: candidate: static void SPIClass::begin()

static void begin(); ^~~~~ C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SPI\src/SPI.h:159:15: note: candidate expects 0 arguments, 3 provided

exit status 1 no matching function for call to 'SPIClass::begin(int, int, int)'"

IoTThinks commented 4 years ago

My bad, SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI); is for arduino-esp32 only. You can remove the above line for Arduino as the SPI pins are fixed.

MariaDan commented 4 years ago

I get the same error. Is is possible to be a problem the fact that I use Adafruit ItsyBitsy 32u4 - 3V 8MHz to replace Arduino Uno?

12

IoTThinks commented 4 years ago

Last try. In setup() pinMode(LoRa_SS, OUTPUT); digitalWrite(LoRa_SS, HIGH);

If no luck, then Arduino Uno is a better choice than Arduino Nano.

IoTThinks commented 4 years ago

Or you set the SPI frequency down to 8Mhz. LoRa.setSPIFrequency(8E6); https://github.com/sandeepmistry/arduino-LoRa/blob/master/API.md#set-spi-frequency

Too low MCU frequency may affect SPI connection. Arduino Nano has 16Mhz frequency. Your module only has 8Mhz.

MariaDan commented 4 years ago

Unfortunately, it still doesn't work. I tried on Arduino Uno and it works. What can be the difference? What should I modify on my Itsy Bitsy to make it work as well?

IoTThinks commented 4 years ago

I suspect the frequency of your board is too low (8Mhz),

Or your board's pin definition is different from Nano or Uno.

Or the power input of your board is insufficient. You can try to provide external power to LoRa.

MariaDan commented 4 years ago

Thank you so much! You have all my respect. I declare this issue closed.

MariaDan commented 4 years ago

I found and solved the issue, maybe this answer will help someone:

  1. Itsy Bitsy has different pinout, so you should make the following connections: LoRa module -> Itsy Bitsy GND -> GND Vcc -> 3.3V MISO -> MISO MOSI -> MOSI
    SLCK -> SCK Nss -> D10 Di00 -> D7 RST -> D9

  2. Add the code below in void setup: LoRa.setSPIFrequency(8E6); //set the SPI frequency down to 8Mhz LoRa.setPins(10, 9, 7); //override the default NSS, NRESET, and DIO0 pins used by the library

  3. Don't forget to change the frequency, write the one your LoRa module is using. Mine has 433 MHz: LoRa.begin(433E6)

IoTThinks commented 4 years ago

Love to hear the working update.

Remember to update the lib to 0.7.2. 0.7.1 has issue.