Data entry from keyboard to PSOC

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
eeEn_4618901
Level 4
Level 4
5 likes given First like received First like given

Hi,

I want to input data from the keyboard to PSOC.

I want to load the information I enter from the keyboard into an array.

I want to print on the LCD screen from there too.

How can I communicate psoc with keyboard?

0 Likes
1 Solution
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Eemuh-san,

Please refer to

I2C Full Keyboard Sample (CardKb)

Best Regards,

26-Feb-2020

Motoo Tanaka

View solution in original post

14 Replies
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi,

Could you please specify what kind of inputs that your LCD screen support? Also you are using a USB keyboard correct? Does your application involves using a computer?

For I/O applications we recommend you to use UART component in PSoC. Please refer the code example CE195366 present in PSoC Creator itself.

Thanks

Ganesh

0 Likes

Hi,

I will connect to psoc with usb. There will be no computer. I am thinking of using LCD display.

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

Using a standard USB keyboard with PSoC 5LP may not be easy.

I've just tried to find USB HID samples, all I could find were for the mouse.

I've written a simple USB Keyboard program using other vendor's MCU and it was not easy,

but accepting an external USB Keyboard will be more difficult, IMHO.

Are you going to need all alphabet letters?

If you can survive with 4x4 (=20) or 5x5 (=25)  keys,

considering Matrix Keys would be more practical.

moto

Hi Moto,

Firstly, can I use 6x5 = 30keys?

So, is it possible for me to do with the keyboard connected to the computer?

Keyboards ==> Computer ==> PSOC

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear eeEn-san,

If you connect a PC between the keyboard and PSoC you can connect almost any keyboard.

My point was if you connect the keyboard or keypad directly to the PSoC via USB,

then it's going to be a challenging project.

So what we need to confirm  now is...

Which are you planning?

(1) Keyboard/Keypad === PC === PSoC

