mLink 12Bit I2C Digital Port Expander (HCMODU0180)

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

mLink 12Bit I2C Digital Port Expander (HCMODU0180)

Post by admin » Mon Sep 27, 2021 9:40 am

Image



The mLink port expander is a serial (I2C/IIC) digital I/O module. It allows you to add 12 digital input output pins per module to your existing microcontroller/Arduino using only its I2C interface. It is compatible with other mLink or standard I2C modules allowing you to daisy-chain several different types of modules together using only the two I2C pins of your microcontroller.


For Arduino users you can use the mLink library (see below) to control any type of mLink module. Only one single instance of the library is needed to control multiple types of mLink modules resulting in very little resources overhead and therefore making it great for Arduinos with small amounts of memory and pin counts.

For Raspberry Pi users we have a Python module which can be installed via pip or downloaded and installed directly from our forum. Please see the mLink Python forum thread for requirements and download link here: viewtopic.php?f=131&t=3062&p=8592#p8592


Module specifications:

Module code: 					HCMODU0180
Supply Voltage (VDD): 			3V to 5.5V
Current consumption (no load):		4.5mA
Interfaces:					I2C & 12 x digital I/O pins
I2C Interface speed: 				400kbits/s (fast mode)
I2C default address (HEX): 		0h50
Maximum number of modules: 		5 with pullups fitted, 112 with pullups removed*
Module dimensions (inc headers):	43mm x 19mm x 11.5mm

Digital output max freq:			1.54KHz
Digital Input low level voltage: 		-0.3V to 0.3 x VDD 
Digital Input high level voltage: 	0.7 x VDD to VDD + 0.3V
Digital output pin current source:	 Max 10mA
Digital output pin current sink:		Pins 0 to 2 & 5 to 11 max 10mA 
Pins 3 & 4 max 4mA
Digital output pullup resistor: 		30K to 80K Ohms

*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 all fitted to all modules. 





Arduino Connection Example:


Image

Image



Write pin (blink) example

Arduino Digital Output (Blink) Example:

This sketch uses the mLink to 'blink' digital pin 0 on an mLink 12 pin digital port expander module (SKU: HCMODU0180).

To use this sketch connect an LED with a suitable current limiting resistor in series to pin D0 and GND. The LED should then flash slowly

  1. #include "mLink.h"      // Include the library
  2.  
  3. mLink mLink;            //Create an instance of the library
  4.  
  5. #define I2C_ADD 0x50    //Default I2C address
  6.  
  7. void setup()
  8. {
  9.   mLink.init();
  10.  
  11.   // Set pin D0 to an output
  12.   mLink.writeBit(I2C_ADD, DIO12_D0_OUTPUT);
  13. }
  14.  
  15.  
  16. void loop()
  17. {
  18.   mLink.writeBit(I2C_ADD, DIO12_D0, HIGH);    // Set pin D0 HIGH
  19.   delay(1000);                                // Wait for a second
  20.   mLink.writeBit(I2C_ADD, DIO12_D0, LOW);     // Set pin D0 LOW
  21.   delay(1000);                                // Wait for a second
  22. }

Read pin example

Arduino Digital Input Example:

This sketch uses the mLink to read the state of pin D1 on an mLink 12 pin digital port expander module (SKU: HCMODU0180).

To use this sketch connect a push button to pin D1 and GND. The sketch will output the pin state to the monitor window.

  1. #include "mLink.h"      // Include the library
  2.  
  3. mLink mLink;            // Create an instance of the library
  4.  
  5. #define I2C_ADD 0x50    // Default I2C address
  6.  
  7. void setup()
  8. {
  9.   Serial.begin(9600);
  10.   mLink.init();
  11.  
  12.   // Set pin D1 to an input
  13.   mLink.writeBit(I2C_ADD, DIO12_D1_INPUT);
  14. }
  15.  
  16.  
  17. void loop()
  18. {
  19.   boolean result = mLink.readBit(I2C_ADD, DIO12_D1);  // Read pin D1
  20.  
  21.   Serial.println(result);     // Output the pin state to the serial monitor
  22.   delay(500);                 // Wait a little
  23. }



Raspberry Pi Connection Diagram

Image


Write pin (blink) example

Raspberry Pi Digital Output 'Blink' Example:

This sketch uses the mLink Raspberry Pi library module to 'blink' digital pin 0 on an mLink 12 pin digital port expander module (SKU: HCMODU0180).

To use this example connect an LED with a suitable current limiting resistor in series to pin D0 and GND. The LED should then flash slowly

This program requires the mLink Python library module to be installed. Please see the following forum thread for more information on how to install the Python module and requirements:

viewtopic.php?f=131&t=3062

  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 = 0x50                                  # Default I2C address is 0x50
  7.  
  8.  
  9. # Set pin 0 to an output
  10. ml.DIO12_Pin_Dir(I2C_ADD, ml.DIO12_D0, ml.DIO12_OUTPUT)
  11.  
  12. while 1:
  13.     ml.DIO12_Pin_Write(0x50, ml.DIO12_D0, 0)    # Set pin 0 low
  14.     time.sleep(1)
  15.     ml.DIO12_Pin_Write(0x50, ml.DIO12_D0, 1)    # Set pin 0 high
  16.     time.sleep(1)

Read pin example

Raspberry Pi Digital Input Example:

mLink Raspberry Pi 12 bit port expander pin read example.

This program requires the mLink Python library module to be installed. Please see the following forum thread for more information on how to install the Python module and requirements:

viewtopic.php?f=131&t=3062

  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 = 0x50                                  # Default I2C address is 0x50
  7.  
  8.  
  9. # Set pin 1 to an input
  10. ml.DIO12_Pin_Dir(I2C_ADD, ml.DIO12_D1, ml.DIO12_INPUT)
  11.  
  12. while 1:
  13.     print(ml.DIO12_Pin_Read (0x50, ml.DIO12_D1))
  14.     time.sleep(0.5)



Removing the modules I2C pullup resistors

Please note that the modules I2C pullup resistors should be removed if you intend to use it as follows:

1) You wish to connect more than 5 modules to the same I2C bus.

2) You wish to power this module at 5V and you have a 3.3V development board that does not have a 5V tolerant I2C interface.

3) You wish to power this module at 5V and you have a 3.3V development board that has its own I2C pullup resistors.


To disconnect the modules two 10K pullup resistors from the I2C bus simply cut the two tracks that connect the 3 pads labelled ‘END DEV’ together:

Image





Image

mLink Arduino library
viewtopic.php?f=58&t=3001


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 Library Quick Start Guide For Arduino Users
https://hobbycomponents.com/downloads/m ... _Guide.pdf


mLink Library Reference Guide For The 12Bit Port Expander Module
https://hobbycomponents.com/downloads/m ... _Guide.pdf


mLink Specifications and Register Map For The 12Bit Port Expander Module
https://hobbycomponents.com/downloads/m ... er_Map.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 no provide any guarantees or warranties as to their accuracy or fitness for purpose.

Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.

Post Reply

Return to “mLink”