Hand Wiring Switches and LED Backlighting questions

User avatar
Muirium
µ

24 Mar 2014, 14:41

It takes a lot to break a switch. Trust me, I've been pretty brutal!

Did you install those resistors? If so, they could be the problem.

User avatar
rklm

24 Mar 2014, 21:27

I am back home now, and testing my board.

I changed the code a bit, and this seems to work:
Spoiler:
/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
const int led = LED_BUILTIN;
const byte ROWS = 13; //four rows
const byte COLS = 6; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','4','5','6'},
{'7','8','9','11','12','13'},
{'14','15','16','17','18','19'},
{'20','21','22','23','24','25'},
{'26','27','28','29','30','31'},
{'32','33','34','35','36','37'},
{'38','39','40','41','42','43'},
{'44','45','46','47','48','49'},
{'50','51','52','53','54','55'},
{'56','57','58','59','60','61'},
{'62','63','64','65','66','67'},
{'68','69','70','71','72','73'},
{'74','75','76','77','78','79'}
};
byte rowPins[ROWS] = {22, 23, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {21, 20, 19, 18, 17, 16}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

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

void loop(){
char key = keypad.getKey();

if (key){
// Serial.println(key);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
}
}
(I edited the keypad and blink examples together to create this)

When I first loaded that code on my teensy, I used a 1x1 matrix (pins 22 and 21).

The light was off at first, then I held down the key and the light turned on for 500ms, then turned off. Sweet.

I bumped it up to a 2x2 matrix (pins (22, 23)(21,20)) and it behaved the same way. Sweet.

When I bumped it up to 6x13 using my original code, it failed because the diodes are wired along the other axis, so I flipped it to 13x6. Wasn't sweet, but now it's sweet.

Once I got all the code working and all the keys registering, it the teensy started blinking very quickly. Wat.

When I tried actuating the keys, almost all behaved exactly how they did before, the LED stopped blinking and became solid for 500ms, then went out. Ok...

When I pressed keys on column 2 (counting from the left. Pin 1) the light would go solid and stay that way, instead of turning off after 500ms. <-- First weird thing.

When I pressed keys on column 3 (counting from the left. Pin 2) the light did nothing. It didn't stop blinking. <-- Totally non-functional... but evrything is connected.

I tried disconnecting those whole columns, and the light still blinks. <-- Why would this happen if the connection faults were on those columns?

Not sure what is going wrong, the teensy can run other software, so I don't think that is the fault point. I guess it has to be one or two connections that are failing somewhere near those two columns, but I am not sure how to think through tracing them back.

Here are some pics:
Spoiler:
ImageImageImageImage
My Imgur: http://imgur.com/a/QfPJP

User avatar
Muirium
µ

24 Mar 2014, 21:33

Okay, no resistors in sight: phew! Are all the diodes the same polarity? And have you tested for shorts between rows and columns (accidental continuity when no switches are pressed)?

User avatar
rklm

24 Mar 2014, 22:06

Yes, the diodes are all the same polarity.

I haven't checked for shorts, but I am pretty sure the only place a short could be happening is on pin 1 or 2 (the 2nd and 3rd column from the left).

Those are the ones that are behaving weirdly thus far. Also, all the switches in those columns behave the same way, so I would imagine the problem is somewhere along the connection between those columns and the teensy... but I can't see anything wrong there and the blinking problem still happens after I desolder those leads.

User avatar
Muirium
µ

24 Mar 2014, 22:09

When I had shorts on my matrix, it showed up as ghosting along whole columns. Nothing else was broken, just my handiwork!

Get forensic with that continuity meter, stat.

User avatar
rklm

24 Mar 2014, 23:32

I just tried jumping those leads to any of the row leads and it has the same affect... so the problem might be in the code? Or the teensy itself? I am quite confused... still testing.

User avatar
rklm

24 Mar 2014, 23:37

aaaand... when I run this:
Spoiler:
/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
const int led = LED_BUILTIN;
const byte ROWS = 2; //four rows
const byte COLS = 6; //three columns
char keys[ROWS][COLS] = {
{'1','2','3','4','5','6'},
{'7','8','9','11','12','13'}
};
byte rowPins[ROWS] = {2, 1}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {21, 20, 19, 18, 17, 16}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

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

void loop(){
char key = keypad.getKey();

if (key){
// Serial.println(key);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
}
}
those two columns work perfectly...?

User avatar
rklm

24 Mar 2014, 23:47

Actually... isolating two columns at a time they all seem to work... still trying to figure out how to get a reading on the serial signal though, the monitor never shows anything so I can't tell if there is ghosting just from that.

Also, I will borrow a continuity meter to test the connections later

User avatar
rklm

25 Mar 2014, 00:06

When I run
10 pins: {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} together all switches are fine (same goes for everything less than 10
11 pins: {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} the 0 row stops working, but the other 10/11 work fine
12 pins: {23, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0} the blinking starts AND 0 and 1 behave like 1 and 2 did when all are running together.


I feel I am on to something... I hope it isn't the bandwidth limitation of the teensy though :s

[EDIT]

Checked the columns from the other direction:
When I run
10 pins: {22, 23, 10, 9, 8, 7, 6, 5, 4, 3}: works fine
11 pins: {22, 23, 10, 9, 8, 7, 6, 5, 4, 3, 2}: #2 does nothing
12 pins: {22, 23, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}: the feedback loop-esque blinking begins

User avatar
rklm

25 Mar 2014, 05:10

I think the problem I was having is a software issue, so I am going to load the actual software on it and test that.

Anyone wanna help me with my layout source files? It's pretty simple, but I am too noobly to understand all of it.

User avatar
rklm

25 Mar 2014, 22:48

I am trying to edit the GH60 code to make it work for my weird matrix, but there are a couple things in there I just can't seem to figure out.

for the columns, I changed static matrix_row_t read_cols(void) so that it would return:
Spoiler:
{
return (PINB&(1<<0) ? 0 : (1<<0)) |
(PINB&(1<<1) ? 0 : (1<<1)) |
(PINB&(1<<2) ? 0 : (1<<2)) |
(PINB&(1<<3) ? 0 : (1<<3)) |
(PINB&(1<<7) ? 0 : (1<<4)) |
(PIND&(1<<0) ? 0 : (1<<5)) |
(PIND&(1<<1) ? 0 : (1<<6)) |
(PIND&(1<<2) ? 0 : (1<<7)) |
(PIND&(1<<3) ? 0 : (1<<8)) |
(PINC&(1<<6) ? 0 : (1<<9)) |
(PINC&(1<<7) ? 0 : (1<<10)) |
(PIND&(1<<5) ? 0 : (1<<11)) |
(PIND&(1<<4) ? 0 : (1<<12)) ;
}
but I don't know what to do with static void init_cols(void). The default stuff for the gh60 is:
Spoiler:
{
// Input with pull-up(DDR:0, PORT:1)
DDRF &= ~(1<<0 | 1<<1);
PORTF |= (1<<0 | 1<<1);
DDRE &= ~(1<<6);
PORTE |= (1<<6);
DDRD &= ~(1<<7 | 1<<6 | 1<<4);
PORTD |= (1<<7 | 1<<6 | 1<<4);
DDRC &= ~(1<<7 | 1<<6);
PORTC |= (1<<7 | 1<<6);
DDRB &= ~(1<<7 | 1<<6 | 1<< 5 | 1<<4 | 1<<3 | 1<<1 | 1<<0);
PORTB |= (1<<7 | 1<<6 | 1<< 5 | 1<<4 | 1<<3 | 1<<1 | 1<<0);
}
But I don't think that is compatible with my matrix.


Same goes for the rows, I changed my static void select_row(uint8_t row) to
Spoiler:
{
switch (row) {
case 0:
DDRF |= (1<<0);
PORTF &= ~(1<<0);
break;
case 1:
DDRF |= (1<<1);
PORTF &= ~(1<<1);
break;
case 2:
DDRF |= (1<<2);
PORTF &= ~(1<<4);
break;
case 3:
DDRF |= (1<<3);
PORTF &= ~(1<<5);
break;
case 4:
DDRF |= (1<<5);
PORTF &= ~(1<<6);
break;
}
}
but I don't know what to do with static void unselect_rows(void). The default for that one is:
Spoiler:
{
// Hi-Z(DDR:0, PORT:0) to unselect
DDRD &= ~0b00101111;
PORTD &= ~0b00101111;
}
Should I leave it alone? or make it unselect?




More vaguely, does anyone know what I have to change to reduce the column size to 13 (on different pins) and the row size to 6 (also on different pins)?

I think I have the keymap part together, figured that out from context, but don't know how to correct the other files.

And another thing! I tried to recreate matt3o's brownfox diode orientation... does that mean that I have to reorient the matrix? like 13 rows 6 columns? The only way the board worked with my little arduino test was in that orientation.

User avatar
rklm

26 Mar 2014, 00:28

I should have lurked /workshop more before spending all that time with the source code... Soarer's firmware is so much more awesome.

I just set all the matrix values to blank and tested the switches with HID_listen like he said to and it turns out all of my switches produce the correct matrix code and don't ghost (as far as I am aware) at all! No shorts on the first try!

User avatar
Muirium
µ

26 Mar 2014, 00:35

That's more like it. I don't really code, and I'm much more comfortable with Soarer's controller too. Be sure to give it a good test though. Ghosts aren't fun.

User avatar
rklm

26 Mar 2014, 00:43

Are there any definitive tests for that sort of thing?

User avatar
Muirium
µ

26 Mar 2014, 00:48

If you're on Windows, everyone there swears by Aqua's KeyTest:

http://geekhack.org/index.php?topic=6643.0

On OS X, I simply open up the onscreen keyboard and keep an eye on it while putting on the caps. Ghosts show up quite clearly as multiple keys go dark.

User avatar
rklm

26 Mar 2014, 01:24

Based on AquaKey, everything is 100%, so now all I need to do is map the function layer

User avatar
Muirium
µ

26 Mar 2014, 01:40

Congrats!

User avatar
rklm

26 Mar 2014, 06:09

I got all my function layer remaps working and everything.

Oh man, it's so awesome.

It's so awesome.

Once those damned LEDs come from china I will wire up that matrix and finish my build log.

User avatar
rklm

26 Mar 2014, 15:09

I just tested the USB nkey rollover... It is functioning better than I have ever seen on USB... I have always been a PS2 guy but this changes everything!

Did I mention that I am a huge Soarer fan now?

Happily Minimal Animal typing, I hope those LEDs come soon (I also have a couple MX clears that I am going to mod and put on the board)

User avatar
Muirium
µ

26 Mar 2014, 15:13

Soarer has turn-key awesome ready to go, right out the box. I'm a huge fan too! You get all the same powers with his converter, too, which brings a naturally NKRO board like an IBM Model F right into the USB age. I was amazed the first time I saw it!

User avatar
rklm

30 Mar 2014, 09:58

Got my LEDs, wired them up (which was probably more complicated and took more time than the switch matrix, since I only gave myself a ~9mm cavity to work in :lol: ).

Everything worked first try once again (I am a very methodical solder-er).

You guys might have been right... at 5mA the LEDs are SUPER DUPER AWESOME GIGA BRIGHT.

Like... This keyboard is LITTERALLY(and not that stupid new 'also figurative' definition) brighter than any flashlight I have ever owned!

I can see the ceiling above my desk perfectly well now.

Good thing I am going to be blocking them out with red color changer caps and blank black DSA keycaps...

Still can't solder in the LEDs for backspace, space, and my UDLR keys, since I haven't gotten my mx clear stems and springs yet, but everything else is ready to go around it (the positive leads and the resistors are in place)

I will post pics in the morning. I am sleepy and mostly blinded at the moment.

User avatar
rklm

09 Apr 2014, 22:58

Project is completely (well, until I find something else to tinker with) finished.

Here is the new forum post: http://deskthority.net/workshop-f7/mini ... ml#p157190

User avatar
tentator

28 Jan 2016, 23:13

Hello Rklm.. noticing just now your interesting project with the leds since I'm also thinking about what to do with leds on my new project based on teensy..
in the end did you connect the leds to the teensy or just directly to the 5v rail from USB?
And you used 330ohm resistors for each led? (I was more into 1kohm or even more actually..)
But actually I'd then also like to be able to increase or diminish or turn off completely the leds by connecting them to a pwm pin anyways.. hope this is still possible without damaging the pin..
my plan would be to have 4 pins used like: one for caps, one for num and one for scroll locks and a fourth one for the rest of the leds in background configuration as a whole...

Matt_

28 Jan 2016, 23:30

If you plan on using TMK, flabbergast provides valuable info on how to wire and control backlight here: workshop-f7/how-to-build-your-very-own- ... ml#p240050

Teensy 2.0 has 25 pins, so as long as your matrix does not use more than 21 pins you should be able to use four as described (caps/numlock/scrlock/backlight).

Post Reply

Return to “Workshop”