(2) Keyboard/keypad === PSoC === PC === (PC's) Keyboard

If you are going to do

(1) may be you can refer to my sample

tty_utils a utility sample for CLI type program

(2) please browse, something like

https://learn.adafruit.com/matrix-keypad?view=all

And find a matrix keypad you are going to use and let us know the product URL

so that we can be some help.

Best Regards,

13-Feb-2020

Motoo Tanaka

Hi;

I don't want to use a computer.

I want to use                Keyboard/keypad ==> PSoC

but I could not find a similar example project in this way.

0 Likes

If you need a simple solution - you need a keyboard that supports PS / 2

Solution Options:

SPIS block interface for PS2 keyboard

Board of PC2 keyboard for PSoC

a simpler Matrix Keyboard you will find by searching this forum:

Matrix Keyboard Solution

PSoC 4 Pioneer Kit Community Project # 054

lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I found an old 4x4 matrix keypad from my drawer.

So I created a quick-simple sample.

Although it's a 4x4 matrix, I hope that the idea is same for 5x5 or 5x6 or whatever you are going to use.

IMG_4132.JPG

schematic

Note: As you can see, this is a pretty dumb device, so the MCU must apply voltage to each ROWs and measure COLs.

So when ROW1_Write(1) and COL0_Read() == 1, SW_1 is pushed.

032-Schematic.JPG

I prepared a couple of arrays to hold key status key[NUM_ROW][NUM_COL]

and mapped letter for each key letter[NUM_ROW][NUM_COL].

So when key[0][3] == 1, print 'A' instead of 1.

You can configure any letter mapping(s) as you like.

======================

#define NUM_ROW 4

#define NUM_COL 4

volatile uint8_t key[NUM_ROW][NUM_COL] = { 0u } ;

uint8_t letter[NUM_ROW][NUM_COL] = {

    { '1', '2', '3', 'A' },

    { '4', '5', '6', 'B' },

    { '7', '8', '9', 'C' },

    { '*', '0', '#', 'D' }

} ;

======================

Pins

033-pins.JPG

Tera Term log

031-TeraTerm-keymatrix-5.JPG

main.c

==============

#include "project.h"

#include "stdio.h"

#define NUM_ROW 4

#define NUM_COL 4

volatile uint8_t key[NUM_ROW][NUM_COL] = { 0u } ;

uint8_t letter[NUM_ROW][NUM_COL] = {

    { '1', '2', '3', 'A' },

    { '4', '5', '6', 'B' },

    { '7', '8', '9', 'C' },

    { '*', '0', '#', 'D' }

} ;

   

volatile int row_no = 0 ;

volatile int col_no = 0 ;

void scan_key_matrix(void)

{

    switch(row_no) {

    case  0: ROW0_Write(1) ; ROW1_Write(0) ; ROW2_Write(0) ; ROW3_Write(0) ; break ;

    case  1: ROW0_Write(0) ; ROW1_Write(1) ; ROW2_Write(0) ; ROW3_Write(0) ; break ;

    case  2: ROW0_Write(0) ; ROW1_Write(0) ; ROW2_Write(1) ; ROW3_Write(0) ; break ;

    case  3: ROW0_Write(0) ; ROW1_Write(0) ; ROW2_Write(0) ; ROW3_Write(1) ; break ;

    default: ROW0_Write(0) ; ROW1_Write(0) ; ROW2_Write(0) ; ROW3_Write(0) ; break ;

    }

    switch(col_no) {

    case 0: key[row_no][col_no] = COL0_Read() ; break ;

    case 1: key[row_no][col_no] = COL1_Read() ; break ;

    case 2: key[row_no][col_no] = COL2_Read() ; break ;

    case 3: key[row_no][col_no] = COL3_Read() ; break ;

    }

   

    col_no++ ;

    if (col_no >= NUM_COL) {

        col_no = 0 ;

        row_no = (row_no + 1) % NUM_ROW ;

    }

    ROW0_Write(0) ;

    ROW1_Write(0) ;

    ROW2_Write(0) ;

    ROW3_Write(0) ;

}

CY_ISR(my_tick_isr)

{

    scan_key_matrix() ;

}

#define STR_LEN 64

char str[STR_LEN+1] ;

void print(char *str)

{

    UART_PutString(str) ;

}

void printc(char c)

{

    UART_PutChar(c) ;

}

void cls(void)

{

    print("\033c") ; /* reset */

    CyDelay(20) ;

    print("\033[2J") ; /* clear screen */

    CyDelay(20) ;

}

void splash(void)

{

    cls() ;

    print("5LP Timer 5Sec Test") ;

    snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;

    print(str) ;

}

void init_hardware(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    splash() ;

    CySysTickStart() ;

    CySysTickSetCallback(0, my_tick_isr) ;

}

void dump_key_matrix(void)

{

    int col, row ;

    for (row = 0 ; row < NUM_ROW ; row++) {

        for (col = 0 ; col < NUM_COL ; col++) {

            if (key[row][col]) {

                snprintf(str, STR_LEN, "%c ", letter[row][col]) ;

                print(str) ;

            } else {

                print("- ") ;

            }

        }

        print("\n\r") ;

    }  

}

int main(void)

{

    init_hardware() ;

    for(;;)

    {

        cls() ;

        dump_key_matrix() ;

        CyDelay(1000) ;

    }

}

==============

moto

Combined USB UART and HID Keyboard

Do you think this project will solve the problem?

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

The project makes your PSoC as a UART and a Keyboard from the viewpoint of the PC

but it will not let you connect an external keyboard.

Although it's depending on what you want to do with the keyboard,

IMHO, usually handling a USB keyboard is not an easy task.

Following URL is the USB HID source of Linux, please refer tree/root/driver/hid directory

hid\drivers - kernel/git/torvalds/linux.git - Linux kernel source tree

moto

Hi Motoo,

If Arduino can be operated with keyboard. I think it works in psoc too.

Keyboard PCB | Serial output | Alphabet Numbers Signs - YouTube

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi Eemuh-san,

Yes, I think that it will work with PSoC, too.

moto

P.S. OOPS, I forgot to mention,

needless to say (write) someone needs to write the driver program.

Meantime, keyboard like below may work, too.

M5Stack Official CardKB Mini Keyboard Unit MEGA328P GROVE I2C USB ISP Programmer for ESP32 Arduino D...

MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Eemuh-san,

Please refer to

I2C Full Keyboard Sample (CardKb)

Best Regards,

26-Feb-2020

Motoo Tanaka

Hi Motoo,

I also  ordered M5Stack  CardKB . Delivered approximately 15 days later.

when the cargo comes to me, i will try the project right away.

https://youtu.be/M6OcPC5g_eM   ==> another project

Best Regards,