These are my first attempts at programming a Parallax Javelin Stamp.

Using I2C to talk to a Matrix Orbital LK202-25 20x2 LCD.

Using Serial UART to talk to a Matrix Orbital LCD2041 20x4 LCD.

I2C:

I'm still coming to grips with Java, so this code example is probably not the the best. Ideally, we need a Matrix Orbital class, so that we can do things like:

mo.cleardisplay();
mo.display("Hello World!");

which would cut down the code below in the talktoMO() routine by a lot.

//Talk to a Matrix Orbital LK202 LCD display via I2C
//Simply display "Hello" on the display

//import the I2C library
import stamp.core.*;
import stamp.peripheral.io.I2C;

public class MOtest
{
___public static void main()
___{
______CPU.nap(6); // one second delay - give MO time to initialise
______talktoMO();
___}

___static void talktoMO()
___{
______// create bus for I2C devices [SDA = pin0, SCL = pin1]
______I2C i2cBus = new I2C(CPU.pin0, CPU.pin1);
______i2cBus.start();
______i2cBus.write(0x50); //MO display address for WRITING to
______i2cBus.write(254); //Command to MO display
______i2cBus.write(88); //Clear the display
______i2cBus.write(72); // "H"
______i2cBus.write(101); // "e"
______i2cBus.write(108); // "l"
______i2cBus.write(108); // "l"
______i2cBus.write(111); // "o"
______i2cBus.stop();
___}
}

 

UART:

I discovered that using "system.out.print" isn't a good idea for talking to peripherals. You'll get garbage if you use hyperterminal or any Mac terminal - even if your baud rates are correct, etc.

There is a more powerful and flexible method - use the uart class. See below:

//Talk to a Matrix Orbital LCD2041 LCD display via a UART
//Simply display "Lennard Electronics www.lennard.net.nz" on the display

import stamp.core.*;
___public class MOserialtest
___{
______final static int SERIAL_TX_PIN = CPU.pin2;
______final static int SERIAL_RTS_PIN = CPU.pin3;

______static Uart txUart = new Uart( Uart.dirTransmit, SERIAL_TX_PIN, ______Uart.dontInvert,SERIAL_RTS_PIN, Uart.dontInvert, Uart.speed19200,Uart.stop1 );

______public static void main()
______{
_________CPU.delay(1000); //give the display time to initialise
_________txUart.sendByte(254); //send a command
_________txUart.sendByte(88); //command = clear the display
_________txUart.sendByte(254); //send a command
_________txUart.sendByte(84); //command = turn off block cursor
_________txUart.sendString("Lennard Electronics ");
_________txUart.sendByte(254); //send a command
_________txUart.sendByte(71); //command = place cursor
_________txUart.sendByte(1); //at the start of line 2
_________txUart.sendByte(2);
_________txUart.sendString("www.lennard.net.nz");
______} // end main
___} // end class declaration

Note: I'm connecting straight to the RS232 port of the display, therefore I'm going through a simple MAX232 based transciever.