LongReach (LoRa) mLink Module (HCMODU0250)

mLink serial I2C modules
admin
Site Admin
Posts: 884
Joined: Sun Aug 05, 2012 4:02 pm

LongReach (LoRa) mLink Module (HCMODU0250)

Post by admin » Fri Sep 06, 2024 9:41 am

Image

Image

The LongReach mLink module is a LoRa-based wireless device that connects to most microcontrollers using a serial mLink (I2C) interface. Once connected, it enables your microcontroller to communicate with other devices through its built-in RM95 LoRa radio transceiver. By using two or more modules, you can establish wireless communication between multiple microcontrollers over far greater distances than technologies like WiFi or Bluetooth.




Image


The module is also compatible with other LongReach modules such as the LongReach USB module for communication from a microcontroller to a computer, or remote sensing and control using the LongReach 4CH Relay module or Tx module, etc.


Image



mLink I2C interface
As the module incorporates the mLink I2C interface it is also compatible with our range of mLink modules meaning it can be daisy-chained with other mLink modules such as LCD displays, keypads, sensors, relays etc., all via a single I2C interface and only requiring one compact library to be installed.

For Arduino and Raspberry Pi users we have a dedicated library and Python module which makes transmitting data and sensor readings via your sketches or python scripts as simple as possible (see below for examples and library links).


Specification:
[pre]Product code: HCMODU0250
Supply voltage: 5V via mLink interface
Supply current: 2mA (sleep), 19mA (Rx), 150mA (Tx)
Radio type: LoRa RM95
Range: >1 kilometre in free air
Frequency: 868 to 915MHz
Max packet size: 256 bytes
Max bitrate (nominal): 9380bps (at -118dBm sensitivity)
Interface: 4 pin male mLink 0.1” headerI2C
Interface speed: 400kbits/s (fast mode)
I2C default address (HEX): 0h5F
Maximum number of modules: 5 with pullups fitted, 112 with pullups removed**
Dimensions (ex antenna): 42mm x 22mm x 5mm[/pre]

*Note the maximum number of connected modules will depend on cable lengths and power requirements of each module. Do not exceed 5 mLink modules connected in series with I2C pullups fitted to all modules. For disconnecting pullups see forum post.




Image


Image



Send example

Send some example text:

This sketch uses the mLink library to send some example text to a remote module.


  1. #include "mLink.h"                                    // Include the library
  2.  
  3.  
  4. mLink mLink;                                          // Create an instance of the library
  5.  
  6.  
  7. #define I2C_ADD 0x5F                                  // Default I2C address
  8.  
  9.  
  10. char data[] = "Hello!";                               // Some example data to send
  11.  
  12.  
  13. void setup()
  14. {
  15.   mLink.init();                                       // Initialise the library
  16. }
  17.  
  18.  
  19.  
  20. void loop()
  21. {
  22.   mLink.LORA_Tx_Load(I2C_ADD, sizeof(data), data);    // Load the data into the Tx buffer
  23.  
  24.  
  25.   mLink.LORA_Tx_Send(I2C_ADD);                        // Send it
  26.  
  27.  
  28.   while(mLink.LORA_Tx_Busy(I2C_ADD));                 // Wait for module to finish transmitting
  29.  
  30.  
  31.   delay(2000);                                        // Wait a little before sending again
  32. }

Receive example

Receive some data example:

