This is a user interface consisting of a 16x2 lcd display and a 16 way touch keypad. Ideal for connecting to a host to use as a front panel. It has an I2C interface and so only two wires are required from the host. The keypad is also buffered so that the host does not need to constantly monitor the keys.
The LCD screen has a protective coating which is not obvious, remove for a clearer display
- Data sheet
- Data sheet for the LCD controller, can be directly accessed with command 31
- Overlay samples (png & Inkscape )
- Raspberry Pi
- FAQ & Tips
- EEPROM utility (python for the RPi)
- Purchase <Byvac Shop> <eBay shop>
- BV4242 Library and samples - version 1.05
The above zip file has a selection of examples and the library itself:
void clrBuf(); Clears / resets the keypad buffer, the buffer is 79 bytes big
uint8_t keysBuf(); Returns the number of keys in the buffer
uint8_t key(); removes and returns the key in the buffer, if no key, returns a 0
uint8_t keyIn(uint8_t k); See if 'k' is in the buffer, 0 if not or a number representing its position in the buffer
uint8_t scan(); Returns the scan code if a pad is being touched, if no pad being touched then returns 0
void avg(uint16_t *b); Supply a buffer 8 integers big and this will return the 8 averages from each channel
void delta(uint16_t *b); Supply a buffer 8 integers big and this will return the delta value for each channel. The delta value is the difference between an average value and the touched value, if no pad is thouched the delaa value will therefore be 0
void EEreset(); Resets all EEPROM values back to their defaults
void sleep(); Shuts down device to save power, can only be awakened with a reset or I2C activity. NOTE the keypad will not respond when in sleep mode.
NOTE: Values written to the EEPROM will not take effect until the device is reset. For what the values mean consult the data sheet in the Device Parameters section.
void trigger(uint16_t value); Write a new trigger value to the EEPROM
void hyst(uint8_t value); Writes a new hysteresis value to EEPROM
void keyPtr(uint8_t value); Writes a new key pointer value to EEPROM
void keySize(uint8_t value); Writes a new key table size value to EEPROM
void debounce(uint8_t value); Writes a new debounce value to EEPROM
void repeat(uint16_t value); Writes a new repeat key value to EEPROM
void timebase(uint8_t value); Writes a new timebase value to EEPROM
void defaultBL(uint8_t value); Writes a new default back light value to EEPROM
void EEwrite(uint8_t adr, uint8_t value); Writes a value to the specified EEPROM address
uint8_t EEread(uint8_t adr); Reads an EEPROM value at the specified address
uint16_t ID(); Gets the device id number as an integer, in this case 4242
void Version(uint8_t *b); Gets the firmware version as two bytes
The LCD secion uses exactly the same function names as used in the LiquidCrystal library and so will not be repeated here. There are however a few extra functions listed
void lcd_mode(uint8_t mode); The default is 0 which is a 16 x 2 line display, set this to 1 and the display will be 16 x 1 line with double height characters.void bl(uint8_t v);
void lcd_reset(); Sends a reset to the LCD display
void lcd_contrast(uint8_t m); The contrast is a value between 0 and 63 and will require changing depending on the voltage used. The default value is held in EEPROM and is set to about 45 which is right for 3.3V. 5V requires about 25.
void lcd_startMsg(); This simply displays the message stored in EEPROM
Use the device exactly as any other I2C device, wiring:
|3.3V (or 5V)||V+|
Start off with 3.3V as the contrast is set for 3.3V (see FAQ).
Unzip the library file and try one of the examples.
This should not really be necessary but it is there is a utility that will display all of the channel average and delta values. Tuning details are covered in the data sheet.
This is a normal I2C device that can easily be used with Python. Connect and use i2cdetect to make sure it is connected okay.
pi@raspberrypi ~ $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- UU -- 3d -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@raspberrypi ~ $
The address is 0x3d as shown. Just to get a feel of how it works i2ctools can be used:
- i2cset -y 1 0x3d 31 1 // clears the LCD screen by sensing command 1
- i2cset -y 1 0x3d 32 65 // prints 'A' to the display
- i2cget -y 1 0x3d 3 // gets a key from the keypad buffer
On the last command "i2cget -y 1 0x3d 3" if it returns 0, touch a key and send the command again, you will see that the key value will now be fetched.
There is a utility that is already compiled called bv4242_lcd, this is entered at the command line with the following parameters:
bv4242_lcd <i2cAddress> <row> <column> "text"
The utility will also return any keys that are in the buffer, so touch the keypad a couple of times before sending. As an example to write "Hello" to the second line of the display
./bv4242 0x3d 2 1 "Hello"
The tuning utility is also run from the command line and will show the average values for each channel along with the delta values. When a key is touched the delta values will change for the channel that is being effected.
bv4242_tune <i2caddress> <count>
Count is the number of times the average and delta are displayed. For example to run the program with 10 counts:
./bv4242_tune 0x3d 10
Actual output - finger placed on one of the keys shows the delta value changing from 0. The amount of change is determined by the physical environment. More tuning details can be found in the data sheet.
Raspberry Pi BV4242.o Library
There is a C library very similar to the Arduino library and so will not be repeated here. It relies on WiriingPiI2C and so that will need installing. Once installed the supplied files can be compiled if required. To see how to use the library follow the bv4242_lcd or bv4242_tune examples.
gcc -lwiringPi -c -o bv4242.o bv4242.c // this will create a bv4242.o library
gcc -lwiringPi -o myProgram myProgram.c bv4242.o // this is to compile your own program
There is also a python class that can be incorporated into Python programs.
The program does use notSMB and so that will also be required. As an example the following is a Python interactive session at the command line.
Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bv4242 as b
>>> ui = b.BV4242(0x3d,1)
The ByPic driver and test program are on the ByPic website.
The keypad is designed as a front panel and comes with just a bare PCB, the front of which has the touch pads on. The idea is to create your own design to suit a particular project.
- Layouts examples - zip file
The layouts file contains an svg file. This can be opened and edited in inkscape which is free and rather good. The file contains some rough sketches and also two layouts that have been exported to the png files. Also in the zip file is a dxf file that is an accurate rendering for use in other programs.
Sticky backed glossy photo paper was used to produce the layouts that were made a bit oversized. When printed the rectangle hole for the LCD display was cut out so as to position the overlay.
This covered the PCB. The excess was cut off from the back.
Another good material is Vinyl but it is a bit thinner and so the PCB shows through. Clear sticky back material could also be used. The LCD rectangle could be left unprinted and stuck over the whole PCB, thus making it weather resistant.
The device will fit exactly onto this box: http://www.ebay.co.uk/itm/PLASTIC-BOX-ENCLOSURE-CASE-HOBBY-ELECTRONIC-PROJECT-ABS-E76-/130738084288
There is also the dimension, dxf drawing in the overlay and samples zip file above. From the back of the PCB to the back of the display is 6mm, the connecting pins protrude for 10mm.
- The display just has white squares like this:
This is because the contrast is set in the EEPROM for 3.3V, it will need adjusting via the I2C interface.
- LCD writing speed
To keep the power requirements to a minimum each letter takes about 5mS, this does not effect the display but is does effect how fast the I2C can read and write. When writing allow a delay 0f 5mS between each character.
- I2C Swamp
The device is constantly monitoring the keypad but the I2C has priority over this and will always be acknowledged. If the host is constantly reading or writing to the device then it will have less time to do its job. If it is necessary to respond quickly to a key pad touch then use one of the interrupt pins rather than poling the I2C.