Quantcast
Channel: routerboard – IO Digital Sec
Viewing all articles
Browse latest Browse all 15

Using picolcd on linux, lcdproc, routerboard, liblcdusb

$
0
0

I’ve posted previously about my embedded device and picolcd. I wanted to put some thoughts down about using picolcd.

The easiest way to drive your picolcd is with lcdproc I’ve found. The device doesn’t require any special drivers which is great, as long as you have USB support working you’re fine. Make sure uhci-hcd and usbcore are loaded, you should be able to use ehci-hcd as well as it supports USB 1.1 and 2.0 but I haven’t tested that.

Use lsusb to make sure that the device is shown and recognised. If you see:

    Bus 002 Device 003: ID 04d8:0002 Microchip Technology, Inc.

then great. Your device is connected, working and your machine supports USB.

Make sure that libusb and libhid are installed, and then grab a copy of: usblcd from: http://www.mini-itx.com/store/information/usblcd/usblcd-src-0.1.4.tgz, compile and install it.

Here’s some relevant parts of the documentation on using usblcd from the archive. It’s pretty complete and you should now be able to use usblcd to control your device. I’ll cover writing your own applications as well as using lcdproc further down, anyway, here’s the docs:

usblcd backlight [0|1]
turns on or off LCD screen backlight

usblcd  contrast [0-40]
set the contrast. 0 is maximum contrast and 40 minimum

usblcd led [led number] [0|1]
turn on/off one of the front panel leds (1-8)

usblcd clear
clears LCD screen

usblcd text [row:0-1][column:0-19]
prints text on LCD screen starting with row and column

usblcd splash [filename]
sets the splash screens content from filename.
Samples of splash files are located in doc/ directory. After the splash file has been loaded into EEPROM the usb lcd should be restarted by reconnecting it to USB port.

Example of a splash file:

# Splash file must have :splash as header.
# Current compiled version support 2 lines of 20 characters each
# Number of lines/columns can be changed in driver.h
#
# Format is:
# (minutes) (seconds)
# Text Line 1
# Text Line 2
# (minute) (seconds)
# Text Line 1
# Text Line 2
:splash

00 05
12345678901234567890
12345678901234567890
00 15
12345678901234567890
12345678901234567890
00 25
12345678901234567890
12345678901234567890
00 35
12345678901234567890
12345678901234567890
00 45
12345678901234567890
12345678901234567890

usblcd setfont [filename]
overwrite the first 10 characters from LCD CG-RAM with the characters from filename.

usblcd flash [filename]
write the firmware from filename into EEPROM

usblcdread
read events (key press and infrared data) and outputs to stderr
This data can be piped and parsed by another application.

Format is: KEY: <key1> <key2>
For keyboard events <00> <00> means key release or more than 2 keys pressed at the same time.

wait [seconds]
wait for a number of seconds before executing the next command

Examples
——–

usblcd led 1 1 wait 1 led 2 1 wait 1 backlight 1 contrast 0 text 1 2 “mini-box.com USB LCD” read
This will lightup first led then wait 1 second, light the second led and wait 1 second, will turn backlight on, set the contrast to maximum, write the “mini-box.com USB LCD” text to second row starting from third column, and will continue printing events till closed with CTRL+C or SIGTERM

For more examples see the examples directory.

Now that we’ve got used to usblcd, we can move on to building our own application on libusblcd. Take a look here: http://resources.mini-box.com/online/picoLCD%2020×2%20(OEM)/Documentation/libusblcd-development-guide.txt for the full function set, but here’s a simple example in C to get started with:

#include <stdio.h>
#include <unistd.h>
#define SLEEP_FOR 2

int main(int argc, char **argv)
{
    usblcd_operation *picolcd;
    if (argc == 2)
    {
        picolcd = new_usblcd_operations();
        picolcd->init(picolcd);
        picolcd->backlight(picolcd,1);
        picolcd->settext(picolcd, 0, 0, argv[1]);
        sleep(SLEEP_FOR);
        picolcd->backlight(picolcd,0);
        picolcd->close(picolcd);
    } else {
        printf("Usage is: %s <text>n", argv[0]);
        return 1;
    }
    return 0;
}

Make sure that you compile with -lusblcd and you’ll be on your way.

Lastly, I’m not going to go too far into the lcdproc project, they have a great informative site and it’s pretty simple to get working. Suffice to say, it works perfectly with picolcd! It also seems to run and respond a lot faster than libusblcd


Viewing all articles
Browse latest Browse all 15

Trending Articles