8x32 MX7219 dot matrix with 3x4 Keypad including MD_Parola & MD_MAX72XX

Hi,

it's my second arduino project and it looks like i am stuck. I didn't find my answer anywhere, so i hope you can help me.

What i want to do sound simple, is to write digits/numbers with the 3x4 Keypad and make them appear on the 8x32 MX7219 dot matrix next to each others, then press '*' to erase the dot matrix. But so far, i can only find the way to show the multiple digits number without keypad(quite easy but i need to connect to a computer to change it) and with the 3x4 keypad i can only show the last number punched and clear the screen.

Or i don't know if it will be easier if when we press the '#' button on the keypad, it shows the digits combination punched. I tried multiple projects code to try to make it work but i failed

Here's the code for now

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#include <Keypad.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define DATA_PIN 11
#define CS_PIN 9
#define CLK_PIN 10

char hexaKeys[4][3] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[4] = {8,7,6,5};
byte colPins[3] = {4,3,2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys),rowPins,colPins,4,3);

MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);


void setup() 
{
  Serial.begin(9600);

  myDisplay.begin();
  myDisplay.setIntensity(0);
  myDisplay.displayClear();
  myDisplay.setTextAlignment(PA_CENTER);
}


void loop() 
{
  char customKey = customKeypad.getKey();
  if (customKey)
  {
    myDisplay.print(customKey);
    if (customKey == '*')
    {
      myDisplay.displayClear();
    }
  }
}

Do not start like that. "Simple and easy" means you can do it without asking for help.

Using your code I could see a keypress show on an LED dot matrix. You must verify your hardware connections, including external power supply to drive 8x32 LEDs.

1 Like

Replace this line:

for this one:

#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW

and tell us the result.

1 Like

It doesn't display the digits the right way

Yeah sorry for the simple and easy, i correct it :wink:

all my hardware connection are good, i'm pretty shure since the MX7219 dot matrix 8x32 (https://www.amazon.ca/dp/B07QGDTP7K?ref=ppx_yo2ov_dt_b_product_details&th=1) is working well. But what i'm not able to do is to display multiple number next to each other by using a 3x4 keypad.

I am certain your connections are not good.

I used your code and made "numbers appear" on the LED matrix.

I used @ruilviana correction to your code and it worked perfectly.

dotmatrix

File for wokwi.com...

diagram.json
{
  "version": 1,
  "author": "Anonymous maker",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-nano", "id": "nano", "top": 0, "left": 0, "attrs": {} },
    {
      "type": "wokwi-membrane-keypad",
      "id": "keypad1",
      "top": -366.8,
      "left": -18.9,
      "attrs": { "columns": "3" }
    },
    {
      "type": "wokwi-max7219-matrix",
      "id": "matrix1",
      "top": 67.8,
      "left": -338.16,
      "attrs": { "chain": "4" }
    }
  ],
  "connections": [
    [ "keypad1:R1", "nano:8", "green", [ "v19.2", "h-172.8" ] ],
    [ "keypad1:R2", "nano:7", "green", [ "v19.2", "h-173.2" ] ],
    [ "keypad1:R3", "nano:6", "green", [ "v19.2", "h-182.7" ] ],
    [ "keypad1:R4", "nano:5", "green", [ "v19.2", "h-173" ] ],
    [ "keypad1:C1", "nano:4", "green", [ "v19.2", "h-172.9" ] ],
    [ "keypad1:C2", "nano:3", "green", [ "v19.2", "h-182.4" ] ],
    [ "keypad1:C3", "nano:2", "green", [ "v19.2", "h-182.55" ] ],
    [ "matrix1:V+", "nano:5V", "green", [ "h0" ] ],
    [ "matrix1:GND", "nano:GND.1", "black", [ "h0" ] ],
    [ "matrix1:DIN", "nano:11", "green", [ "h0" ] ],
    [ "matrix1:CS", "nano:9", "green", [ "h0" ] ],
    [ "matrix1:CLK", "nano:10", "green", [ "h0" ] ]
  ],
  "dependencies": {}
}

