Hello everyone,
First of I want to share that I have experience with programming but zero of it with microcontrollers, so I apologise beforehand for any stupid mistakes.
I want to make a simple keyboard matrix of 6 buttons to work, but the output I am getting from the teensy seems random to me.
I am using pins 3-7. I was using the ones from 2-6 but I changed them in an attempt to solve the issue.
Pins 3-5 are columns. Pins 6 and 7 are rows.
This is the code. I also tried with Keyboard.send_now(). I am not using Keyboard.print() because later on I would like to use the keys for media controlls via HID codes.
When I tried seeing what was idling with the below code it always returns the same button when I'm not pressing anything. i - 5, j - 6 - which corresponds to the bottom left button on the image.
Here's an image of my soldering. Red numbers are pin numbers. White numbers are what is supposed to be output from the keys.
What is actually being output is this:
Expected output: --- Actual output:
1 --------------------- 13
2 --------------------- 24(5)
3 --------------------- 35
4 --------------------- 4(5)6
5 --------------------- 51
6 --------------------- 62(5)
The 5 in the brackets sometimes is there, sometimes it's not....
When leaving it idle while testing the actual output it sometimes starts spamming 5s, "as it should" since it 's the key output from the debug println above, but not before scrambling through other numbers.
In other cases it continues outputting random numbers. I have observed that it is relevant with the position of the teensy but I have not reached a concrete scenario and I couldn't find any potential shortages in my solders.
I also tried playing around with the pinmodes - result was either the same or nothing was returned.
Thanks in advance. Any help is highly appreciated.
First of I want to share that I have experience with programming but zero of it with microcontrollers, so I apologise beforehand for any stupid mistakes.
I want to make a simple keyboard matrix of 6 buttons to work, but the output I am getting from the teensy seems random to me.
I am using pins 3-7. I was using the ones from 2-6 but I changed them in an attempt to solve the issue.
Pins 3-5 are columns. Pins 6 and 7 are rows.
This is the code. I also tried with Keyboard.send_now(). I am not using Keyboard.print() because later on I would like to use the keys for media controlls via HID codes.
Code:
#include <usb_keyboard.h>
int keyArray[] = {0x1E /*1*/, 0x1F /*2*/, 0x20 /*3*/, 0x21 /*4*/, 0x22 /*5*/, 0x23 /*6*/};
void setup()
{
//pinMode(13, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
}
void loop()
{
/* Testing code
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13, LOW);
delay(200);
*/
for(int i = 3; i <= 5; i++)
{
digitalWrite(i, HIGH);
for(int j = 6; j <= 7; j++)
{
if(digitalRead(j))
{
int index = (i - 3) * 2 + (j - 6);
//press
keyboard_keys[0] = keyArray[index];;
usb_keyboard_send();
delay(200);
}
else
{
//release
keyboard_keys[0] = 0;
usb_keyboard_send();
}
}
digitalWrite(i, LOW);
}
}
When I tried seeing what was idling with the below code it always returns the same button when I'm not pressing anything. i - 5, j - 6 - which corresponds to the bottom left button on the image.
Code:
Keyboard.println(digitalRead(j));
Keyboard.println(i);
Keyboard.println(j);
Here's an image of my soldering. Red numbers are pin numbers. White numbers are what is supposed to be output from the keys.
What is actually being output is this:
Expected output: --- Actual output:
1 --------------------- 13
2 --------------------- 24(5)
3 --------------------- 35
4 --------------------- 4(5)6
5 --------------------- 51
6 --------------------- 62(5)
The 5 in the brackets sometimes is there, sometimes it's not....
When leaving it idle while testing the actual output it sometimes starts spamming 5s, "as it should" since it 's the key output from the debug println above, but not before scrambling through other numbers.
In other cases it continues outputting random numbers. I have observed that it is relevant with the position of the teensy but I have not reached a concrete scenario and I couldn't find any potential shortages in my solders.
I also tried playing around with the pinmodes - result was either the same or nothing was returned.
Thanks in advance. Any help is highly appreciated.