LORA help

Hi guys (& ladies). First time here and asking for some direction.

Have used Arduino at a very amateur hobby level but now wish to start a home grown

data transfer program.

I need a system with one master and up to 10 slaves spread out over a distance of 5 miles.

After some studies have found that LORA probably best fits my requirements.

Have purchased 2 DUINOTECH arduino shields (915 MHz) and 2 Arduino Uno boards.

Can you point me to a program just to get me started by transferring data

from one unit to another at a range of about 1 metre (to start).

Thanks :o

The RadioHead Library has lots of examples.

over a distance of 5 miles

LoRa will work over such a range, given unobstructed line of sight.

Thanks for the advice I will give the radio hear a go

Tx

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .

Have you googled;

arduino lora example code

Thanks.. Tom.. :slight_smile:

kiwiwiki:
I need a system with one master and up to 10 slaves spread out over a distance of 5 miles.

After some studies have found that LORA probably best fits my requirements.

Whether LoRa is suitable, depends entirely on where the '5 miles' is;

Dakota salt flats ?
Urban area ?
Forest ?

And of course, where you are in the World.

For some background information on LoRa read here;

What is LoRa ?

Tx for comments.

All points are line of sight.

Open country with a few small trees.

Country is New Zealand.

Master unit will be inside a brick house.( could be outside if necessary)

Are the Duinotech shields reliable??

I cannot seem to find our much info on the pin outs.Can anyone help with this?

Hi, from across the Tasman.
Can you post a link to the Duinotech shields please.

Thanks.. Tom.. :slight_smile:

kiwiwiki:
Are the Duinotech shields reliable??
I cannot seem to find our much info on the pin outs.Can anyone help with this?

If the place you are considering buying them from cannot provide the pinnout information, then consider buying something else.

kiwiwiki:
Tx for comments.

All points are line of sight.

Open country with a few small trees.

Country is New Zealand.

Master unit will be inside a brick house.( could be outside if necessary)

Should be OK, but do realise that the distance capabilty of LoRa is dependant on the data rate.

At the highest data rate, 37500bps if you were to get 1km then at the lowest practical data rate of 300bps you would get 10km.

There are newer LoRa devices that make practical even lower data rates and would go 4 times further again.

Elevating the master unit antenna could make a significant difference to the range\datarates possible.

:slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile:

Thanks. Works great at 1 meter.

Had to change the Frequency in the Radio Head Library and

change the LED pin 6 to 13 in the server sketch and then it worked.

The example sketch transmits “letters and words” but I want to send “Numbers”

Can you tell me how to modify the attached sketch to use Numbers instead of Characters?

Thank you

// rf95_client.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing client
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
// reliability, so you should only use RH_RF95 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example rf95_server
// Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with
// the RFM95W, Adafruit Feather M0 with RFM95

#include <SPI.h>
#include <RH_RF95.h>

// Singleton instance of the radio driver
RH_RF95 rf95;
//RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W
//RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95 

// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)
//#define Serial SerialUSB

void setup() 
{
  // Rocket Scream Mini Ultra Pro with the RFM95W only:
  // Ensure serial flash is not interfering with radio communication on SPI bus
//  pinMode(4, OUTPUT);
//  digitalWrite(4, HIGH);

  Serial.begin(9600);
  while (!Serial) ; // Wait for serial port to be available
  if (!rf95.init())
    Serial.println("init failed");
  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 
  // you can set transmitter powers from 5 to 23 dBm:
//  driver.setTxPower(23, false);
  // If you are using Modtronix inAir4 or inAir9,or any other module which uses the
  // transmitter RFO pins and not the PA_BOOST pins
  // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true. 
  // Failure to do that will result in extremely low transmit powers.
//  driver.setTxPower(14, true);
}

void loop()
{
  Serial.println("Sending to rf95_server");
  // Send a message to rf95_server
  uint8_t data[] = "Hello World!";
  rf95.send(data, sizeof(data));
  
  rf95.waitPacketSent();
  // Now wait for a reply
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  if (rf95.waitAvailableTimeout(3000))
  { 
    // Should be a reply message for us now   
    if (rf95.recv(buf, &len))
   {
      Serial.print("got reply: ");
      Serial.println((char*)buf);
//      Serial.print("RSSI: ");
//      Serial.println(rf95.lastRssi(), DEC);    
    }
    else
    {
      Serial.println("recv failed");
    }
  }
  else
  {
    Serial.println("No reply, is rf95_server running?");
  }
  delay(400);
}

Check out the function signatures in RH_RF95.h:

virtual bool    send(const uint8_t* data, uint8_t len);
virtual bool    recv(uint8_t* buf, uint8_t* len);

You can send any type of data you want. Just pass in a pointer to it (cast as a 'uint8_t *' if required) and the length in bytes. Receiving is similar.

As the comments in the code you copied imply, you should check out the 'RHReliableDatagram' classes:

// Example sketch showing how to create a simple messageing client
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
// reliability, so you should only use RH_RF95 if you do not need the higher
// level messaging abilities.

Hi,
You might be better with this library;

Tom... :slight_smile:

Tx gfvalvo. But have no idea how to implement what you advise.

The "virtual bool send(const uint8_t* data, uint8_t len);" wont compile.

TomGeorge . Tx for your suggestion and it seems a much easier option.

The Sender side works fine but the receiving side is still receiving the

numbers as "Characters" and I dont know how to convert them back to the numbers which were sent.

I would really like to be able to express the number received as a "int Variable"

Eg. int aaaa = value of the data received.

Can you help here???

Tx

Hi,
Instead of sending

“Hello World!” what do you receive if you sent say “234” ?

Tom… :slight_smile:

Have attached "receiver" code.

Send the number 234 from sender.

Receive 2 then 3 then 4 which print out as the character (234)

What I need is a Integer so that I can divide or multiply the received number.

(eg 234 * 4 = 936 or Plus, Minus or Division

I did have a NRF24 working for a while and used the following code on the receiver:

/'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''"
while (radio.available())
{
radio.read( &datarec, sizeof(datarec));
}
digitalWrite (13,HIGH);
Serial.print (" RECEIVED ");Serial.print (datarec[0]); Serial.print (" and .. ");Serial.print (datarec[1]);
Serial.print (" and .. ");Serial.println (datarec[2]);"

/""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

This worked out just fine with the following definitions

/""""""""""""""""""""
int datarec[3];
int data1 = 0;
int data2 = 0;
int data3 = 0;
/"""""""""""""""""""""

This allowed me to transmit and receive 3 seperate Integers which is what I need from the

Lora receiver.

Hope this makes some sort of sense.

kiwiwiki:
I did have a NRF24 working for a while and used the following code on the receiver:.............
.
.
.
This allowed me to transmit and receive 3 seperate Integers which is what I need from the Lora receiver.

So, why can't you do the same thing with the LORA?

Because I dont know how to do it??

I have tried but because the commands are so different between

Lora and NRF24 I just cannot get it to work.

If I could get the Lora sketch to accept " int datasent[3] & int datarec [3]"

arrays I might be a step closer.

Hi,
Try this;

int number = atoi( input );

Where input is your char value.
I don't know if it works or not but worth a try.

I have written code with the Lora.h which I will have to dig up to see what I did in a peer to peer remote temperature system.

Tom.... :slight_smile:

kiwiwiki:
I have tried but because the commands are so different between
Lora and NRF24 I just cannot get it to work.

NO, They’re nearly identical!!! I tried to get you to look at function prototypes in my previous post. The prototype tells you the function’s arguments and return type. It's the first thing to check when learning how to use a new function. Look at them now for the ‘send()’ and ‘recv()’ functions of the RH_RF95 and RH_NRF24 classes in the RadioHead library:

virtual bool send(const uint8_t* data, uint8_t len);  // RF95
bool send(const uint8_t* data, uint8_t len);  // NRF24 

virtual bool recv(uint8_t* buf, uint8_t* len);  // RF95
bool recv(uint8_t* buf, uint8_t* len);  // NRF24

With the exception of the functions being designated virtual in the RF95 class (not important for this discussion), they are identical. So, within limits of the particular hardware, you use them the same way.

To send some data you simply supply a pointer to the data and the number of bytes to be sent. Two common ways to send data are with an array or a struct. The array allows you to send multiple values all of the same type. In C / C++, the name of an array can act as the pointer. So:

uint32_t dataToSend[5];
  
  radio.send((uint8_t *)dataToSend, sizeof(dataToSend));

A struct allows you to send values of different types. So:

struct DataStruct {
    uint8_t remoteID;
    char name[5];
    float temperature;
    uint16_t altitude; 
  };

  DataStruct dataToSend;
  
  radio.send((uint8_t *)&dataToSend, sizeof(dataToSend));

In the above, ‘radio’ is an instance of the appropriate class (RH_RF95, RH_NRF24).

Use of the ‘recv()’ function is also identical for the RH_RF95 and RH_NRF24 classes.