This sketch uses the mLink library to display a value representing the Arduino 'up time'
  1. #include "mLink.h"                                    // Include the library
  2.  
  3.  
  4. mLink mLink;                                          // Create an instance of the library
  5.  
  6.  
  7. #define I2C_ADD 0x5F                                  // Default I2C address
  8.  
  9.  
  10. byte rxBuffer[255];                                   // Buffer to hold Rx data (max 255 bytes)
  11.  
  12.  
  13.  
  14. void setup()
  15. {
  16.   Serial.begin(9600);
  17.  
  18.   mLink.init();                                       // Initialise the library
  19.  
  20.  
  21.   mLink.LORA_Mode(I2C_ADD, LORA_MODE_RXCONTINUOUS);   // Put the module into continuous receive mode
  22. }
  23.  
  24.  
  25.  
  26. void loop()
  27. {
  28.   byte avail = mLink.LORA_Rx_Available(I2C_ADD);      // Check for new data
  29.  
  30.  
  31.   if(avail == 1)                                          
  32.   {
  33.     byte size = mLink.LORA_Rx_Size(I2C_ADD);          // Get the length of the data in bytes
  34.  
  35.  
  36.     mLink.LORA_Rx_Read(I2C_ADD, size, rxBuffer);      // Read the data into the buffer
  37.  
  38.  
  39.     int rssi = mLink.LORA_RSSI(I2C_ADD);              // Get the signal strength (RSSI)
  40.  
  41.  
  42.     Serial.print("Size = "); Serial.println(size);    // Print out the details
  43.     Serial.print("RSSI = "); Serial.println(rssi);
  44.  
  45.  
  46.     Serial.print("Data = ");                          // Print out the data in hex
  47.     for(byte i = 0; i < size; i++)
  48.     {
  49.       Serial.print(rxBuffer[i], HEX);
  50.       Serial.print(":");
  51.     }
  52.  
  53.  
  54.     Serial.println(); Serial.println();
  55.   }
  56. }

LongReach transmit example

Transmit some data example:
This sketch demonstrates how to use the mLink RM95 LoRa module
to transmit commands to LongReach modules such at the LongReach
4CH relay module (HCMODU0249).

Please see Licence.txt in the library folder for terms of use.
  1. #include "mLink.h"                            // Include the library
  2.  
  3. mLink mLink;                                  // Create an instance of the library
  4.  
  5. #define I2C_ADD 0x5F                          // Default I2C address
  6.  
  7. char switchON[] = "SW0=1";                    // Example LongReach command to turn switch 0 on
  8. char switchOFF[] = "SW0=0";                   // Example LongReach command to turn switch 0 off
  9.  
  10.  
  11. void setup()
  12. {
  13.   mLink.init();                               // Initialise the library
  14.  
  15.   mLink.LORA_LR_Mode(I2C_ADD, LR_MODE_ON);    // Turn on LongReach mode (LR_MODE_OFF to turn off)
  16. }
  17.  
  18.  
  19. void loop()
  20. {
  21.   mLink.LORA_Tx_Load(I2C_ADD, 5, switchON);   // Load the Tx buffer with the on command
  22.   mLink.LORA_Tx_LR_Send(I2C_ADD, 0);          // Send to LongReach module(s) with address 0
  23.   while(mLink.LORA_Tx_Busy(I2C_ADD));         // Wait for module to finish transmitting
  24.   delay(2000);
  25.  
  26.   mLink.LORA_Tx_Load(I2C_ADD, 5, switchOFF);  // Load the Tx buffer with the off command
  27.   mLink.LORA_Tx_LR_Send(I2C_ADD, 0);          // Send it LongReach module(s) with address 0
  28.   while(mLink.LORA_Tx_Busy(I2C_ADD));         // Wait for module to finish transmitting
  29.   delay(2000);
  30. }

LongReach receive example

Receive some data example:
This sketch demonstrates how to use the mLink RM95 LoRa module
to receive LongReach data packets sent by other Hobby Components
LongReach modules.

