serial event triggering an output state

sort of need a kick in the right direction on this. I have a electronics hardware background so designing boards and the like is easy for me. coding , not so much.

anyway..

I have a set of boards that has 10 buttons on it (5 of those are a joystick) that I will to control via a serial keypad command.

the keypad I designed for this task is based around a dafulai Key55b IC capable of supporting 25 keys (I am using 17 keys in this instance) all with individual addresses when the key is pushed. this IC also gives out a secondary address with the key released. my intent was to ignore that address and use the one the key gave when pushed. output from this board isstd TTL level serial at 4800 baud.

I have a mega2560 that I am trying to set this up on and would like this to happen:

press a key,issue a serial address then momentary toggle an output to ground or 5v (I am firing a transistor with this)

I am thinking triggering on a serial event is the go here but unsure how to go about it

I don't understand what data the Arduino will be receiving. Perhaps you can post some examples?

Posting a link to the datasheet for the keypad IC would be a big help.

Initial experiments using an Arduino Mega would be a good idea as it has three spare HardwareSerial ports.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

1. When you are sure that a pressed own key on your Keypad produces TTL-async code (8-bit character, 1-stopbit, no-parity) at 4800 bd, then connect it with MEGA in the following manner:

TX-pin of Keypad with RX1-pin of MEGA
RX-pin of Keypad with TX1-pin of MEGA
GND-pin of Keypad with GND-pin of MEGA

2. Upload the following sketch in MEGA

void setup()
{
    Serial.begin(4800);
    Serial1.begin(4800);

}

void loop()
{
    byte n = Serial1.available();
    if (n !=0)
    {
        byte x = Serial1.read();
        Serial.print(x, HEX);        //scan code/address value generated by a pressed down key
        if(x == 0x34)                 //an arbitrary comparison value
        {
            //take action
        }
    }
}

3. Press a key on your Keypad. Check that an 8-bit value has appeared on the Serial Monitor. Press down another key on the Keypad, observe that another 8-bit value has appeared on the Serial Monitor which is different from the previous one.

robin,

started there and that's how I worked out the addresses of this board. big help!!

GolamMostafa,

thanks!!

if all it is going to be is IF/THEN loops then I have this. I got lost in the forum posts thinking it was more complex.

Robin2:
I don't understand what data the Arduino will be receiving. Perhaps you can post some examples?

Posting a link to the datasheet for the keypad IC would be a big help.

Initial experiments using an Arduino Mega would be a good idea as it has three spare HardwareSerial ports.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

(had to make breakfast :slight_smile: )

ok.
mega will get serial from this IC - it has a TxD line only so no return data.
connections to the 2560 I have under control.
sheet I will need to attach as the link for it is no longer.
its basically a revised version of a 74c923 though except with serial out instead of BCD.
the basics page you linked was my first stop via google and that helped with getting the addresses of the 17 buttons I have this set up for. the joystick/encoder (which is 7 buttons) is a bit fussy but I can sort that now that I know what I am looking at.

will post the sheet for the IC in a bit as its on another machine.

You can interface Arduino with PS2 keyboards and mice. Walmart was selling PS2 kb+mouse for $12 last year.

chrrroger might get a real kick out of the hardware hacking section of this forum, they include software.

Here's a site with nice, well explained tutorials showing many down to the metal aspects dealing with Arduinos, including code. And just to be clear, it's not my site.
http://gammon.com.au/forum/index.php?bbtopic_id=123

GoForSmoke:
You can interface Arduino with PS2 keyboards and mice. Walmart was selling PS2 kb+mouse for $12 last year.

chrrroger might get a real kick out of the hardware hacking section of this forum, they include software.

Here's a site with nice, well explained tutorials showing many down to the metal aspects dealing with Arduinos, including code. And just to be clear, it's not my site.
Gammon Forum : Electronics : Microprocessors

thanks! will look at that.
as I said , my background is in hardware (EE from early 90s) and not really coding. the only coding I know is VB and machine code. so the foundation is there for this , I just need to work it out.

most of the stuff I do is automotive related as that was the angle I took when I finished my EE.

and yes I like breaking into things for the hell of it.

fyi the IC I am working with

DFL-KEY55B.pdf (79.1 KB)

Try this code and see what happens

void loop() {
   if (Serial1.available >=1 ) {
      byte keyByte = Serial1.read();
      Serial.println(keyByte, BIN);
   }
   delay(300); // to slow things down for testing
}

You should see a different value for each key, and for keys being pressed and released.

Keep in mind that leading zeros won't be displayed.

...R

Robin2:
Try this code and see what happens

void loop() {

if (Serial1.available >=1 ) {
      byte keyByte = Serial1.read();
      Serial.println(keyByte, BIN);
  }
  delay(300); // to slow things down for testing
}




You should see a different value for each key, and for keys being pressed and released.

Keep in mind that leading zeros won't be displayed.

...R

that one generates an error on compile actually.

I understand what you are showing though and in binary as well.
Hex is fine for what I am doing.

there was a code snippet I picked up a few days back that worked and I could toggle number format on. the only variance was the delay line.
if I read this correctly that should fix the erratic numbers coming off the joystick. (assumption here)

(side note one of the items that is also in this same design uses a 32bit binary code - Hex numbers are FAR easier on that one.

Ok
design error on my part. all the keys pop up and I think I worked out my joystick/encoder issue.(I screwed up so it's a rework of a board.)

so all of the buttons should be easy. set the variables for the buttons then set them in a if/then loop and a digital write twice with a delay between to the appropriate pin to change state high/low.

correct?

the code above provided by GolamMostafa works for one button toggle

(text dump follows) - $=HEX

BUTTONS

VOICE: $21
SET: $26
'+': $2B
'-': $30
MFD/NAV :$20
DISP:$25
RET: $2A
MENU: $2F
MODE: $34

JOYSTICK
ENC UP: $38
ENC DN: $2E
JOY UP: $23
JOY DN: $28
JOY RT: $

**scratch pad **

382EB8AE - ENC UP
2E38AEB82E38AEB8 - ENC DOWN
JOY RT: 3768B7E8
JOY LT: 286DADE8

If you can find an old analog stick or rewire a new one, you could have an analog stick. The best stick I had was optically encoded, second best has a magnet that gets turned under a single-axis linear Hall sensor, worst used pots.

chrrroger:
that one generates an error on compile actually.

If you post the complete program that caused the error and the error message I will try to help.

...R

been away for a few days.

Robin,
the initial code you provided to decode the key addresses is what I was referencing.
(I will get the error for you once I get back on that machine.)

one of the annoying bugs I am dealing with on the joystick looks to be key bounce as the other 10 keys are constant. this means I may set this up another way yet.
going to persevere with the current design for a bit before i pull out a bigger hammer.

chrrroger:
Robin,
the initial code you provided to decode the key addresses is what I was referencing.

The code I posted in Reply #8 is not a complete program - I assume you know how to add the missing bits.

...R