Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Mulitplex Keypad Output


  • Please log in to reply
29 replies to this topic

#21 GlenS

GlenS

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationTamworth, UK

Posted 11 March 2012 - 09:36 PM

Paul,

Glad to hear you have the project working. Still no joy at my end, although I am now seeing the LED's flash when the button connection is made. In terms of the Hex code output, the ToString() method in the Micro .NET framework does not implement conversion directly to hexadecimal. I do have this code that I use, and offer it up in thanks for your help.

public static class HexHelper
    {
        public static string ToHexString(this byte value)
        {
            char[] hexValues = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
            string result = hexValues[value / 16].ToString() + hexValues[value % 16].ToString();
            return result;
        }
    }

Please go ahead and put the work on the wiki, I'm sure the good work you and Mario have done here will benefit the community.

Once again many thanks.

Glen

#22 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 13 March 2012 - 06:14 PM

Added Wiki page.

#23 Nathan Baker

Nathan Baker

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationWisconsin

Posted 13 March 2012 - 08:15 PM

This is quite the interesting idea, and I don't think I would have ever thought of doing it in this way. I will have to try this out at some point.
Posted Image

#24 GlenS

GlenS

    Member

  • Members
  • PipPip
  • 23 posts
  • LocationTamworth, UK

Posted 15 March 2012 - 10:24 PM

Ok,

After a weekend away and a busy week at work, I have returned to this with "proper" diodes and finally managed to get the project to work. I see the same as Paul in that the values returned seem to be reversed from his theory. Below is a work-in-progress driver class for the setup. It needs a lot of work, especially in improving area of key-debounce. I am seeing far too often double key presses. I would like to improve the oversized switch statement as well.

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
#if Netduino 
using SecretLabs.NETMF.Hardware.Netduino;
#else
using SecretLabs.NETMF.Hardware.NetduinoPlus;
#endif

namespace KeypadTest
{
    public class KeypadDriver 
    {

        public delegate void KeyPressHandler(object sender, char keyPressed);
        
        public KeypadDriver(int debounce=250)
        {
            this.debounce = debounce;
            keyReader = new Thread(new ThreadStart(ReadKeyPad));
            keyReader.Start();
        }

        public event KeyPressHandler OnKeyPressed;

        private void ReadKeyPad()
        {
            while (true) 
            {
                readbuffer[0] = 0x00;
                writebuffer[0] = 0x01;
                spi.WriteRead(writebuffer, readbuffer);
                if (readbuffer[0] != 0xFF)
                {
                    char result = '+'; // need to define something ...
                    switch (readbuffer[0])
                    {
                        case 0x88:
                            result = '1';
                            break;
                        case 0x84:
                            result = '2';
                            break;
                        case 0x82:
                            result = '3';
                            break;
                        case 0x81:
                            result = 'A';
                            break;
                        case 0x48:
                            result = '4';
                            break;
                        case 0x44:
                            result = '5';
                            break;
                        case 0x42:
                            result = '6';
                            break;
                        case 0x41:
                            result = 'B';
                            break;
                        case 0x28:
                            result = '7';
                            break;
                        case 0x24:
                            result = '8';
                            break;
                        case 0x22:
                            result = '9';
                            break;
                        case 0x21:
                            result = 'C';
                            break;
                        case 0x18:
                            result = '*';
                            break;
                        case 0x14:
                            result = '0';
                            break;
                        case 0x12:
                            result = '#';
                            break;
                        case 0x11:
                            result = 'D';
                            break;
                    }
                    if (OnKeyPressed != null)
                    {
                        OnKeyPressed(this, result);
                    }
                }
                Thread.Sleep(debounce);
            }
        }

        private Thread keyReader;
        private int debounce;
        private byte[] readbuffer = new byte[1];
        private byte[] writebuffer = new byte[1];
        private SPI spi = new SPI(new SPI.Configuration(Pins.GPIO_NONE, false, 0, 0, false, true, 32, SPI.SPI_module.SPI1));
    }
}

An example use:-

public class Program
    {
        public static void Main()
        {
            // write your code here
            KeypadDriver driver = new KeypadDriver();
            driver.OnKeyPressed += new KeypadDriver.KeyPressHandler(driver_OnKeyPressed);
            while (true)
            {
                Thread.Sleep(250);
            }
        }

        static void driver_OnKeyPressed(object sender, char keyPressed)
        {
            Debug.Print("Key Pressed = " + keyPressed.ToString());
        }
    }

Once again thanks to Mario and Paul for the efforts they both put in answering my original query. Paul, please feel free to add this code to the wiki article, I'm afraid I had a look but could not work out the process.

Glen

#25 Djeizan

Djeizan

    Member

  • Members
  • PipPip
  • 11 posts

Posted 26 March 2013 - 12:00 AM

is possible to use other device SPI with this matrix keypad?



#26 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 26 March 2013 - 08:01 PM

is possible to use other device SPI with this matrix keypad?

Hi Djeizan,

 

I have not tried using it with other SPI devices yet.

 

I think it can be made to work, but there will be some fiddling since the data to the Netduino is connected in an unusual way.

 

It should be straight forward to connect other output devices (especially if you use separate strobe lines).

Connecting input devices will be a little more tricky.

 

What device(s) do you want to use? (Part numbers / links to data sheets will be useful.)

 

Paul



#27 Djeizan

Djeizan

    Member

  • Members
  • PipPip
  • 11 posts

Posted 26 March 2013 - 08:51 PM

>>What device(s) do you want to use? (Part numbers / links to data sheets will be useful.)

 

74HC165

 

http://forums.netdui...h-the-netduino/



#28 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 26 March 2013 - 10:20 PM

Yes, I think this will work.

 

Try the following:

 

1/ Connect the 74HC165 to the Netduino as normal :

  • Q7 (pin 9) connected to MISO,
  • CP (pin 2) connected to SCLK,
  • PL (pin 1) connected to your choice of GPIO for the strobe.

2/ Connect the matrix scanner so that the signal that used to go to MISO, now goes to DS (pin 10) on the 74HC165 .

3/ Starting with the software above (its a small program so will make a simple test harness to get you started). Make the following changes:

  • Change the read and write arrays to two bytes each.
  • Set the write data to {0x01, 0x01}.
  • When the SPI device is created, specify your GPIO pin for the strobe line (this is only needed for the 74HC165).
  • Set the correct polarity for the strobe - I'm not sure which way up it needs to be - try it out and see what happens.
  • After doing the WriteRead operation, print out both of the readBuffer bytes so you can tell which way round they are arriving and whether the data is correct.

Now the data from the 74HC165 should be in the first byte to be read, and the keypad byte in the second.

 

If the data does not seem correct, try swapping the polarity of the strobe.

 

I have not tried this myself, so please let us know how it goes.

 

Paul



#29 Djeizan

Djeizan

    Member

  • Members
  • PipPip
  • 11 posts

Posted 27 March 2013 - 06:28 PM

Great Idea

 

I will try your suggestion and post the results here

 

Jaison  



#30 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 07 April 2013 - 01:03 PM

Hi everyone,

 

A year after the original posts, I have now built my own decoder. (Previously I only tested it on a plug board.)

 

I have updated the WIki page with photos.

 

Enjoy (but not too much, they are only photos) - Paul






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.