Please see Licence.txt in the library folder for terms of use.

  1. #include "mLink.h"                                    // Include the library
  2.  
  3. mLink mLink;                                          // Create an instance of the library
  4.  
  5. #define I2C_ADD 0x5F                                  // Default I2C address
  6.  
  7. char rxBuffer[32];                                    // Buffer to hold Rx data (max 32 bytes)
  8.  
  9.  
  10. void setup()
  11. {
  12.   Serial.begin(9600);
  13.  
  14.   mLink.init();                                       // Initialise the library
  15.  
  16.   mLink.LORA_LR_Mode(I2C_ADD, LR_MODE_ON);            // Put the module into LongReach mode
  17.                                                       // Module will now receive data from other LongReach devices
  18.  
  19.   mLink.LORA_Mode(I2C_ADD, LORA_MODE_RXCONTINUOUS);   // Put the module into continuous receive mode
  20. }
  21.  
  22.  
  23. void loop()
  24. {
  25.   boolean avail = mLink.LORA_Rx_Available(I2C_ADD);      // Check for new data
  26.  
  27.   if(avail)                                          
  28.   {
  29.     byte size = mLink.LORA_Rx_Size(I2C_ADD);          // Get the length of the data in bytes
  30.  
  31.     if(size > 32)                                     // Make sure data does not exceed buffer size
  32.       size = 32;
  33.  
  34.     mLink.LORA_Rx_Read(I2C_ADD, size, rxBuffer);      // Read the data into the buffer
  35.  
  36.     int16_t rssi = mLink.LORA_RSSI(I2C_ADD);          // Get the signal strength (RSSI)
  37.  
  38.     byte address = mLink.LORA_Rx_Address(I2C_ADD);    // Get the address of the module that sent the data
  39.  
  40.     Serial.print("Size = "); Serial.println(size);    // Print out the details
  41.     Serial.print("RSSI = "); Serial.println(rssi);
  42.     Serial.print("Address = "); Serial.println(address);
  43.  
  44.     Serial.print("Data = ");                          // Print out the data as ASCII
  45.     for(byte i = 0; i < size; i++)
  46.     {
  47.       Serial.print(rxBuffer[i]);
  48.     }
  49.    
  50.     Serial.println(); Serial.println();
  51.   }
  52. }






Image


Image


When connecting to a Raspberry Pi the mLink modules I2C pullup resistors should be removed. See the 'Removing the modules I2C pullup resistors' section below for more information.

Send example

mLink LoRa transmit data example:

This example demonstrates how to transmit raw data to a remote module
Use this script in conjunction with the mLink LoRa receive example.

To use this script you will need to have the mLink module installed.
Please see library forum thread for more information

  1. from mLink import mLink                             # Import the mLink module
  2. import time
  3.  
  4. ml = mLink.mLink(1)                                 # Create an instance of the module
  5.  
  6. I2C_ADD = 0x5F                                      # Default I2C address is 0x5F
  7.  
  8.  
  9. data = ['H','E','L','L','O','!']                    # Create a list of data to send
  10.  
  11.  
  12. while 1:
  13.     ml.LORA_Tx_Load(I2C_ADD, data, len(data))       # Load the Tx buffer
  14.  
  15.     ml.LORA_Tx_Send(I2C_ADD, 0)                     # Send the data
  16.  
  17.     while (ml.LORA_Tx_Busy(I2C_ADD)):               # Wait for data to be transmitted
  18.         continue
  19.  
  20.     time.sleep(10)                                  # Wait a little before sending again

Receive example

mLink LoRa receive data example:

This example demonstrates how to receive raw data from a remote module.
Use this script in conjunction with the mLink LoRa transmit example.

To use this script you will need to have the mLink module installed.
Please see library forum thread for more information

  1. from mLink import mLink                             # Import the mLink module
  2. import time
  3.  
  4. ml = mLink.mLink(1)                                 # Create an instance of the module
  5.  
  6. I2C_ADD = 0x5F                                      # Default I2C address is 0x5F
  7.  
  8.  
  9. ml.LORA_Mode(I2C_ADD, ml.LORA_MODE_RXCONTINUOUS)    # Put module into continuous receive mode
  10.  
  11.  
  12. while 1:
  13.     avail = ml.LORA_Rx_Available(I2C_ADD)           # Check for new data
  14.    
  15.     if avail:
  16.         size = ml.LORA_Rx_Size(I2C_ADD)             # Get the size in bytes of the new data
  17.         rssi = ml.LORA_RSSI(I2C_ADD)
  18.         data = ml.LORA_Rx_Read(I2C_ADD, size)       # Read out the data
  19.         print("Size = ", size)                      # Print out the size in bytes
  20.         print("RSSI = ", rssi)                      # Print out the size in bytes
  21.         print(data)                                 # Print out the raw data
  22.         print(''.join(map(chr, data)))              # Print out the data as an ASCII string
  23.        
  24.     time.sleep(1)
  25.  

