3C : Keypad I2C

Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.

Moderators: Benj, Mods

Post Reply
User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

3C : Keypad I2C

Post by Dan81 »

Hello

I'm still using "Customize Component Code" !

I like I2C protocol (sorry for other comms users), there are only 2 wires for this bus (and pull up) .

You can choose any keypad (allowed by Matrix, from 1x1 to 4x4, see Extended Properties).

The expander can be a MCP23008 or a PCF8574.

The only rule is to respect the schematic below :
Columns : from P4 to (P7 or less) ,
Rows : from P0 to (P3 or less).

Pull UP for rows are not needed , MCP and PCF have internal ones, Matrix Eblocks (EB-014) has pull DOWN resistor.

The simulation with Proteus is OK, as soon as the real test is done I'll post the code. I'm waiting for the keypad.
KeyPad.jpg
KeyPad.jpg (38.05 KiB) Viewed 28348 times
Daniel

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: 3C : Keypad I2C

Post by Spanish_dude »

I just want to add that you need to enable the pull up resistors first by sending 0xFF to the GPPU control register.

Cheers ;-)

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: 3C : Keypad I2C

Post by Dan81 »

Hello

I have created a new component macro "Init" where all the configuration of the expanser is done.
This macro must be put AFTER the "Init" of the I2C component. (the same thing like LCD I2C)

Daniel

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: 3C : Keypad I2C

Post by Dan81 »

How to use I2C Keypad.

INTRODUCTION

The pinout of MCP 23008 is more interesting than PCF8574 one

The "MCP version" is hard tested on a EB016 (prototype board). "PCF version" is only simulated on Proteus 7.8.

Note : I2C Keypad address (0x21) (different from I2C LCD :0x20).


TECHNICAL

For hardware the only rule is to respect the schematic given above.
The Pull Up resistors are not needed, they are "native" on the PCF, on MCP they are enabled during initialisation.

For the Software,
Choose your keypad as usual (1x1 to 4x4), the macros are identical (and simulable).

You must also add :
- a I2C component and its init macro.
- The Keypad init (a new macro called KP_init) AFTER the I2C init macro.

Note : I2C is only "Hardware" (by default in the properties).

Note2 : It is not necessary to provide a port for the keypad connection.


Remark :
- I have done the same thing for the Switch bank and Led array.
Attachments
Keypad_MCP.fcc
(8.22 KiB) Downloaded 1030 times
keypad_MCP-forum.fcf
Hard tested
(16.04 KiB) Downloaded 1159 times

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: 3C : Keypad I2C

Post by Dan81 »

The files for PCF8574 (not PCF8574A)
Attachments
Keypad_PCF.fcc
(7.39 KiB) Downloaded 999 times
keypad_PCF-forum.fcf
Simulation OK with Proteus7.8
(15.13 KiB) Downloaded 1157 times

Mouine
Posts: 10
Joined: Sun May 13, 2012 1:13 pm
Location: France
Contact:

Re: 3C : Keypad I2C

Post by Mouine »

Hello and congratulations for the work done,

I tried the i2c for the LCD and it works perfectly but is it also possible to have the macro file to the Switch bank and Led array.

Thank you very much in advance.

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: 3C : Keypad I2C

Post by Dan81 »

Hello Mouine

I think it is not useful to create spécial I2C macros for switches and leds.

You just have to read or write one register.

I find MCP easier to drive than PCF.

Daniel

Mouine
Posts: 10
Joined: Sun May 13, 2012 1:13 pm
Location: France
Contact:

Re: 3C : Keypad I2C

Post by Mouine »

Thank you for your reply,

I tested this several times but nothing doing. I'm not arrived to switch on the LED in output.

Image


I put the register 00 in output and then I send the information to switch the LED. Is this the right way to go or I all wrong?

Thank so much.

User avatar
Dan81
Valued Contributor
Valued Contributor
Posts: 268
Joined: Sun Jan 15, 2006 4:07 pm
Location: Albi France
Been thanked: 60 times
Contact:

Re: 3C : Keypad I2C

