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

Seedstudio Keypad Module


  • Please log in to reply
13 replies to this topic

#1 Mike Hole

Mike Hole

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 22 March 2012 - 02:48 PM

I recently purchased the Electronic Brick Starter kit for use on my Netduino Plus board. Loving the experience so far :). I also purchased the Keypad Module (BUS) http://proto-pic.co....pad-module-bus/ not realising that this is a discontinued product :( I have tried to work out how this interfaces with the Netduino and have had limited success in getting an output that I can understand. I have searched the internet, the forum and WIKI but cannot find any information on how this board works with any Arduino board. Does anybody have any information available that you are able to point me towards? Thanks, Mike

#2 Bainesbunch

Bainesbunch

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts
  • LocationFrance

Posted 22 March 2012 - 04:16 PM

Hello,

If you look at the Arduino code that is on the webpage for this keypad it looks like a basic 3x3 multiplexed matrix


void setup() 
{
  Serial.begin(9600);
  for(i=0;i<3;i++) 	pinMode((KeyOPin + i), OUTPUT); 	
  for (i=0;i<3;i++)	pinMode(( KeyIPin + i), INPUT); 
} 	

void loop()
{
   scankey();
   if (press)
   {
	press=0;
	Serial.print("Keycode is ");
	Serial.println(oldkey,HEX);
   }
}

void scankey()
{
  reg = 1;
  for (i=0;i<3;i++)
  {
	for (n=0;n<3;n++)
	{
      if((reg>>n)&1)        digitalWrite(KeyOPin+n , HIGH); 
      else                  digitalWrite(KeyOPin+n , LOW);
	}   
	for (n=0;n<3;n++)
	{
  	if(digitalRead(KeyIPin + n))
  	{ 	
    	key = key | (1<<(4+n));	
    	key = key | reg ; 
      }                    
	}
	reg = reg << 1;
  }

  if (key & 0xf8)
  {
	if (key!=oldkey)   {   
  	press = 1;  
  	oldkey = key ; 
	}
  }
  else   	oldkey = 0;


  key = 0;
}


it is an easy task to translate this code from the Arduino C++ Variant to C# or VB

It would be useful to know the pin outs on the IDC connector they have attached to the board so you know which pins connect to the 3 ports that are outputs and which should be connected to the inputs.

If you are having problem drop me a PM or ask further here and I can do the translation for you. But it is best to try yourself first.

Cheers Pete.
I was going to change the world, then I discovered Netduino.
The world will have to wait.

#3 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 22 March 2012 - 04:20 PM

Hello,

If you look at the Arduino code that is on the webpage for this keypad it looks like a basic 3x3 multiplexed matrix

If it's a multiplexed matrix, then there's netduino code:
http://netmftoolbox....re.MatrixKeyPad
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#4 Mike Hole

Mike Hole

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 22 March 2012 - 05:10 PM

Hi Both, I have tried your code Stefan but it's not worked :( I have also tried a simple app that just lists pin values for the conected pins: public static void Main() { TristatePort d2 = new TristatePort(Pins.GPIO_PIN_D2, false, false, Port.ResistorMode.PullUp); TristatePort d3 = new TristatePort(Pins.GPIO_PIN_D3, false, false, Port.ResistorMode.PullUp); TristatePort d4 = new TristatePort(Pins.GPIO_PIN_D4, false, false, Port.ResistorMode.PullUp); TristatePort d5 = new TristatePort(Pins.GPIO_PIN_D5, false, false, Port.ResistorMode.PullUp); TristatePort d6 = new TristatePort(Pins.GPIO_PIN_D6, false, false, Port.ResistorMode.PullUp); TristatePort d7 = new TristatePort(Pins.GPIO_PIN_D7, false, false, Port.ResistorMode.PullUp); TristatePort d8 = new TristatePort(Pins.GPIO_PIN_D8, false, false, Port.ResistorMode.PullUp); TristatePort d9 = new TristatePort(Pins.GPIO_PIN_D9, false, false, Port.ResistorMode.PullUp); while (true) { Debug.Print( " d2: " + d2.Read().ToString() + " d3: " + d3.Read().ToString() + " d4: " + d4.Read().ToString() + " d5: " + d5.Read().ToString() + " d6: " + d6.Read().ToString() + " d7: " + d7.Read().ToString() + " d8: " + d8.Read().ToString() + " d9: " + d9.Read().ToString() ); } } With this I only get changes in D5, D6 and D7 for the rows but none of the other pins show a change. Could it be that I have not set up the pins correctly in code?

#5 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 22 March 2012 - 05:22 PM

I have tried your code Stefan but it's not worked :(

Have you configured the pins correctly? The class is generic for matrix keypads, but the pins can be different with your keypad.

I have also tried a simple app that just lists pin values for the conected pins:

