Experiments with LCD03 4x20 LCD display and 12key keypad - using the i2c bus
Objective
Learn to drive the LCD03 and keypad from robot-electronics using the i2c option (RS232 is also possible)
The LCD03 carries a small daughter board that also connects to the keypad and the i2c lines
Tested on Debian nslu2 (Slug) - should also be OK on Sweex/Edimax routers etc using OpenWrt and OpenWrt Slug.
Method
I use the tools from i2ctools in lm-sensors
i2cget and i2cset to drive the LCD03 interface (they can be used on any Linux)
It should be possible to use "apt-get install i2c-tools" (originally part of the lm-sensors project)
for Debian Slug but mine refused to create i2cget - so I used the SVN to compile my own - very easy - see the README in the package.
The Blassic basic program below is a demonstrator to remind me how to use the LCD03 in future (!)
It shells to the bash script environment to run the i2cget and i2cset utilities.
If you press a key on the pad the number appears on the LCD and espeak speaks the value.
If you press # the program exits
#!/usr/sbin/blassic LABEL Again 'send the low and high bytes to the ramdisk then bring it into Blassic 'PRINT lo_byte$ IF lo_byte$ = "0x01" THEN key$ = "1": hex_key$ = "31" 'temporary exit - press # to stop the program IF lo_byte$ = "0x00" AND hi_byte$ = "0x00" THEN key$ = "no key pressed":hex_key$ = "7E" 'PRINT "key pressed is ",key$ 'send error reports below to stdout and then to null 'espeak always works but gives an error message - dump the message PAUSE 300 |
The ramdisk is used to transfer data from bash scripts to Blassic basic
I do mount -o size=2M -t tmpfs tmpfs /var/www/ramdisk in a startup script to create the ramdisk in memory
in -
i2cset -y 0 0x63 0x0 0x0C b > /dev/null 2>&1
-y stops the "are you sure" request
0 is the i2c dev number
0x63 is the i2c address
0x0 is the register address (anything sent to register 0 goes to the LCD)
0x0C is (in this case) the character to clear the screen (decimal 12) see this table
b means use bytes
2>&1 means 'send error messages to stdout' , > /dev/null dumps them
stah makes espeak say "star" with an english accent!
gud bye is "Goodbye"
A simple screen driver
Print a string of any length to the i2c LCD panel - top left corner is line-1/column-1, choose to clear the screen or not (1/0)
If the string is longer than a line it wraps to the next line
Example print_word.bas Hello 2 6 1 - print Hello at line 1, column 6, clear the screen first
#!/usr/sbin/blassic word$ = PROGRAMARG$(1) IF PROGRAMARG$(4) = "1" THEN SHELL "i2cset -y 0 0x63 0x0 0x0C" 'clear screen for character_number = 1 to word_length SYSTEM |