mLink 1ch (HCMODU00182), 2ch (HCMODU0183), And 4ch (HCMODU0184) I2C / Parallel Relay Modules

mLink serial I2C modules
andrew
Site Admin
Posts: 1481
Joined: Sun Aug 05, 2012 4:15 pm

Re: mLink 1ch (HCMODU00182), 2ch (HCMODU0183), And 4ch (HCMODU0184) I2C / Parallel Relay Modules

Post by andrew » Wed Feb 26, 2025 10:26 am

Great work and thank you for taking the time to support these products. I've now added the link for your github page to the first post of this thread and the RGBW thread.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

ChrisSharp
Posts: 38
Joined: Thu Dec 31, 2020 1:22 pm

Re: mLink 1ch (HCMODU00182), 2ch (HCMODU0183), And 4ch (HCMODU0184) I2C / Parallel Relay Modules

Post by ChrisSharp » Tue Mar 11, 2025 7:14 am

Hi Andrew

I'm glad I read through this thread and found these new features in the library. For me this is a much more convenient way of turning the relays on and off.

Depending on how I chose to code things the less than one second timer may also be useful. I am using them to control model railway points. These require a short pulse of power to throw them. 100ms should do nicely.

Have you considered adding these features to the Reference Guide for these modules. Or adding an Example sketch to the library?

Cheers
Chris

andrew wrote:
Thu Nov 28, 2024 5:04 pm
That would be perfect, thanks for the distillation!
Pun intended? :-)

So.....

I’ve had time to review the firmware and have now added the features discussed. Since the existing registers couldn't support the changes, I’ve introduced 6 new registers:

Register 19 (Relay On):
- Writing a value between 0 and 3 to this register turns on the corresponding relay.
- If the relay’s timer is already running, writing to this register will restart the timer.

Register 20 (Relay Off):
- Writing a value between 0 and 3 to this register turns off the corresponding relay.
- If the relay’s timer is running, writing to this register will cancel the timer and immediately turn off the relay.

Register 21 (Relay 0 Timer Resolution):
- Writing 0 sets the timer resolution for Relay 0 to 1 second (default).
- Writing 1 sets the resolution to 100ms.

Register 22 (Relay 1 Timer Resolution):
- Writing 0 sets the timer resolution for Relay 1 to 1 second (default).
- Writing 1 sets the resolution to 100ms.

Register 23 (Relay 2 Timer Resolution):
- Writing 0 sets the timer resolution for Relay 2 to 1 second (default).
- Writing 1 sets the resolution to 100ms.

Register 24 (Relay 3 Timer Resolution):
- Writing 0 sets the timer resolution for Relay 3 to 1 second (default).
- Writing 1 sets the resolution to 100ms.


Any mLink relay modules purchased after today will include this version of firmware (v1.01).

---

The upcoming version of the mLink library (v2.2.0) will include macros to use these features:

mLink.RLY_ON(add, index) //Turns the specified relay ON.

mLink.RLY_OFF(add, index) //Turns the specified relay OFF.

mLink.RLY0_TIMER_RES(add, res) //Sets the timer resolution for Relay 0.

mLink.RLY1_TIMER_RES(add, res) //Sets the timer resolution for Relay 1.

mLink.RLY2_TIMER_RES(add, res) // Sets the timer resolution for Relay 2.

mLink.RLY3_TIMER_RES(add, res) // Sets the timer resolution for Relay 3.


- Parameters:
- add: I2C address of the module.
- index: Relay index (0 to 3).
- res: Timer resolution (0 = 1 second (default), 1 = 100ms).

---

I need to add a new servo controller to the library before I upload the updated version (V2.2.0) so I’m unsure when it will be available for download. However, I’m aiming for sometime next week or failing that, the following week.

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

Re: mLink 1ch (HCMODU00182), 2ch (HCMODU0183), And 4ch (HCMODU0184) I2C / Parallel Relay Modules

Post by andrew » Tue Mar 11, 2025 9:32 am

Have you considered adding these features to the Reference Guide for these modules? Or adding an Example sketch to the library?
Hi Chris, yep, it’s on the list but thanks for reminding me. Just got a new sensor module to get out of the way first. The currently uploaded library does support these new features though so the new commands as quoted in your post will work.


Depending on how I chose to code things the less than one second timer may also be useful. I am using them to control model railway points. These require a short pulse of power to throw them. 100ms should do nicely.
I must say that at the time of creating the original module it did not occur to me that a sub 1 second timer would be useful but I’m clearly wrong! Anyway thanks for the feedback on this.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

lewsut
Posts: 16
Joined: Tue Jan 09, 2024 9:08 pm

Re: mLink 1ch (HCMODU00182), 2ch (HCMODU0183), And 4ch (HCMODU0184) I2C / Parallel Relay Modules

Post by lewsut » Mon Mar 17, 2025 1:54 pm

I'm glad this stuff is useful to others and it's not just my weird requirements :)

My testing has gone well and everything works as expected! Thanks.

ChrisSharp
Posts: 38
Joined: Thu Dec 31, 2020 1:22 pm

Re: mLink 1ch (HCMODU00182), 2ch (HCMODU0183), And 4ch (HCMODU0184) I2C / Parallel Relay Modules

Post by ChrisSharp » Thu Mar 20, 2025 2:00 pm

Somewhat frustrated that I purchased one of my relay models in mid November, just prior to this firmware update. I've found it much easier to code with the new features.

proxymowdev
Posts: 4
Joined: Wed Apr 23, 2025 9:41 am

Re: 2ch (HCMODU0183) Parallel Relay Modules

Post by proxymowdev » Wed Apr 23, 2025 10:10 am