Yes it is working the way you said, but its only one digits...how to put them together? Can you type "1"2"3"4" and on the screen it will be written "1234" ?

You will need to learn to use setZone(), displayZoneText() and displayAnimate()

Another not-very-good way to display each key is to create an array, display the array, increment the array, and clear the array when needed.

dotmatrix

Files for wokwi.com:

sketch.ino
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <Keypad.h>

#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 4
#define DATA_PIN 11
#define CS_PIN 9
#define CLK_PIN 10

char hexaKeys[4][3] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[4] = {8, 7, 6, 5};
byte colPins[3] = {4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, 4, 3);

MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

char qcmonkeyboy_array[5]; // add one character to array of "4" for "null" ending
byte qcmonkeyboy_counter;

void setup() {
  // Serial.begin(9600);
  myDisplay.begin();
  myDisplay.setIntensity(0);
  myDisplay.displayClear();
  myDisplay.setTextAlignment(PA_CENTER);
}

void loop() {
  char customKey = customKeypad.getKey();
  if (customKey)
  {
    myDisplay.print(customKey);
    if (customKey == '*') {
      myDisplay.displayClear();
      for (int i = 0; i < 4; i++) // count through array
        qcmonkeyboy_array[i] = '\0'; // clear each array character using SINGLE quote
      qcmonkeyboy_counter = 0; // clear counter
    }
    else { // key was not "*" to clear
      qcmonkeyboy_array[qcmonkeyboy_counter] = customKey; // add the input key to the array
      myDisplay.print(qcmonkeyboy_array); // display the array
      qcmonkeyboy_counter++; // increment the array
      if (qcmonkeyboy_counter > 3) // the counter can not advance above 3
        qcmonkeyboy_counter = 3; // do not store more than 4 characters in the array
    }
  }
}
diagram.json
{
  "version": 1,
  "author": "Anonymous maker",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-nano", "id": "nano", "top": 0, "left": 0, "attrs": {} },
    {
      "type": "wokwi-membrane-keypad",
      "id": "keypad1",
      "top": -366.8,
      "left": -18.9,
      "attrs": { "columns": "3" }
    },
    {
      "type": "wokwi-max7219-matrix",
      "id": "matrix1",
      "top": 67.8,
      "left": -338.16,
      "attrs": { "chain": "4" }
    }
  ],
  "connections": [
    [ "keypad1:R1", "nano:8", "green", [ "v19.2", "h-172.8" ] ],
    [ "keypad1:R2", "nano:7", "green", [ "v19.2", "h-173.2" ] ],
    [ "keypad1:R3", "nano:6", "green", [ "v19.2", "h-182.7" ] ],
    [ "keypad1:R4", "nano:5", "green", [ "v19.2", "h-173" ] ],
    [ "keypad1:C1", "nano:4", "green", [ "v19.2", "h-172.9" ] ],
    [ "keypad1:C2", "nano:3", "green", [ "v19.2", "h-182.4" ] ],
    [ "keypad1:C3", "nano:2", "green", [ "v19.2", "h-182.55" ] ],
    [ "matrix1:V+", "nano:5V", "green", [ "h0" ] ],
    [ "matrix1:GND", "nano:GND.1", "black", [ "h0" ] ],
    [ "matrix1:DIN", "nano:11", "green", [ "h0" ] ],
    [ "matrix1:CS", "nano:9", "green", [ "h0" ] ],
    [ "matrix1:CLK", "nano:10", "green", [ "h0" ] ]
  ],
  "dependencies": {}
}

Why it is a not-very-good way to do it?

Sloppy use of arrays and therefore memory.

As you note, you are displaying just the last character you get rather than the whole string of characters. You need to build up the character string as each one is pressed and then display the new result.

Untested code below

void loop() 
{
  static char code[10] = { "" };
  char customKey = customKeypad.getKey();

  if (customKey)
  {
    if (customKey == '*')
        code]0\ = '\0';
    else
   {
       char new[2] = {  '\0', '\0' };
       new[0] = customkey;
       strcat(code, new);
   |
    myDisplay.print(code);
}

Try this code:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.