LongReach send example

mLink LongReach transmit data example:

This example demonstrates how to transmit a command to a LongReach
module. The script will turn relay 0 on a LongReach relay module
(see SKU: HCMODU0249) on and off every 2 seconds suing the SW0=x
command.

If you have 2 mLink modules you can also use this script in
conjunction with the mLink LongReach receive example to send LongReach
commands from one Pi to another.

To use this script you will need to have the mLink module installed.
Please see library forum thread for more information

  1. from mLink import mLink                         # Import the mLink module
  2. import time
  3.  
  4. ml = mLink.mLink(1)                             # Create an instance of the module
  5.  
  6. I2C_ADD = 0x5F                                  # Default I2C address is 0x5F
  7.  
  8. relay0_On = "SW0=1"                             # Relay 0 ON command
  9. relay0_Off = "SW0=0"                            # Relay 0 OFF command
  10. LR_Dest_Add = 0                                 # Dest LongReach device address
  11.  
  12. ml.LORA_LR_Mode(I2C_ADD, ml.LR_MODE_ON)         # Put the module into LongReach mode
  13.  
  14.  
  15. while 1:
  16.     ml.LORA_Tx_Load(I2C_ADD, 5, relay0_On)      # Load the Tx buffer with the on command
  17.     ml.LORA_Tx_LR_Send(I2C_ADD, LR_Dest_Add)    # Send the command
  18.     while (ml.LORA_Tx_Busy(I2C_ADD)):           # Wait for data to be transmitted
  19.         continue
  20.  
  21.     time.sleep(2)  
  22.    
  23.     ml.LORA_Tx_Load(I2C_ADD, 5, relay0_Off)     # Load the Tx buffer with the off command
  24.     ml.LORA_Tx_LR_Send(I2C_ADD, LR_Dest_Add)    # Send the command
  25.     while (ml.LORA_Tx_Busy(I2C_ADD)):           # Wait for data to be transmitted
  26.         continue
  27.  
  28.     time.sleep(2)

LongReach receive example

mLink LongReach receive data example:

This example demonstrates how to receive a command from a LongReach
module (e.g. digital Tx module SKU: HCMODU0248).

If you have 2 mLink modules you can also use this script in
conjunction with the mLink LongReach send example to send LongReach
commands from one Pi to another.

To use this script you will need to have the mLink module installed.
Please see library forum thread for more information:

  1. from mLink import mLink                             # Import the mLink module
  2. import time
  3.  
  4. ml = mLink.mLink(1)                                 # Create an instance of the module
  5.  
  6. I2C_ADD = 0x5F                                      # Default I2C address is 0x5F
  7.  
  8.  
  9.  
  10. ml.LORA_LR_Mode(I2C_ADD, ml.LR_MODE_ON)             # Put the module into LongReach mode
  11. ml.LORA_Mode(I2C_ADD, ml.LORA_MODE_RXCONTINUOUS)    # Put module into continuous receive mode
  12.  
  13.  
  14. while 1:
  15.     avail = ml.LORA_Rx_Available(I2C_ADD)           # Check for new data
  16.    
  17.     if avail:
  18.         size = ml.LORA_Rx_Size(I2C_ADD)             # Get the size in bytes of the new data
  19.         rssi = ml.LORA_RSSI(I2C_ADD)                # Get the RSSI level
  20.         add = ml.LORA_Rx_Address(I2C_ADD)           # Get the LongReach destination address
  21.         data = ml.LORA_Rx_Read(I2C_ADD, size)       # Read out the command
  22.  
  23.         print("Address=", add)                      # Print out the address
  24.         print("Size=", size)                        # Print out the size in bytes
  25.         print("RSSI=", rssi)                        # Print out the RSSI level
  26.         print("Raw data=", data)                    # Print out the command as raw data
  27.         print("Command=", ''.join(map(chr, data)))  # Print out the command as ASCII
  28.        
  29.     time.sleep(1)