You've got them all just reading a value, but that's not how it works. Look at the diagram on the link I provided. A signal is sent from an output port to an input port. Rows are input ports, columns are output ports (or the other way around, doesn't matter).
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#6 Mike Hole

Mike Hole

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 22 March 2012 - 05:27 PM

Aha! Ok will I will try that.

#7 Bainesbunch

Bainesbunch

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts
  • LocationFrance

Posted 22 March 2012 - 05:36 PM

Aha! Ok will I will try that.


do you have a pinout for this keyboard ?
I was going to change the world, then I discovered Netduino.
The world will have to wait.

#8 Mike Hole

Mike Hole

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 22 March 2012 - 05:41 PM

Nope can't find any documentation anywhere If I did I would know how to feed Stefan's code above with teh right pins. Looks like it's a case of try different combinations ntil it works. Using the electronic brick it maps pins to ports for you but without docs I have to guess where.

#9 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 22 March 2012 - 05:48 PM

From the C sample code:
int  KeyOPin = 5;              
int KeyIPin = 2; 

  for(i=0;i<3;i++)     pinMode((KeyOPin + i), OUTPUT);     
  for (i=0;i<3;i++)    pinMode(( KeyIPin + i), INPUT);
So I take it pins 5, 6, 7 are output and pins 2, 3, 4 are input.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#10 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 22 March 2012 - 06:12 PM

Mike, if you have any multimeter, switch it as "Ohms", then try the various combinations of pins. When a key is pressed only a row and a column should give a low value of resistance (under an hundred of Ohms). Hope it helps. Cheers
Biggest fault of Netduino? It runs by electricity.

#11 Mike Hole

Mike Hole

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 22 March 2012 - 07:03 PM

From the C sample code:

int  KeyOPin = 5;              
int KeyIPin = 2; 

  for(i=0;i<3;i++)     pinMode((KeyOPin + i), OUTPUT);     
  for (i=0;i<3;i++)    pinMode(( KeyIPin + i), INPUT);
So I take it pins 5, 6, 7 are output and pins 2, 3, 4 are input.


Hadn't spotted the numbers there you may have it but I am now home and unable to test until tomorrow :(

#12 Mike Hole

Mike Hole

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 23 March 2012 - 08:45 AM

Arrghgg this is frustrating looks like a multimeter is in order (and there was me thinking a component based kit would make life easier). Trying this (and combinations of the pins in different orders + swapping the rows for the columns): // Row pins. The keypad exists out of 4 rows. Cpu.Pin[] RowPins = { Pins.GPIO_PIN_D2, Pins.GPIO_PIN_D3, Pins.GPIO_PIN_D4 }; // Col pins. The keypad exists out of 3 columns. Cpu.Pin[] ColPins = { Pins.GPIO_PIN_D5, Pins.GPIO_PIN_D6, Pins.GPIO_PIN_D7 }; The best results I get are: Top Row: Key pressed: 6 Key released: 6 Key pressed: 6 Key released: 6 Key pressed: 6 Key released: 6 Middle Row: Key pressed: 7 Key released: 7 Key pressed: 7 Key released: 7 Key pressed: 7 Key released: 7 Key pressed: 7 Key released: 7 Bottom Row: Key pressed: 8 Key released: 8 Key pressed: 8 Key released: 8 Key pressed: 8 Key released: 8 Key pressed: 8 Key released: 8

#13 Mike Hole

Mike Hole

    Advanced Member

  • Members
  • PipPipPip
  • 39 posts

Posted 23 March 2012 - 09:17 AM

Yay this works for me now all I needs tydying up and events added but got there in the end:

public static void Main()
{

OutputPort[] outP =
{
new OutputPort(Pins.GPIO_PIN_D5, false),
new OutputPort(Pins.GPIO_PIN_D6, false),
new OutputPort(Pins.GPIO_PIN_D7, false)
};

InputPort[] inP =
{
new InputPort(Pins.GPIO_PIN_D2, true, Port.ResistorMode.PullUp),
new InputPort(Pins.GPIO_PIN_D3, true, Port.ResistorMode.PullUp),
new InputPort(Pins.GPIO_PIN_D4, true, Port.ResistorMode.PullUp)
};

while (true)
{
for (int o = 0; o < 3; o++)
{
outP[o].Write(true);


for (int i = 0; i < 3; i++)
{
if (inP[i].Read())
Debug.Print( o.ToString() + " - " + i.ToString());
}

outP[o].Write(false);
}
}
}

#14 Bainesbunch

Bainesbunch

    Advanced Member

  • Members
  • PipPipPip
  • 61 posts
  • LocationFrance

Posted 23 March 2012 - 06:04 PM

Well done !! :D Now go and have some more fun
I was going to change the world, then I discovered Netduino.
The world will have to wait.




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.