Python Library

A library for driving the Pimoroni Micro Dot pHAT Raspberry Pi add-on.

This library creates a virtual buffer of unlimited size onto which you can write text and icons for scrolling around the Micro Dot pHAT display.

Methods are included for rotating and scrolling, plus writing text either kerned to one pixel spacing, or spaced to place one character per matrix.

microdotphat.clear()[source]

Clear the buffer

microdotphat.draw_tiny(display, text)[source]

Draw tiny numbers to the buffer

Useful for drawing things like IP addresses. Can sometimes fit up to 3 digits on a single matrix

Parameters:
  • display – Index from 0 to 5 of display to target, determines buffer offset
  • text – Number to display
microdotphat.fill(c)[source]

Fill the buffer either lit or unlit

Parameters:c – Colour that should be filled onto the display: 1=lit or 0=unlit
microdotphat.scroll(amount_x=0, amount_y=0)[source]

Scroll the buffer

Will scroll by 1 pixel horizontall if no arguments are supplied.

Parameters:
  • amount_x – Amount to scroll along x axis (default 0)
  • amount_y – Amount to scroll along y axis (default 0)
Examples:

Scroll vertically:

microdotphat.scroll(amount_y=1)

Scroll diagonally:

microdotphat.scroll(amount_x=1,amount_y=1)
microdotphat.scroll_horizontal(amount=1)[source]

Scroll horizontally (along x)

Will scroll one pixel horizontally if no amount is supplied.

Parameters:amount – Amount to scroll along x axis (default 1)
microdotphat.scroll_to(position_x=0, position_y=0)[source]

Scroll to a specific position

Parameters:
  • position_x – Desired position along x axis (default 0)
  • position_y – Desired position along y axis (default 0)
microdotphat.scroll_vertical(amount=1)[source]

Scroll vertically (along y)

Will scroll one pixel vertically if no amount is supplied.

Parameters:amount – Amount to scroll along y axis (default 1)
microdotphat.set_brightness(brightness)[source]

Set the display brightness

Parameters:brightness – Brightness to set, from 0.0 to 1.0
microdotphat.set_clear_on_exit(value)[source]

Set whether the display should be cleared on exit

Set this to false if you want to display a fixed message after your Python script exits.

Parameters:value – Whether the display should be cleared on exit: True/False
microdotphat.set_col(x, col)[source]

Set a whole column of the buffer

Only useful when not scrolling vertically

Parameters:
  • x – Specify which column to set
  • col – An 8-bit integer, the 7 least significant bits correspond to each row
microdotphat.set_decimal(index, state)[source]

Set the state of a _decimal point

Parameters:
  • index – Index of _decimal from 0 to 5
  • state – State to set: 1=lit or 0=unlit
microdotphat.set_mirror(value)[source]

Set whether the display should be flipped left to right (mirrored)

Parameters:value – Whether the display should be flipped left to right: True/False
microdotphat.set_pixel(x, y, c)[source]

Set the state of a single pixel in the buffer

If the pixel falls outside the current buffer size, it will be grown automatically

Parameters:
  • x – The x position of the pixel to set
  • y – The y position of the pixel to set
  • c – The colour to set: 1=lit or 0=unlit
microdotphat.set_rotate180(value)[source]

Set whether the display should be rotated 180 degrees

Parameters:value – Whether the display should be rotated 180 degrees: True/False
microdotphat.show()[source]

Output the buffer to the display

A copy of the buffer will be scrolled and rotated according to settings before being drawn to the display.

microdotphat.write_char(char, offset_x=0, offset_y=0)[source]

Write a single character to the buffer

Parameters:
  • char – The ASCII char to write
  • offset_x – Position the character along x (default 0)
  • offset_y – Position the character along y (default 0)
microdotphat.write_string(string, offset_x=0, offset_y=0, kerning=True)[source]

Write a string to the buffer

Returns:

The length, in pixels, of the written string.

Parameters:
  • string – The text string to write
  • offset_x – Position the text along x (default 0)
  • offset_y – Position the text along y (default 0)
  • kerning – Whether to kern the characters closely together or display one per matrix (default True)
Examples:

Write a string to the buffer, aligning one character per dislay, This is ideal for displaying still messages up to 6 characters long:

microdotphat.write_string("Bilge!", kerning=False)

Write a string to buffer, with the characters as close together as possible. This is ideal for writing text which you intend to scroll:

microdotphat.write_string("Hello World!")

Constants

WIDTH - The width of the physical display, including 3 hidden pixels between each matrix

HEIGHT - The height of the physical display