NOTE: If you plan on using the TWIDisplay 8-digit LCD display with the Arduino IDE or with avr-gcc, there is a ready-made library available. See here for details.

The TWI 7-segment Display defines a simple TWI protocol for easy interfacing. Connect SDA and SCL to the corresponding SDA and SCL pins on your microcontroller. The TWI protocol requires pull-up resistors, 4.7k or 10k are usually good values, but for short cable runs it is usually sufficient to use the microcontroller's built-in pull-up resistors if available.

The display works as a TWI slave. The default slave address is 0x12. Writing bytes to the slave address activates the display.

Bytes with values between 0x00 and 0x79 (that is, all 7-bit ASCII values, with MSB 0) either print the corresponding ASCII table character to the display, or print a space character if the character cannot be printed or is not available.

When a display character is sent, the display changes immediately (there is no pre-buffering) and the display will stay in the same state until another command or character is sent.

All bytes with values between 0x80 and 0xff (that is, all 8-bit values with MSB 1) are reserved for commands. Any command not available is treated as a nop and has no effect.

Examples:

To Write "abcd": Send bytes 'a' 'b' 'c' 'd'
To Write "10.43": Send bytes '1' '0' '4' '3' 0x85 (set dots) 0x04 (dot 2 on)
To Write "- -": Send bytes '-' 0x89 (set position) 0x04 '-'
To clear the display: Send byte 0x82 (clear display)
To set the display to half brightness: Send bytes 0x80 (set brightness) and 127 (half brightness)

Character set (0x00 - 0x80)

Digits from 0-9 (and A-F for hexadecimal) and all letters A-Z as well as simple punctuation such as '-' is available. Any character not available will print as a space character.

0x00 - 0x0f: Displays a single digit 0-9 or hexadecimal digit A-F.

0x0g - 0x79: Display a character on the display. For instance, sending 'a' will display a lowercase letter 'a', sending an 'E' will display an uppercase E. Some characters have no difference between uppercase and lowercase. Punctuation marks - _ ' and "" are also available. All other characters are undefined, and will display as a space.

Command set

All bytes from 0x80 to 0xff are reserved for commands. Some commands are followed by additional data in the form of one of more bytes. For such commands, be sure to send all expected bytes, otherwise the display will be stuck in an invalid state.

0x80 (brightness): Set brightness. Send this command followed by a byte describing the desired display brightness from 0 (display is off) to 255 (display at maximum brightness)

0x81 (slave addr): Change slave address. Send this command followed by a new TWI slave address. The valid address range is 0-127 (7-bits). If an invalid address is sent, it will be ignored.

After changing the address, it is neccesary to toggle power to the device: Once the address has been successfully changed, the display will only respond by its new address. To see which address the display currently has, connect VCC and GND only and wait for a few seconds. The display will show its current address.

0x82: Clear the display

0x83 <1 or 0>: Set scroll mode. Send this command followed by a byte of the value 0 to set ROTATE mode (this is the default on power-on), or a byte of the value 1 to set SCROLL mode.

In ROTATE mode, the first character sent goes to the first position (leftmost), the second character to the second position, the third character to the third position and the forth character to the forth position. Once the fifth character is received, the position will rotate around back to the first position and overwrite whatever is there.

In SCROLL mode, each character written will force the existing characters to scroll to the left. This is useful for scrolling long strings across the screen: Just send one character at a time with a suitable delay, and the message will scroll.

Example: Sending "ab" to the display in rotate mode: "ab " is displayed. Sending "abcd" to the display in rotate mode: "abcd" is displayed. Sending "abcde" to the diplay in rotate mode: "ebcd" is displayed. Sending "ab" to the display in scroll mode: " ab" is displayed. Sending "abcd" to the display in scroll mode: "abcd" is displayed. Sending "abcde" to the display in scroll mode: "bcde" is displayed.

Sending the clear command always resets the display cursor back to position 1.

0x84 (custom character): Display custom character. Send this command followed by a byte describing which segments to turn on and off. Segments are numbered from A to G: A 1 siginifies that a segment is on, and a 0 signifies that it is off. The MSB (bit 7) maps to segment A. Segments B to G are mapped to bits 6 to 2 respectively. The LSB maps to the dot next the the character.

NOTE: Setting a custom character in any position overrides the setting for the dot in that position.

The character sent behaves exactly as sending a normal character (so ROTATE and SCROLL mode works as expected)

0x85 (dots): Set dots. Send this command followed by a byte that describes the state of the four individual dots on the display. Dots are numbered from left to right.

Bit 7~4: don't care (ignored) Bit 3: Dot 1 Bit 2: Dot 2 Bit 1: Dot 3 Bit 0: Dot 4

For example, to set dots 1 and 3, send (1<<3)|(1<<1).

0x86: Reserved for future use.

0x87 <hour, minute, seconds): Set time. This is a convenience function to use for using the display to indicate time. Hours and minutes are displayed, and the middle dot is used to indicate seconds (with the dot on for even seconds, off for odd).

Send this command followed by three bytes: hours, minutes and finally seconds. Any contents currently in the display will be cleared automatically, so it is not neccesary to send a clear command.

This command is not affected by scroll mode setting.

0x88 <lsb msb): Display 16-bit integer. Send this command followed by two bytes. The first byte send is LSB, the second MSB. The value displayed in the display is (MSB<<8) + LSB

0x89 <pos): Set position. Send this command followed by two bytes to set the position for the next character to display. This command is ignored when in SCROLL mode.

0x8a: Get firmare revision. Currently returns 1, and all commands described here are available in firmware revision 1.

0x8b: Get number of digits. Returns 4.