Image


Dimensions:


Image


Removing I2C pullups:


Image

If your development board already has pullups for its I2C interface fitted, or you wish to connect more than 5 mLink boards to the same I2C interface, then you can remove the pullups for the additional boards by cutting the tracks between the solder pads shown below.



Image


mLink Arduino library

viewtopic.php?f=58&t=3001

Please note that you will need at least V2.2.0 (09 Sep 2024) of the library to support this module. If you have an older version already installed please update it to the latest version.


mLink Raspberry Pi Python module
The mLink python module can be installed with the following terminal command:

  1. pip install hc-mlink

Alternatively the library can be manually installed by downloading it from the forum and unzipping it to your project folder. See the Python module forum thread for more information and download link:
viewtopic.php?f=131&t=3062&p=8592#p8592

Please note that in some cases there may be additional configuration required. If you have issues getting your Raspberry Pi to communicate with the mLink module then please see the Python module forum thread here: viewtopic.php?f=131&t=3062


mLink Specifications and Register Map

https://hobbycomponents.com/downloads/m ... V1_0_2.pdf





Libraries, example code, and diagrams are provided as an additional free service by Hobby Components and are not sold as part of this product. We do not provide any guarantees or warranties as to their accuracy or fitness for purpose.

RogerL
Posts: 35
Joined: Mon Apr 14, 2014 7:56 pm

Re: LongReach (LoRa) mLink Module (HCMODU0250)

Post by RogerL » Fri Jan 31, 2025 3:15 pm

Hi. I am considering these modules for a project I am just starting that requires 2 tranceivers in 2 separate buildings. The distance isn't great, but there are walls in the way. If I find I need to upgrade the pigtails to either stick aerials or a more elaborate antenna, do you have any ideas on how best to establish the connection to the board? I notice that there are pads either side of the pigtail. Is this to allow the fitment of a 4-legged RP-SMA connector or similar?

andrew
Site Admin
Posts: 1477
Joined: Sun Aug 05, 2012 4:15 pm

Re: LongReach (LoRa) mLink Module (HCMODU0250)

Post by andrew » Fri Jan 31, 2025 3:54 pm

The distance isn't great, but there are walls in the way.
If it's not far then I don't think it will be an issue. I myself have tested them though a building and they still manage to maintain a decent range with the stock antennas.

If I find I need to upgrade the pigtails to either stick aerials or a more elaborate antenna, do you have any ideas on how best to establish the connection to the board? I notice that there are pads either side of the pigtail. Is this to allow the fitment of a 4-legged RP-SMA connector or similar?
Yep, on the mLink modules the pads are suitable for an end-launch SMA connector. Which coincidentally, we are hoping to get on sale sometime next week.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

RogerL
Posts: 35
Joined: Mon Apr 14, 2014 7:56 pm

Re: LongReach (LoRa) mLink Module (HCMODU0250)

Post by RogerL » Fri Jan 31, 2025 6:48 pm

That's great Andrew. Thanks for getting back to me so quickly.

JohnF
Posts: 9
Joined: Thu May 15, 2025 11:20 am

Re: LongReach (LoRa) mLink Module (HCMODU0250)

Post by JohnF » Fri May 16, 2025 11:46 am

Andrew