I have a couple of the 2ch mlink relay modules and they where both working fine. I use them to switch the cutter motors in my ESP8266 robotic lawn mowers. They are an excellent fit for this because unlike directly connected relays they don't flicker when the device is started or restarted. They are driven by simple Micro-Python code and both relays have been working fine since I purchased them from Hobby Components in September 2024. However, one has developed a fault. Each relay can still be turned on, but neither will turn off without killing the power. It is definitely a problem with the module because I swapped my two over, and the other one is working fine. Has anyone come across any similar issues.

Regards

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

Re: mLink 1ch (HCMODU00182), 2ch (HCMODU0183), And 4ch (HCMODU0184) I2C / Parallel Relay Modules

Post by andrew » Wed Apr 23, 2025 1:55 pm

Each relay can still be turned on, but neither will turn off without killing the power. It is definitely a problem with the module because I swapped my two over, and the other one is working fine. Has anyone come across any similar issues.

I can’t explain why you would be able to turn the relay on via software but not off. That’s a weird issue. But a couple of things to check:

Firstly, if you have a multimeter can you check the 5V supply to the relay, just in case it's a bit low. It could be that one module is more tolerant.

Secondly, if it’s also convenient to do, do the relays switch ok if you control them from the header pins?
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Mark M
Posts: 2
Joined: Sun May 04, 2025 3:58 am

Re: 2ch (HCMODU0183) Parallel Relay Modules

Post by Mark M » Sun May 04, 2025 4:09 am

proxymowdev wrote:
Wed Apr 23, 2025 10:10 am
I have a couple of the 2ch mlink relay modules and they where both working fine. I use them to switch the cutter motors in my ESP8266 robotic lawn mowers. They are an excellent fit for this because unlike directly connected relays they don't flicker when the device is started or restarted. They are driven by simple Micro-Python code and both relays have been working fine since I purchased them from Hobby Components in September 2024. However, one has developed a fault. Each relay can still be turned on, but neither will turn off without killing the power. It is definitely a problem with the module because I swapped my two over, and the other one is working fine. Has anyone come across any similar issues.

Regards
i have the similar issue, i can turn on the relay but have issues trying to turn off:
*using i2c via Rpi Gpio

script:
#!/bin/sh

from mLink import mLink # Import the mLink module
ml = mLink.mLink(1) # Create an instance using the Pis I2C port 1

ml.Relay0_off(0x52) # Turns relay 0 off

When script is run:
mdm1981@raspberrypi:~/klipper/scripts $ python mLink_Relay0_off.sh
Traceback (most recent call last):
File "/home/mdm1981/klipper/scripts/mLink_Relay0_off.sh", line 6, in <module>
mLink.Relay0_off(0x52) # Turns relay 0 off
AttributeError: module 'mLink.mLink' has no attribute 'Relay0_off'

Script used to turn on relay is same(with on/off variable changed) and works fine.
relay tested on GPIO works fine

any help would be much appreciated.
Mark
Last edited by Mark M on Mon May 05, 2025 7:09 am, edited 2 times in total.

proxymowdev
Posts: 4
Joined: Wed Apr 23, 2025 9:41 am

Re: mLink 1ch (HCMODU00182), 2ch (HCMODU0183), And 4ch (HCMODU0184) I2C / Parallel Relay Modules

Post by proxymowdev » Sun May 04, 2025 8:14 am

Firstly, if you have a multimeter can you check the 5V supply to the relay, just in case it's a bit low. It could be that one module is more tolerant.

Secondly, if it’s also convenient to do, do the relays switch ok if you control them from the header pins?
I have checked the supply and it is healthy, and I can reproduce the same results using the header pins. I am curious about the reset/clear function pins. I remember reading about it somewhere, but can't find the reference now. It implies there is some configuration in nv memory that can be reset? Is this worth trying?

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

Re: mLink 1ch (HCMODU00182), 2ch (HCMODU0183), And 4ch (HCMODU0184) I2C / Parallel Relay Modules

Post by andrew » Mon May 05, 2025 7:17 am

@Mark M
i have the similar issue, i can turn on the relay but have issues trying to turn off:
*using i2c via Rpi Gpio

script:
#!/bin/sh

from mLink import mLink # Import the mLink module
ml = mLink.mLink(1) # Create an instance using the Pis I2C port 1

ml.Relay0_off(0x52) # Turns relay 0 off

When script is run:
mdm1981@raspberrypi:~/klipper/scripts $ python mLink_Relay0_off.sh
Traceback (most recent call last):
File "/home/mdm1981/klipper/scripts/mLink_Relay0_off.sh", line 6, in <module>
mLink.Relay0_off(0x52) # Turns relay 0 off
AttributeError: module 'mLink.mLink' has no attribute 'Relay0_off'

Script used to turn on relay is same(with on/off variable changed) and works fine.


The error message seems to suggest a problem with the script. I don’t know why it is complaining about Relay1_off when your script is using Relay0_off. Maybe you have a reference to Relay1_off in your script somewhere. However i do see a problem:


You're creating an instance of the mLink library and assigning it to the name ‘ml’.

  1. ml = mLink.mLink(1) # Create an instance using the Pis I2C port 1

However in the error message i can see it is referencing it as ‘mlink’.

  1. mLink.Relay0_off(0x52) # Turns relay 0 off

The above line needs to be:

  1. ml.Relay0_off(0x52) # Turns relay 0 off


If you run the example script in the first post of this thread does it work ok?

  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 = 0x52                              # Default I2C address is 0x52
  7.  
  8.  
  9. while 1:
  10.     ml.Relay0_On(I2C_ADD)                   # Turn relay 0 on
  11.     time.sleep(1)
  12.     ml.Relay0_Off(I2C_ADD)                  # Trun relay 0 off
  13.     time.sleep(1)
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “mLink”