ST7032Display
- class quanser.devices.interfaces.ST7032Display
A Python wrapper for the Quanser Devices API interface to Sitronix ST7032 displays.
Example
>>> from quanser.devices import ST7032Display >>> display = ST7032Display()
- close()
Close the display.
Example
>>> from quanser.devices import ST7032Display >>> display = ST7032Display() >>> display.open("i2c-cpu://localhost:8?address=0x3E,baud=400000") >>> ... ... >>> display.close()
- open(uri)
Opens the ST7032 (or NewHaven NHD-C0216C0Z) display.
Example
>>> from quanser.devices import ST7032Display >>> display = ST7032Display() >>> display.open("i2c-cpu://localhost:8?address=0x3E,baud=400000") >>> ... ... >>> display.close()
- printText(line, column, message, length)
Print to the display.
- Parameters
line (int) – The line where the message will be displayed. Line 0 is the first line.
column (int) – The column where the message will be displayed. Column 0 is the first column.
message (string) –
The message to display. Unrecognized characters are skipped. If more than 16 characters would be printed on a line then the line is truncated. A newline will cause the characters to be displayed on the next line. As there are only two lines on the display there should only be one newline in the format string. Printing starts at the given line and column. Line 0 is the first line and column 0 is the first column.
The format string is UTF-8 and does support Unicode (particularly, Katakana characters).
length (int) – The length of the message.
Example
Print ‘Hello, World!’ to the top, left corner of the display.
>>> from quanser.devices import ST7032Display >>> display = ST7032Display() >>> display.open("i2c-cpu://localhost:8?address=0x3E,baud=400000") >>> message = "Hello, world!" >>> display.printText(0, 0, message, len(message)) >>> ... ... >>> display.close()
- setCharacter(code, pattern)
Defines the character associated with the given character code.
- Parameters
code (int) – Defines the character associated with the given character code. Valid character codes are 0x10 to 0x17 i.e., ‘’ to ‘’. Using these characters will produce the bitmap defined in the pattern for that character.
pattern (bytes) –
The pattern defines each line of the character being defined, with the five bits in each byte defining the pixels of that line. For example to define the letter T, the pattern would be:
pattern = b’@@@@@@'
0b00011111 () 0b00000100 (@) 0b00000100 (@) 0b00000100 (@) 0b00000100 (@) 0b00000100 (@) 0b00000100 (@) 0b00000000 () <= should generally be zero to allow for cursor Note that only bits 0-4 are used. Bit 0 is the rightmost pixel and bit 4 is the leftmost pixel.
Examples
Print a custom character with three lines along the top, middle and bottom.
>>> from quanser.devices import ST7032Display >>> display = ST7032Display() >>> display.open("i2c-cpu://localhost:8?address=0x3E,baud=400000") >>> character_code = 0o20 >>> pattern = b'' >>> display.setCharacter(character_code, pattern) >>> message = str(chr(character_code)) >>> display.printText(0, 0, message, len(message)) >>> ... ... >>> display.close()
Print a pair of custom characters that give the appearance of a wifi signal strength indicator.
>>> from quanser.devices import ST7032Display >>> display = ST7032Display() >>> display.open("i2c-cpu://localhost:8?address=0x3E,baud=400000") >>> character_code_left = 0o20 >>> pattern_left = b'' >>> character_code_right = 0o21 >>> pattern_right = b'' >>> display.setCharacter(character_code_left, pattern_left) >>> display.setCharacter(character_code_right, pattern_right) >>> message = str(chr(character_code_left)) + str(chr(character_code_right)) >>> display.printText(1, 1, message, len(message)) >>> ... ... >>> display.close()