mLink 4x4 Matrix Keypad (HCMODU0188)

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

mLink 4x4 Matrix Keypad (HCMODU0188)

Post by admin » Mon Apr 04, 2022 3:51 pm

Image



The mLink 4x4 matrix keypad is a panel mountable serial (I2C/IIC) 16 key tactile keypad. On the rear of the keypad is mounted a mLink module which continuously scans the keypad (with automatic debouncing) for any key presses. If a key is pressed the module stores the key as an 8 bit ASCII value which can then be read out of its serial 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: 					HCMODU0188
Supply voltage (VDD): 			3.3V to 5.5V
Operating range (recommended):	-5 to 105oC
Keypad type:					16 key matrix tactile keypad in 4x4 arrangement
Current consumption (idle):		4.5mA
Interfaces:					I2C, Keypad
I2C Interface speed: 				400kbits/s (fast mode)
I2C default address (HEX): 		0h55
Maximum number of modules: 		5 with pullups fitted, 112 with pullups removed*
Module dimensions (inc headers):	46mm x 14mm x 11mm
Keypad dimensions (inc module):	68.5mm x 65mm x 17mm


*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 pullups fitted.





Arduino Example:

Image


Image


Because the modules use an I2C interface this also means multiple modules can be controlled from a single Arduino I2C interface simply by daisy-chaining them together. Note to control multiple mLink modules of the same type requires changing the default I2C address of the additional modules. See mLink Library Quick Start Guide for how to do this.


Image




  1. #include "mLink.h"                                    // Include the library
  2.  
  3. mLink mLink;                                          // Create an instance of the library
  4.  
  5. #define I2C_ADD 0x55                                  // Default I2C address
  6.  
  7. void setup()
  8. {
  9.   Serial.begin(9600);
  10.  
  11.   mLink.init();                                       // Initialise the library
  12. }
  13.  
  14.  
  15. void loop()
  16. {  
  17.   char key = mLink.read(I2C_ADD, KEYPAD_4X4_KEY);     // Read the key status
  18.  
  19.   if(key)                                             // Has a key been pressed ?
  20.   {
  21.     Serial.print("Key: ");                            // If so then print out the key
  22.     Serial.println(key);
  23.   }
  24. }





Raspberry Pi Example:

Image



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 = 0x55                          # Default I2C address is 0x55
  7.  
  8.  
  9. while 1:
  10.     key = ml.Keypad_4X4_Read(I2C_ADD)   # Read the keypad
  11.     if key != '':                       # Is it a valid key?
  12.         print(key)                      # If so then print it out
  13.     time.sleep(0.1)




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 PTC Temperature Sensor Module
https://hobbycomponents.com/downloads/m ... _Guide.pdf


mLink Specifications and Register Map For The PTC Temperature Sensor Modul
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.

IainW
Posts: 2
Joined: Mon May 23, 2022 1:43 pm

Using mLink 4x4 Matrix Keypad with Raspberry Pi

Post by IainW » Mon May 23, 2022 2:16 pm

<t>Hello,<br/>
<br/>
I have purchased an mLink 4x4 Matrix Keypad and would like to use it with a Raspberry Pi 4. Can anyone give me an example Python program please?<br/>
<br/>
Thanks,<br/>
Iain</t>

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

Re: Using mLink 4x4 Matrix Keypad with Raspberry Pi

Post by andrew » Tue May 24, 2022 8:45 am

Try this:

  1. from smbus import SMBus
  2. I2C_ADD = 0x55
  3. KEYPAD_4X4_KEY = 0x0B
  4. i2cbus = SMBus(1)
  5.  
  6. while 1:
  7.     key = i2cbus.read_byte_data(I2C_ADD, KEYPAD_4X4_KEY)
  8.     if key != 0:
  9.         print(chr(key))
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

IainW
Posts: 2
Joined: Mon May 23, 2022 1:43 pm

Re: Using mLink 4x4 Matrix Keypad with Raspberry Pi

Post by IainW » Wed May 25, 2022 10:53 am

Hello Andrew,

Works fine so problem solved, thanks for your help.

Regards,
Iain

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

Re: mLink 4x4 Matrix Keypad (HCMODU0188)

Post by andrew » Fri May 27, 2022 9:40 am

Thanks for confirming. I've moved these post to the product thread as other users may find it helpful.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “mLink”