SDI12 and LoRA librarys Problem

Hi there

I would like to combine the functions of the SDI12 library and the LoRa library.
For testin i used the example LoRaSender.ino & LoRaReciever.ino.

I adding a function to read one SDI12 Sensor.

The Problem is if I call the function to read my Sensor the Program stuck when it is about to write over LoRa to the Reciever.

If I comment out the function Lora writes to the Reciever.
If I comment out the send Packet LoRa part, my SDI12 function delivers data every 5 sec.

Why isn't I working together?

I hope somebody can help me. Thanks in advance...

Here is the code:

#include <SDI12.h>
#include <SPI.h>
#include <LoRa.h>

#define DATA_PIN 53 /*!< The pin of the SDI-12 data bus */
#define POWER_PIN -1
#define SENSOR_ADDRESS 0

int counter = 0;

/** Define the SDI-12 bus */
SDI12 mySDI12(DATA_PIN);

void setup()
{
Serial.begin(9600);
while (!Serial);

Serial.println("LoRa Sender");

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

Serial.println("Opening SDI-12 bus...");
mySDI12.begin();
delay(500);  // allow things to settle

}

void loop()
{

String myData = daten();
Serial.println(myData);


Serial.println(counter);

// send packet
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();

counter++;

delay(5000);

}

//Funktion Sensor daten SDI 12 5TM---------------------------------------------------------------------

String daten() {
String dataString;

mySDI12.sendCommand("0M!");
delay(500);
mySDI12.clearBuffer();
//Command Read
mySDI12.sendCommand("0D0!");
delay(500);
// build response string
while (mySDI12.available()) {
    char c = mySDI12.read();
    if ((c != 45) && (c != 43)) {
        dataString += c;
        delay(10);  // 1 character ~ 7.5ms
    }
    else {
        dataString += ";";
        dataString += c;
    }
}
mySDI12.clearBuffer();
if (dataString.length() > 1){
return dataString;
}

}

Always helpful to tell the forum which Arduino you are using and to provide a connection diagram ...................................

So I will guess because of this line assigning pin 53;

#define DATA_PIN 53 /*!< The pin of the SDI-12 data bus */

Your using a Mega 2560 maybe ?

In which case if you look at a pinout diagram you will see pin 53 on a Mega is the default SS pin used by the SPI library ........ so try a different pin for your SDI-12

Hi, @unverricht_p
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hi srnet

Thank you very, very much for the quick answer.

I use for the Sender Arduino Mega 2560 and a Draguino LoRa Shield.
The Receiver is a Uno with the same shield.

I changed the pin from 53 to 15 but no sucess.
Removing the SPI library doesn't helped either.

The SDI12 Pins available on a Mega is pretty limited.

Arduino Mega or Mega 2560 SDI12 Pins:

  • 0, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)

The Draguino shield uses Digital Pin 8..13, 6,7,2

However, the 50+ Pins from my Mega didn't worked. So I changed the Sender to a Uno as well.
Any Uno Pin is available for SDI12 , sparing the Draguino Pins of coarse.

Now it works. But I don't know why.
I think srnet, you are wright, but what was the exact Problem eliminating the SPI Library?



#include <SDI12.h>
//#include <SPI.h>
#include <LoRa.h>


#define DATA_PIN 4        /*!< The pin of the SDI-12 data bus */
#define POWER_PIN -1
#define SENSOR_ADDRESS 0


int counter = 0;


/** Define the SDI-12 bus */
SDI12 mySDI12(DATA_PIN);


void setup()
{
    Serial.begin(9600);
    while (!Serial);

    Serial.println("LoRa Sender");

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

    Serial.println("Opening SDI-12 bus...");
    mySDI12.begin();
    delay(500);  // allow things to settle
}

void loop()
{

    String myData = daten();
    Serial.println(myData);

 
    Serial.println(counter);

    // send packet
    LoRa.beginPacket();
    LoRa.print(myData);
    LoRa.print(counter);
    LoRa.endPacket();

    counter++;

    delay(5000);

   
 

}



//Funktion Sensor daten SDI 12 5TM---------------------------------------------------------------------

String daten() {
    String dataString;

    mySDI12.sendCommand("0M!");
    delay(500);
    mySDI12.clearBuffer();
    //Command Read
    mySDI12.sendCommand("0D0!");
    delay(500);
    // build response string
    while (mySDI12.available()) {
        char c = mySDI12.read();
        if ((c != 45) && (c != 43)) {
            dataString += c;
            delay(10);  // 1 character ~ 7.5ms
        }
        else {
            dataString += ";";
            dataString += c;
        }
    }
    mySDI12.clearBuffer();
    if (dataString.length() > 1){
    return dataString;
    }
    
    
}


Thank you !

But you did not, the LoRa library loads SPI.h by default.

And since the LoRa device is a SPI device the LoRa code would not compile with the SPI library missing.

Ah....
I though I had:

#include <SDI12.h>
//#include <SPI.h>
#include <LoRa.h>

But now it's clear.
Thank you!!!

Have a great day.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.