Keyboard entry doesnt work

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

cross mob
Anonymous
Not applicable

Hello guys,

   

Thought my task would be easy, but I cant get any keyboard entry with my PSoC 5LP.

   

I tried scanf and getchar, nothing is working. I thought, with getchar() my code would stop until I press any key, but my code somehow just skips the command.

   

Any experiences with Creator and keyboard entries?

   

Thanks in adance,

   

Alexander

0 Likes
18 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Alexander,

   

a bit more information required: What kind of Keyboard are you using?

   

Which PSoC board? CY8CKIT-050?? Any external connections made? Which??

   

Project workspace Bundle available?

   

And: getchar() is afaik an operating system call and needs some support in GCC to work correctly.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Sure, firstly I want something like "press 1 to go to options, press 2 to ..." Just to choose between different options. Secondly I want to type in some values for my measurement. Just using the keyboard of my computer. In the future I want to connect some external keypad to my PSoC CY8CKIT-058 (building up a handheld device), but currently it would be sufficient just to use the computer keyboard.
What do you mean by support of GCC to get it working.

   

Regards, Alexander

0 Likes
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted
        StudentA, allegedly, connecting to PSoC requires PS2-type keyboard, the kind of old style with RS232 output. Its output need be further level-matched to PSoC TTL level using something like MAX232. Before connecting to PSOC I suggest plugging it to PC and inspect output using a terminal. As you described you goal, there may be a shortcut. Get Arduino 4x4 keypad ($1 eBay) and connect it to PSoC using Bob Marlowe's keypad component http://www.cypress.com/forum/psoc-5-known-problems-and-solutions/matrix-keyboard-solution   
0 Likes
Anonymous
Not applicable

Thanks for the reply, but the current problem is just, to type something in with my computer key board and show it via UART. If i try some code with getch() or scanf() with an simple C compiler, everthing is fine. But by using the commands in Creator, no success.

0 Likes
        Attached basic UART_Rx example, use it to test keyboard connection to PSoC. Once you get something working, modify code for your needs. Note that PS2 keyboard, +level-shifting are mandatory http://www.cypress.com/file/208726/download   
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Have a look into the CY8CKIT-059 (Typo?) the kitprog's usb-uart bridge uses pins P12_7 and P12_6, connect your UART to them.

   

Then you will read with  UART_GetChar() from your PuTTY interface.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

yes  -059 is right. It was never a problem with the connection or the UART itself. Maybe my problem explanation wasnt clear enough, sorry for  that. Found out that my problem was the loop, I thought UART_GetChar() would wait for an keyboard input. Now I configured my loop, so problem one is solved. I used the switch-case-procedure for my option selection in the way of "press 1 to go to options, press 2 to ..."

   

But now comes the second problem. I am not able to type in some values. For example want to type in a frequency value of 30000 Hz via my keyboard. Any ideas??

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Usual approach is: Collect all chars (!=0) in a buffer. When receiving a terminator as \n or \r insert a 0x00 into the buffer and your input string is ready. Challenge is to allow for backspaces. Remember that PuTTY is able of processing VT100 cursor positioning commands. There is always something to program...

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I dont understand a word, do you have some code pieces?

0 Likes
        Look for the complete project posted above. It is based on Bob Marlowe's description on handling UART on PSoC. If you are not able to make it run, any further handwaving is pointless.   
0 Likes
Anonymous
Not applicable

If I look into www I always find scanf() for keyboard inputs. Works fine with every C compiler. Except Creator, there must be some trick to use scanf() in Creator. Thought it is basic C ?!

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

scanf() is there for you and does work, but your problem seems to be to get the string to scan. In the embedded world there is no default input device, you have to provide that.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

ok, so the following example should work. Am i right with the code guys?

   

int i;          

   

scanf("%d",&i);                 //my typed value is stored in i

   

sprintf(TransmitBuffer, "Eingabe: %d", i); 

   

UART_1_PutString(TransmitBuffer);    //i is shown via UART on my Putty.

   

 

   

So sprintf and UART stuff works fine, on my screen I just see: "Eingabe:0" I am not able to type something in, do I need a loop or where is my mistake?
 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

scanf() reads from a device named stdin supported by an operating system. Since you have got none, you need to use another member of the scanf-family: sscanf(). Have a look into the C-manual here. So what you need at first is a means to get the characters you type into PuTTY which are sent to your UART into a string. Use this string with sscanf() to convert the string to the required value.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Understood, but my question is exactly how to get the characters I typed into putty via UART to my psoc.

   

Maybe a loop with getchar() where psoc can assemble the single characters to a whole value?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The answer is exactly what I wrote in the post you commented with "I dont understand a word".

   

 

   

Bob

0 Likes
Anonymous
Not applicable

oh ok 😉 thanks, I will try it.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is some information on using C and programming Psoc types of Computers. http://www.cypress.com/blog/psoc-creator-news-and-information/matts-tips-embedded-programming-c-begi...

0 Likes