B4R Library rRadioHead - RF95 / Dragino Lora shield

SS-2017-12-03_14.48.44.jpg


This is a wrapper for RadioHead library. Currently only RF95 is exposed.
RadioHead documentation: http://www.airspayce.com/mikem/arduino/RadioHead/classRH__RF95.html#details

"Driver to send and receive unaddressed, unreliable datagrams via a LoRa capable radio transceiver."

Installation steps:
1. Download the attached library and copy to the additional libraries folder.
2. Download RadioHead and copy it to Arduino libraries folder (by default it is Documents\Arduino\libraries).

SS-2017-12-03_15.00.16.png


Usage:

1. Initialize RF95 and make sure that it returns True.
2. Set the frequency.
2. Send messages with RF95.Send.
3. Handle the DataAvailable event.

Max message length is 251 bytes.

Example:

Program A:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private rf95 As RF95
   Private ser As B4RSerializator
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   If rf95.Initialize("rf95_DataAvailable") = False Then
     Log("Failed to init!!!")
     Return
   End If
   rf95.Frequency = 868.1
End Sub

Sub rf95_DataAvailable (Data() As Byte)
   Dim objects(5) As Object
   Dim res() As Object = ser.ConvertBytesToArray(Data, objects)
   If res.Length > 0 Then
     Log("Message received from: ", res(0))
     Dim time As ULong = res(1)
     Log("Message time: ", time)
     rf95.Send(ser.ConvertArrayToBytes(Array("Mega - Thank you!", Millis)))
   End If
End Sub

Program B:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private rf95 As RF95
   Private timer1 As Timer
   Private ser As B4RSerializator
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   If rf95.Initialize("rf95_DataAvailable") = False Then
     Log("Failed to init!!!")
     Return
   End If
   rf95.Frequency = 868.1
   timer1.Initialize("timer1_Tick", 1000)
   timer1.Enabled = True
End Sub

Sub Timer1_Tick
   Dim b() As Byte = ser.ConvertArrayToBytes(Array("Arduino Uno", Millis))
   If rf95.Send(b) = False Then
     Log("Failed to send message")
   End If
End Sub

Sub rf95_DataAvailable (Data() As Byte)
   Dim objects(5) As Object
   Dim res() As Object = ser.ConvertBytesToArray(Data, objects)
   If res.Length > 0 Then
     Log("Message received from: ", res(0))
     Dim time As ULong = res(1)
     Log("Message time: ", time)
   End If
End Sub

Examples depend on rRadioHead and rRandomAccessFile libraries.
 

Attachments

  • rRadioHead.zip
    2.3 KB · Views: 750

janderkan

Well-Known Member
Licensed User
Longtime User
I create a new project.
I include rRadiohead library, but do not use it.
It compiles fine on a UNO or a Mega.
When I select a Wemos R1 D1 Mini I get this error.

B4X:
C:\2Work\1C\B4R\RADIOH~1\Objects\bin\sketch\rRadioHead.cpp: In member function 'bool B4R::B4RRF95::Send(B4R::Array*)':
rRadioHead.cpp:22: error: invalid conversion from 'void*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]
   return rf95->send(Data->data, Data->length);
                                             ^
In file included from C:\2Work\1C\B4R\RADIOH~1\Objects\bin\sketch\rRadioHead.h:5:0,
                 from C:\2Work\1C\B4R\RADIOH~1\Objects\bin\sketch\B4RDefines.h:25,
                 from C:\2Work\1C\B4R\RADIOH~1\Objects\bin\sketch\rRadioHead.cpp:1:
C:\Program Files (x86)\Arduino\libraries\RadioHead/RH_RF95.h:672:21: error:   initializing argument 1 of 'virtual bool RH_RF95::send(const uint8_t*, uint8_t)' [-fpermissive]
     virtual bool    send(const uint8_t* data, uint8_t len);
                     ^
exit status 1
 

janderkan

Well-Known Member
Licensed User
Longtime User
Try to change line 22 in rRadioHead.cpp to:
B4X:
return rf95->send((Byte*)Data->data, Data->length);

With this fix I'm still getting an error:
C:\Users\H\Documents\Arduino\libraries\RadioHead\RH_ASK.cpp:44:1: error: when initialized here [-Werror=reorder]

Now I can compile both RF95 and ASK on the Wemos. Need a little more time to know if it is also working :)
I find i very hard to C.

UPDATE: It works.
 
Last edited:

janderkan

Well-Known Member
Licensed User
Longtime User
Here are my additions to rRadioHead library.
Most of the functions are exposed and constants added to make it easier to use.
Radiohead protocol prefixes the datagram with 4 bytes to make it possible to send addressable, reliable packets.
Added properties to access these 4 bytes.

Exposed the ASK class that makes it possible to send and receive data the same way as the RF95 class.
Using very cheap ASK modules instead of the Lora modules.
433-chip.jpg
 

Attachments

  • rRadioHead_2_01.zip
    9.6 KB · Views: 580
  • rRadioHead_ASK_Demo.zip
    1.1 KB · Views: 559
Hi.
I copied RadioHead V1.97 in Arduino Library .
I use "rRadioHead_2_01" and i select Pro or Pro Mini , I get this error :
B4X:
B4R Version: 3.00
Parsing code.    (0.02s)
Building folders structure.    (0.01s)
Compiling code.    (0.05s)
Building project    (0.31s)
Compiling & deploying Ino project (Arduino Pro or Pro Mini - COM7)    Error
Loading configuration...
Initializing packages...
Preparing boards...
Verifying...
rRadioHead.cpp:4: error: prototype for 'bool B4R::B4RRF95::Initialize(B4R::SubVoidByteArray)' does not match any in class 'B4R::B4RRF95'
  bool B4RRF95::Initialize(SubVoidByteArray DataAvailableSub) {
       ^
In file included from D:\B4R-PR~1\ESP826~1\Test_pro\LoRa\V1\Objects\bin\sketch\B4RDefines.h:25:0,
                 from D:\B4R-PR~1\ESP826~1\Test_pro\LoRa\V1\Objects\bin\sketch\rRadioHead.cpp:1:
rRadioHead.h:156: error: candidate is: bool B4R::B4RRF95::Initialize(B4R::SubVoidByteArray, byte)
    bool Initialize(SubVoidByteArray DataAvailableSub, byte ThisAddress);
         ^
exit status 1
Please help me .
 
Top