Post by Dan81 »

Hello Mouine

"Send_Byte_Transaction" macro is for EEPROM (with 16 bits address).
You must use "Transmit_Byte" macro.

Daniel

Mouine
Posts: 10
Joined: Sun May 13, 2012 1:13 pm
Location: France
Contact:

Re: 3C : Keypad I2C

Post by Mouine »

Hello,

After a hard battle, I finally managed to run the MCP23008 input and output.

As you say it, MCP is simple to managed it.

Thank you for your help.

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: 3C : Keypad I2C

Post by Jay Dee »

Hi, I'm really struggling to get a grip with component creation etc, Dan's i2C keypad component would be great but I just cant find a way to import it or any other file on the file system ending in .fcc so I don't know where to copy it too.
Something so simple is driving me nuts ( and this was going to be a time of year to relax!! )
Any pointers much appreciated. Thanks, J.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: 3C : Keypad I2C

Post by medelec35 »

Hi John,
Jay Dee wrote:Dan's i2C keypad component would be great but I just cant find a way to import it or any other file on the file system ending in .fcc
You can only import custom code (.fcc) with Flowcode V5 or below.
What you do is go to Misc Menu then select Custom.
A custom code icon will be added to the panel.
Right click on the custom code icon then select Custom Code.
Then you should see various options including Import.
That is how you import .fcc files

Martin
Martin

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: 3C : Keypad I2C

Post by Jay Dee »

Thanks for reply Martin.. for the life of me I cant find a Misc menu other that the one via component search and that does not have a custom code icon.
I found a Supplementary code tick box in project options and a C code component... but dont think its either of these.
I could not find a reference to custom code in the help.
I just upgraded to latest release.. but still no joy.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: 3C : Keypad I2C

Post by kersing »

Are you using Flowcode version 5 to import the code?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: 3C : Keypad I2C

Post by medelec35 »

Perhaps I should have said components menu?
Misc.png
(78.84 KiB) Downloaded 18361 times
Martin

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: 3C : Keypad I2C

Post by Jay Dee »

Hi, I'm back looking at i2c keypad..
Hmm..I still cant find the Custom icon, I'm running the pro version of 6.1.2 with PIC and PIC16 enabled, its not in the menu martin showed.. indeed that menu icon is called tools and there is no default Misc menu.
There is no custom component listed in the component Search or under any of the tabs...seems to have been removed from this version.. ?? :?
I can place a custom C code component but it does not have any import option.
:?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: 3C : Keypad I2C

Post by medelec35 »

Hi John,
Jay Dee wrote:There is no custom component listed in the component Search or under any of the tabs...seems to have been removed from this version.. ??
Custom component was removed with version V6
Reason for that is to allow user custom components to be created.
Screen shot shown with Custom & Custom2 is from Flowcode V5

This is mentioned on my post on Mon Dec 28, 2015 1:37 am:
medelec35 wrote: You can only import custom code (.fcc) with Flowcode V5 or below.
Also by kersing on on Dec 28, 2015 12:09 pm
kersing wrote:Are you using Flowcode version 5 to import the code?
Martin
Martin

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: 3C : Keypad I2C

Post by Jay Dee »

Oh.. thanks for the clarification. I'll have another look at the custom component videos, it all seems to be a bit 'black art'...

If I understand this right, I cant open custom code in V6, so Dans component is not compatible with V6, and if I wanted the functionality it offered I would need to start from scratch and create a new component.

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: 3C : Keypad I2C

Post by kersing »

Jay,

A component is basically just a collection of macros. If you have C code from a custom component, just create a macro for each of the functions in the custom component code and copy the C code to a C code icon inside that macro. You will probably need to 'rename' the function arguments in the C code from the original code to match the names Flowcode generates, but as you're able to 'insert' them from the list on the right that should not be too much of an issue.

Once you have created all macro's, go to the properties, select 'Interface manager' and set all macros to type 'Downloadable'. Now go to the file menu and export the component. That is all ;-)

Good luck,

Jac
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Post Reply