adafruit / RadioHead

A github'ified version of http://www.airspayce.com/mikem/arduino/RadioHead/
Other
186 stars 115 forks source link

Anyone got Dragino LoRa shield working with ESP32(S)? #49

Closed grasmanek94 closed 4 years ago

grasmanek94 commented 4 years ago

Hey all,

I have different devices:

I have tried to use them with the library, by connecting Dragino LoRa shields in the following manner:

ESP32S(Pin) <=> Dragino
SCK(14) <=> CLK (SPI Header)
MISO(12) <=> MISO (SPI Header)
MOSI(13) <=> MOSI (SPI Header)
SS(15) <=> Pin 10
GPIO2(2) <=> Pin 2
3V3 <=> 3V3
GND <=> GND

All else on Dragino shield is set to default. When I perform the above connections to Arduino (with jumper wires) and adjusting SS from 15 to pin 10 in code (default) then the library works.

Then I connect all cables to ESP32S or a ESP32 but they won't work.

I already figured out RadioHEad library somehow didn't use HSPI bus, so I forced the HSPI bus in code (and force the pins) in RHHardwareSPI.cpp:

   _settings = SPISettings(frequency, bitOrder, dataMode);
   SPI.begin(14,12,13,15);

Init works but send does nothing (tested by using a working arduino with dragino LoRa shield to listen for messages, messages work between 2 Arduino UNOs).

Code:

Arduino (to listen, test if message is received):

#include <Arduino.h>

#include "RadioHead/RH_RF95.h"

namespace LoraServer
{

RH_RF95 rf95;
RH_RF95 &driver = rf95;

float frequency = 868.0;

void setup()
{
    while (!rf95.init())
    {
        delay(100);
    }

    // Setup ISM frequency
    rf95.setFrequency(frequency);
    // Setup Power,dBm
    rf95.setTxPower(13);

    Serial.println("rf95.init() Done");
}

void loop()
{
    //Serial.println("Loop");
    if (driver.available())
    {
        Serial.println("Avail");
        uint8_t buf[driver.maxMessageLength()];
        uint8_t len = sizeof(buf);
        if (driver.recv(buf, &len))
        {
            Serial.print("Received: ");
            Serial.println((char *)&buf);
        }
        else
        {
            Serial.println("recv failed");
        }
    }
    delay(1000);
}

} // namespace LoraServer

void setup()
{
    delay(1000);
    Serial.begin(115200);
    Serial.println("Setup");

    LoraServer::setup();
}

void loop()
{
    LoraServer::loop();
}

And this code works on another Arduino:

#include <Arduino.h>

#include "RadioHead/RH_RF95.h"

namespace LoraClient
{

RH_RF95 rf95;
RH_RF95 &driver = rf95;

float frequency = 868.0;
char HWMessage[] = "Hello World ! I'm happy if you can read me";
uint8_t HWMessageLen;

void setup()
{
    HWMessageLen = strlen(HWMessage);
    while (!rf95.init())
    {
        delay(100);
    }

    // Setup ISM frequency
    rf95.setFrequency(frequency);
    // Setup Power,dBm
    rf95.setTxPower(13);

    Serial.println("rf95.init() Done");
}

void loop()
{
    Serial.println("Loop");
    driver.send((uint8_t *)HWMessage, sizeof(HWMessage)); // Send out ID + Sensor data to LoRa gateway
    Serial.print("Sent: ");
    Serial.println((char *)&HWMessage);
    delay(1000);
}

} // namespace LoraClient

void setup()
{
    delay(1000);
    Serial.begin(115200);
    Serial.println("Setup");

    LoraClient::setup();
}

void loop()
{
    LoraClient::loop();
}

So I port the Arduino Client to ESP32:

#include <Arduino.h>
#include "RadioHead/RH_RF95.h"

namespace LoraClient
{

RH_RF95 rf95(15, 2);
RH_RF95 &driver = rf95;

float frequency = 868.0;
char HWMessage[] = "Hello World ! I'm happy if you can read me";
uint8_t HWMessageLen;

void setup()
{
    HWMessageLen = strlen(HWMessage);

    hardware_spi.setBitOrder(RHGenericSPI::BitOrderMSBFirst);
    hardware_spi.setDataMode(RHGenericSPI::DataMode0);
    hardware_spi.setFrequency(RHGenericSPI::Frequency4MHz);

    while (!rf95.init())
    {
        delay(100);
    }

    // Setup ISM frequency
    rf95.setFrequency(frequency);
    // Setup Power,dBm
    rf95.setTxPower(13);

    Serial.println("rf95.init() Done");
}

void loop()
{
    Serial.println("Loop");
    driver.send((uint8_t *)HWMessage, sizeof(HWMessage)); // Send out ID + Sensor data to LoRa gateway
    Serial.print("Sent: ");
    Serial.println((char *)&HWMessage);
    delay(1000);
}

} // namespace LoraClient

void setup()
{
    delay(1000);

    Serial.begin(115200);
    Serial.println("Setup");

    LoraClient::setup();
}

void loop()
{
    LoraClient::loop();
}

And I get this output:

Setup
rf95.init() Done
Loop
Sent: Hello World ! I'm happy if you can read me
Loop

Then it gets stuck. And Receiver (Arduino Server) doesn't receive anything. With two Arduino's this works fine.

I did check all connections with a multimeter (Ohms) to check if they're intact, and all are (measured from top of ESP to pins on Dragino shield, not measured on the jumper wires themselves, which means they really are connected).

I don't have access to a logic analyzer at the moment..

Edit: I have also noticed that the default SPI is VSPI on ESP32 / ESP32S, I tried that one but then communications is completely broken / doesn't work (I did revert my changes in HardwareSPI.cpp and also connected the pins correctly to VSPI pins).

grasmanek94 commented 4 years ago

It was a weird issue (as expected) on my side..

I specified the same temporary output path for multiple projects in vscode-arduino, which somehow made the linker use old code?

I disabled that feature and completely recompiled every project.

It works now (on VSPI bus).