I have set myself the challenge of writing an ESPHome Custom Component to work with the Scantronic 9940 or 9941 keypad.
The keypad was originally designed to work with the Scantronic range of alarm system control units, but if I link it into ESPHome and Home Assistant it could serve a number of purposes. The device has not only a numeric keypad, but also a 16x2 LCD display, an RFID tag reader, and some more LED lights, switches, and sensors.
I do not know if many others will be interested in such a specialised application (comments welcome below), but I would anyway like my code to be in line with ESPHome standards and conventions, and of course I would like to re-use any useful code that already exists! I am an experienced electronic engineer and C++ programmer, but this is the first time I would be contributing to an Arduino or ESPHome library. I am therefore looking for guidance from an experienced developer to help me navigate the plethora of documentation and source code available and point me in the right direction.
A few details known so far
I have no documentation so am reverse-engineering the protocol from the bottom up, starting with the data link layer as seen by a two-channel digital storage oscilloscope.
The device uses a proprietary synchronous data communication protocol over two wires – Data and Clock. It operates at 2KHz. The protocol is a little like I2C, but does not have exactly the same timings of data and clock, and has no ACK bit. It generally transmits 3 bytes at a time, whose functions I do not yet know – presumably something like the target keypad address, what data is being sent or is wanted, and the data itself.
It is not close enough to I2C to use the processors’s on-board hardware, which is what I assume the ‘Wire’ library does, so I will have to write the whole protocol in code, manipulating the GPIO high and low transitions directly.
Some kick-off questions
-
Since the data comm protocol is similar to i2c, I presume it would make sense to clone the ‘i2c’, ‘i2c_bus’ and ‘wire’ libraries by way of example, then give them new names - like ‘st994x’, ‘st994x_bus’, and ‘st994x_io’.
-
Since the protocol is going to be in software, there will be code inside (or underneath?) ‘st994x_io’ (the new ‘wire’) to do the actual read and write operations – is there a precedent for this?
-
I want the entities presented by ESPHome to be compatible with the relevant Home Assistant add-ons and integrations such as Display, Alarm keypad, and Tag Reader – how can I be sure that is the case? For example, do I treat each numeric key as a binary_sensor, or do I capture one character or all characters in an input_text entity?
-
Should I make a HA integration as well as the ESPHome component?
Thanks in advance of your guidance and ideas.