daveake / pico-tracker

GNU General Public License v3.0
44 stars 9 forks source link

Reusing Lora code #3

Closed codebrane closed 3 years ago

codebrane commented 3 years ago

This is really just a request for clarification on reusing the lora code. Trying to get an MCU using the Arduino LoRa library to work with a pico using this project.

I have an ESP32 Lolin32 Lite listening for messages from a pico which is transmitting. Both are using SX1278 modules. Both modules work as the Lolin32 can recieve from a Node MCU ESP8266 which was using the board the pico is now using. I put it back on the 8266 to verify it is working.

For the pico I've only reused from pico-tracker:

int main() {
  setup_lora(433.0, 6, "CODEBRANE");
}

unsigned char loraBuffer[20] = "Hello From Pico!";
while (1) {
  SendLoRaPacket(loraBuffer, 16, 0);
  sleep_ms(5000);
}

I modified SetupRFM98() to add:

else if (Mode == 6)
{
  ImplicitOrExplicit = IMPLICIT_MODE;
  ErrorCoding = ERROR_CODING_4_5;
  Bandwidth = BANDWIDTH_20K8;
  SpreadingFactor = SPREADING_6;
  LowDataRateOptimize = 0;
}

and the Lolin32 is using the LoRa Arduino library:

void setup() {
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }

  LoRa.setTxPower(17);
  LoRa.setSpreadingFactor(6);
  LoRa.setCodingRate4(5);
  LoRa.setSignalBandwidth(20.8E3);
}

void loop() {
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // parse the packet
  }
}

but the receiver never picks anything up from the pico.

Is there something else I should do to reuse the lora code?

many thanks for any advice you could give.

daveake commented 3 years ago

So, for it to work you need 3 things:

1 - Matching frequency, remembering that LoRa modules can be a few kHz off nominal and that Tx and Rx need to be within about 20% of the set bandwidth, which is 4kHz for those settings 2 - Identical spreading factor etc 3 - For implicit mode, which you are using, Tx and Rx need to be set for the same packet length

For testing, I'd switch to explicit mode and I'd use a wider bandwidth. Remember that in doing so you may (depending on local radio laws) be breaking duty cycle and/or bandwidth limits, but for testing that's what I'd do.

Dave

On Mon, 26 Apr 2021 at 19:36, Alistair Young @.***> wrote:

This is really just a request for clarification on reusing the lora code. Trying to get an MCU using the Arduino LoRa library to work with a pico using this project.

I have an ESP32 Lolin32 Lite listening for messages from a pico which is transmitting. Both are using SX1278 modules. Both modules work as the Lolin32 can recieve from a Node MCU ESP8266 which was using the board the pico is now using. I put it back on the 8266 to verify it is working.

For the pico I've only reused from pico-tracker:

int main() { setup_lora(433.0, 6, "CODEBRANE"); }

unsigned char loraBuffer[20] = "Hello From Pico!"; while (1) { SendLoRaPacket(loraBuffer, 16, 0); sleep_ms(5000); }

I modified SetupRFM98() to add:

else if (Mode == 6) { ImplicitOrExplicit = IMPLICIT_MODE; ErrorCoding = ERROR_CODING_4_5; Bandwidth = BANDWIDTH_20K8; SpreadingFactor = SPREADING_6; LowDataRateOptimize = 0; }

and the Lolin32 is using the LoRa Arduino library:

void setup() { if (!LoRa.begin(433E6)) { Serial.println("Starting LoRa failed!"); while (1); }

LoRa.setTxPower(17); LoRa.setSpreadingFactor(6); LoRa.setCodingRate4(5); LoRa.setSignalBandwidth(20.8E3); }

void loop() { int packetSize = LoRa.parsePacket(); if (packetSize) { // parse the packet } }

but the receiver never picks anything up from the pico.

Is there something else I should do to reuse the lora code?

many thanks for any advice you could give.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/daveake/pico-tracker/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIGQ5FZKVKHB3GTQ4ATLTDTKWXDBANCNFSM43TNVCBA .

codebrane commented 3 years ago

thank you very much for your advice, it's very much appreciated.

Based on what you said about testing I got them communicating with the following on the pico:


int main() {
  setup_lora(433, 6, "CODEBRANE");
  unsigned char loraBuffer[20] = "Hello From Pico!";
  while (1) {
    SendLoRaPacket(loraBuffer, 16, 0);
    sleep_ms(5000);
  }
}
void SetupRFM98(float Frequency, int Mode) {
  else if (Mode == 6)
  {
    ImplicitOrExplicit = EXPLICIT_MODE;
    ErrorCoding = ERROR_CODING_4_8;
    Bandwidth = BANDWIDTH_62K5;
    SpreadingFactor = SPREADING_8;
    LowDataRateOptimize = 0;
  }
}

and on the ESP32:

void setup() {
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }

  LoRa.setTxPower(17);
  LoRa.setSpreadingFactor(8);
  LoRa.setCodingRate4(8);
  LoRa.setSignalBandwidth(62.5E3);
}
daveake commented 3 years ago

Excellent. If you can get the received frequency error from the receiver code, then you adjust either the receiver or transmitter to make that about zero, then you can use a narrower bandwidth.

On Mon, 26 Apr 2021, 20:13 Alistair Young, @.***> wrote:

thank you very much for your advice, it's very much appreciated.

Based on what you said about testing I got them communicating with the following on the pico:

int main() { setup_lora(433, 6, "CODEBRANE"); unsigned char loraBuffer[20] = "Hello From Pico!"; while (1) { SendLoRaPacket(loraBuffer, 16, 0); sleep_ms(5000); } }

void SetupRFM98(float Frequency, int Mode) { else if (Mode == 6) { ImplicitOrExplicit = EXPLICIT_MODE; ErrorCoding = ERROR_CODING_4_8; Bandwidth = BANDWIDTH_62K5; SpreadingFactor = SPREADING_8; LowDataRateOptimize = 0; } }

and on the ESP32:

void setup() { if (!LoRa.begin(433E6)) { Serial.println("Starting LoRa failed!"); while (1); }

LoRa.setTxPower(17); LoRa.setSpreadingFactor(8); LoRa.setCodingRate4(8); LoRa.setSignalBandwidth(62.5E3); }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/daveake/pico-tracker/issues/3#issuecomment-827080432, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIGQ5ES47PH2NCMFCEII5DTKW3OZANCNFSM43TNVCBA .

codebrane commented 3 years ago

I'll close the issue now, thanks for the help. Got it down to 15Kz. I think to get it lower I'll need a TCXO.