I have several of the mLink LoRa modules which I want to use to make a wireless link between different control stations on a model railway, so the distances are not large.

I have a setup on my bench where I have one LoRa connected to a Raspberry Pi 4 and using another two attached to Arduino Uno variants, including one of the Hobby Link OPEN SMART items. I am using one of these for transmitting and one for receiving. I am using the LR mode and setting an address.

I am having a lot of difficulty getting these to work. I have had some success sending from the RPi 4 and none at all from one Arduino to the other.

Is there any way to check whether an mLink LoRa is working?

I think that the function LORA_Tx_Done returns 1 when transmit is working and 0 when done, Some of the examples seem to assume the opposite.

I am now using V1.0.2 of the Longreach guide. I was at first using 1.0.0 and assumed it was correct and the codes were wrong.

Is there any guidance on what can be expected of these items? Have I got them too close together?

Any help will be much appreciated.

John

andrew
Site Admin
Posts: 1477
Joined: Sun Aug 05, 2012 4:15 pm

Re: LongReach (LoRa) mLink Module (HCMODU0250)

Post by andrew » Fri May 16, 2025 1:40 pm

Hi John,
I am having a lot of difficulty getting these to work. I have had some success sending from the RPi 4 and none at all from one Arduino to the other.

Is there any way to check whether an mLink LoRa is working?

If it’s convenient to do, the easiest way to test them is to run the mLink_LongReach_Transmit_Example & mLink_LongReach_Receive_Example examples sketches on your Arduinos. If it works and one transmits to the other you can then try swapping the modules or the sketches to test transmitting in the other direction.

Edit: Additionally, whilst doing the above, you could also run the Longreach receive example python script on your Pi to confirm that each Arduino is transmitting.

I think that the function LORA_Tx_Done returns 1 when transmit is working and 0 when done, Some of the examples seem to assume the opposite.
The LORA_Tx_Done function should return true (1) if transmission is complete and false (0) if still transmitting.

Edit: My apologies, I've just checked the function and it is the opposite as you report, the function will return false when done, and true whilst transmitting. This is a bug and to resolve it the library function may have to be changed to LORA_Tx_Busy() in the next library revision. Thanks again for spotting this.

Is there any guidance on what can be expected of these items? Have I got them too close together?
I regularly use/test them on my desk near each other so having them close together shouldn’t be a problem.


If you’re able to run the suggested examples on your Arduino boards we can take it from there.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

JohnF
Posts: 9
Joined: Thu May 15, 2025 11:20 am

Re: LongReach (LoRa) mLink Module (HCMODU0250)

Post by JohnF » Fri May 16, 2025 9:28 pm

Andrew

Thank you for all this information. I will work my way through it.

I suggest retaining LORA_Tx_Done with the correct meaning as deleting it would break user code.

Thanks again

John
Last edited by JohnF on Sat May 17, 2025 10:02 am, edited 1 time in total.

JohnF
Posts: 9
Joined: Thu May 15, 2025 11:20 am

Re: LongReach (LoRa) mLink Module (HCMODU0250)

Post by JohnF » Sat May 17, 2025 9:54 am

Andrew

You refer to a Python example script. I have not found any. Is there another download somewhere?

John

andrew
Site Admin
Posts: 1477
Joined: Sun Aug 05, 2012 4:15 pm

Re: LongReach (LoRa) mLink Module (HCMODU0250)

Post by andrew » Sat May 17, 2025 10:03 am

They're in the first post of this thread under the raspberry pi section of the post. If you using LongReach mode then you can use the 'mLink LongReach receive example' to monitor the transmissions from your Arduinos.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

JohnF
Posts: 9
Joined: Thu May 15, 2025 11:20 am

Re: LongReach (LoRa) mLink Module (HCMODU0250)

Post by JohnF » Sat May 17, 2025 10:29 am

Andrew

Thank you. I had missed the tabs on the examples and only seen the first one.

John

Post Reply

Return to “mLink”