• Stars
    star
    348
  • Rank 121,840 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 8 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Companion repo for running examples against the luma.oled, luma.lcd, luma.led_matrix and luma.emulator display drivers.

luma.core | luma.docs | luma.emulator | luma.examples | luma.lcd | luma.led_matrix | luma.oled

Luma.Examples

https://github.com/rm-hull/luma.examples/workflows/luma.examples/badge.svg?branch=master

This is the companion repo for running examples against the luma.emulator, luma.oled, luma.lcd and luma.led_matrix display drivers.

Installation instructions

Assuming you are using a Raspberry Pi (running Debian Jessie or newer), follow the pre-requisites & instructions in the above repositories to wire up your display, then from a command-line:

$ sudo usermod -a -G i2c,spi,gpio pi
$ sudo apt install python3-dev python3-pip python3-numpy libfreetype6-dev libjpeg-dev build-essential
$ sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libportmidi-dev

Log out and in again and clone this repository:

$ git clone https://github.com/rm-hull/luma.examples.git
$ cd luma.examples

Finally, install the luma libraries using:

$ sudo -H pip install -e .

Running the examples

After cloning the repository, enter the examples directory and try running one of the following examples listed below. For example:

cd examples
python3 3d_box.py
Example Description
3d_box.py Rotating 3D box wireframe & color dithering
animated_gif.py Renders an animated GIF
bitstamp_ticker.py Display the Bitcoin price at Bitstamp
bitstamp_realtime.py Displays the latest Bitcoin trades in realtime at Bitstamp
bounce.py Display a bouncing ball animation and frames per second
carousel.py Showcase viewport and hotspot functionality
chroma.py Trippy color rendering demo
clock.py An analog clockface with date & time
colors.py Color rendering demo
crawl.py A vertical scrolling demo, which should be familiar
demo.py Use misc draw commands to create a simple image
dotmatrixtool.py Simple demo showing how to integrate output from http://dotmatrixtool.com
font_awesome.py A meander through some awesome fonts
game_of_life.py Conway's game of life
greyscale.py Greyscale rendering demo
image_composition.py Displays different song titles and scrolls them back and forth
invaders.py Space Invaders demo
jetset_willy.py Sprite animation framework demo
larson_hue.py Alpha blending color demo
matrix.py The Matrix
maze.py Maze generator
perfloop.py Simple benchmarking utility to measure performance
picamera_photo.py Capture photo with picamera and display it on a screen
picamera_video.py Capture continuous video stream and display it on a screen
pi_logo.py Display the Raspberry Pi logo (loads image as .png)
runner.py Sprite animation framework demo
savepoint.py Example of savepoint/restore functionality
scrolling_pixelart.py Image dithering and viewport scrolling
sprite_animation.py Using sprite maps for animation effects
starfield.py 3D starfield simulation
sys_histogram.py Display system information including a rolling histogram
sys_info.py Display basic system information
terminal.py Simple println capabilities
tv_snow.py Example image-blitting
tweet_scroll.py Using Twitter's Streaming API to display scrolling notifications
video.py Display a video clip
weather.py 3-day weather forecasts from the BBC
welcome.py Unicode font rendering & scrolling

By default, all the examples will asume I2C port 1, address 0x3C and the ssd1306 driver. If you need to use a different setting, these can be specified on the command line – each program can be invoked with a --help flag to show the options:

$ python3 examples/demo.py --help
usage: demo.py [-h] [--config CONFIG] [--display DISPLAY] [--width WIDTH]
                [--height HEIGHT] [--rotate ROTATION] [--interface INTERFACE]
                [--i2c-port I2C_PORT] [--i2c-address I2C_ADDRESS]
                [--spi-port SPI_PORT] [--spi-device SPI_DEVICE]
                [--spi-bus-speed SPI_BUS_SPEED]
                [--spi-transfer-size SPI_TRANSFER_SIZE]
                [--spi-cs-high SPI_CS_HIGH] [--ftdi-device FTDI_DEVICE]
                [--framebuffer-device FRAMEBUFFER_DEVICE] [--gpio GPIO]
                [--gpio-mode GPIO_MODE]
                [--gpio-data-command GPIO_DATA_COMMAND]
                [--gpio-chip-select GPIO_CHIP_SELECT]
                [--gpio-reset GPIO_RESET] [--gpio-backlight GPIO_BACKLIGHT]
                [--gpio-reset-hold-time GPIO_RESET_HOLD_TIME]
                [--gpio-reset-release-time GPIO_RESET_RELEASE_TIME]
                [--block-orientation ORIENTATION] [--mode MODE]
                [--framebuffer FRAMEBUFFER] [--num-segments NUM_SEGMENTS]
                [--bgr] [--inverse] [--h-offset H_OFFSET]
                [--v-offset V_OFFSET] [--backlight-active VALUE] [--debug]
                [--transform TRANSFORM] [--scale SCALE] [--duration DURATION]
                [--loop LOOP] [--max-frames MAX_FRAMES]

luma.examples arguments

options:
  -h, --help            show this help message and exit

General:
  --config CONFIG, -f CONFIG
                        Load configuration settings from a file (default:
                        None)
  --display DISPLAY, -d DISPLAY
                        Display type, supports real devices or emulators.
                        Allowed values are: ssd1306, ssd1309, ssd1322,
                        ssd1362, ssd1322_nhd, ssd1325, ssd1327, ssd1331,
                        ssd1351, sh1106, sh1107, ws0010, winstar_weh, pcd8544,
                        st7735, st7789, ht1621, uc1701x, st7567, ili9341,
                        ili9486, ili9488, hd44780, max7219, ws2812, neopixel,
                        neosegment, apa102, unicornhathd, capture, gifanim,
                        pygame, asciiart, asciiblock, linux_framebuffer
                        (default: ssd1306)
  --width WIDTH         Width of the device in pixels (default: 128)
  --height HEIGHT       Height of the device in pixels (default: 64)
  --rotate ROTATION, -r ROTATION
                        Rotation factor. Allowed values are: 0, 1, 2, 3
                        (default: 0)
  --interface INTERFACE, -i INTERFACE
                        Interface type. Allowed values are: i2c, noop, spi,
                        gpio_cs_spi, bitbang, ftdi_spi, ftdi_i2c, pcf8574,
                        bitbang_6800 (default: i2c)

I2C:
  --i2c-port I2C_PORT   I2C bus number (default: 1)
  --i2c-address I2C_ADDRESS
                        I2C display address (default: 0x3C)

SPI:
  --spi-port SPI_PORT   SPI port number (default: 0)
  --spi-device SPI_DEVICE
                        SPI device (default: 0)
  --spi-bus-speed SPI_BUS_SPEED
                        SPI max bus speed (Hz) (default: 8000000)
  --spi-transfer-size SPI_TRANSFER_SIZE
                        SPI bus max transfer unit (bytes) (default: 4096)
  --spi-cs-high SPI_CS_HIGH
                        SPI chip select is high (gpio_cs_spi driver only)
                        (default: False)

FTDI:
  --ftdi-device FTDI_DEVICE
                        FTDI device (default: ftdi://::/1)

Linux framebuffer:
  --framebuffer-device FRAMEBUFFER_DEVICE
                        Linux framebuffer device (default: /dev/fd0)

GPIO:
  --gpio GPIO           Alternative RPi.GPIO compatible implementation (SPI
                        interface only) (default: None)
  --gpio-mode GPIO_MODE
                        Alternative pin mapping mode (SPI interface only)
                        (default: None)
  --gpio-data-command GPIO_DATA_COMMAND
                        GPIO pin for D/C RESET (SPI interface only) (default:
                        24)
  --gpio-chip-select GPIO_CHIP_SELECT
                        GPIO pin for Chip select (GPIO_CS_SPI interface only)
                        (default: 24)
  --gpio-reset GPIO_RESET
                        GPIO pin for RESET (SPI interface only) (default: 25)
  --gpio-backlight GPIO_BACKLIGHT
                        GPIO pin for backlight (PCD8544, ST7735 devices only)
                        (default: 18)
  --gpio-reset-hold-time GPIO_RESET_HOLD_TIME
                        Duration to hold reset line active on startup
                        (seconds) (SPI interface only) (default: 0)
  --gpio-reset-release-time GPIO_RESET_RELEASE_TIME
                        Duration to pause for after reset line was made active
                        on startup (seconds) (SPI interface only) (default: 0)

Misc:
  --block-orientation ORIENTATION
                        Fix 90° phase error (MAX7219 LED matrix only). Allowed
                        values are: 0, 90, -90, 180 (default: 0)
  --mode MODE           Colour mode (SSD1322, SSD1325 and emulator only).
                        Allowed values are: 1, RGB, RGBA (default: RGB)
  --framebuffer FRAMEBUFFER
                        Framebuffer implementation (SSD1331, SSD1322, ST7735,
                        ILI9341 displays only). Allowed values are:
                        diff_to_previous, full_frame (default:
                        diff_to_previous)
  --num-segments NUM_SEGMENTS
                        Sets the number of segments to when using the diff-to-
                        previous framebuffer implementation. (default: 4)
  --bgr                 Set if LCD pixels laid out in BGR (ST7735 displays
                        only). (default: False)
  --inverse             Set if LCD has swapped black and white (ST7735
                        displays only). (default: False)
  --h-offset H_OFFSET   Horizontal offset (in pixels) of screen to display
                        memory (ST7735 displays only). (default: 0)
  --v-offset V_OFFSET   Vertical offset (in pixels) of screen to display
                        memory (ST7735 displays only). (default: 0)
  --backlight-active VALUE
                        Set to "low" if LCD backlight is active low, else
                        "high" otherwise (PCD8544, ST7735 displays only).
                        Allowed values are: low, high (default: low)
  --debug               Set to enable debugging. (default: False)

Emulator:
  --transform TRANSFORM
                        Scaling transform to apply (emulator only). Allowed
                        values are: identity, led_matrix, none, scale2x,
                        seven_segment, smoothscale (default: scale2x)
  --scale SCALE         Scaling factor to apply (emulator only) (default: 2)
  --duration DURATION   Animation frame duration (gifanim emulator only)
                        (default: 0.01)
  --loop LOOP           Repeat loop, zero=forever (gifanim emulator only)
                        (default: 0)
  --max-frames MAX_FRAMES
                        Maximum frames to record (gifanim emulator only)
                        (default: None)

Note

  1. python3-dev (apt-get) and psutil (pip/pip3) are required to run the sys_info.py example. See install instructions for the exact commands to use.
  2. At runtime, luma.core enumerates which display drivers are present and dynamically constructs the list of --display options, therefore (for example) the capture/gifanim/pygame options will not show unless luma.emulator is installed

Emulators

There are various display emulators available for running code against, for debugging and screen capture functionality:

  • The luma.emulator.device.capture device will persist a numbered PNG file to disk every time its display method is called.
  • The luma.emulator.device.gifanim device will record every image when its display method is called, and on program exit (or Ctrl-C), will assemble the images into an animated GIF.
  • The luma.emulator.device.pygame device uses the pygame library to render the displayed image to a pygame display surface.

After installing luma.emulator you can invoke the demos with:

$ python3 examples/clock.py --display pygame

or:

$ python3 examples/clock.py --display gifanim

$ python3 examples/starfield.py --display capture

Documentation

Full documentation with installation instructions can be found in:

License

The MIT License (MIT)

Copyright (c) 2017-2023 Richard Hull & Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

luma.oled

Python module to drive a SSD1306 / SSD1309 / SSD1322 / SSD1325 / SSD1327 / SSD1331 / SSD1351 / SH1106 OLED
Python
809
star
2

pifm

Copy of http://www.icrobotics.co.uk/wiki/index.php/Turning_the_Raspberry_Pi_Into_an_FM_Transmitter
C++
524
star
3

luma.led_matrix

Python module to drive LED Matrices & 7-segment displays (MAX7219) and RGB NeoPixels (WS2812 / APA102)
Python
519
star
4

nvd-clojure

National Vulnerability Database dependency checker for Clojure projects
Clojure
268
star
5

OPi.GPIO

RPi.GPIO drop-in replacement library for Orange Pi Zero and other SBCs
Python
185
star
6

luma.lcd

Python module to drive PCD8544, HT1621, ST7735, ST7567 and UC1701X-based LCDs
Python
157
star
7

luma.core

A component library providing a Pillow-compatible drawing canvas, and other functionality to support drawing primitives and text-rendering capabilities for small displays on the Raspberry Pi and other single board computers.
Python
148
star
8

programming-enchiladas

A ClojureScript-based HTML5 Canvas and SVG Graphics Playground, much like http://bl.ocks.org/ but specifically for showcasing small ClojuresScript code demos: The underlying agenda is to show how small simple functional programs can generate complex behaviour.
JavaScript
138
star
9

sql_graphviz

Generates graphviz commands to graphically display tables and show foreign key links.
Python
138
star
10

infix

A Clojure library for expressing LISP expressions as infix rather than prefix notation
Clojure
101
star
11

bme280

Raspberry PI schematics & python module to drive a Bosch BME280 digital sensor module
Python
96
star
12

spidev-test

C
88
star
13

big-bang

ClojureScript event loop abstraction, loosely based on Racket's big-bang and implemented on top of core.async
Clojure
66
star
14

barebones-toolchain

Barebones [ i686-elf / ARMv7-eabi / MIPS ] cross-compiler & toolchain
C
64
star
15

jasentaa

A parser combinator library for Clojure and ClojureScript
Clojure
60
star
16

wireframes

A lightweight 3D graphics rendering engine in Clojure & ClojureScript.
Clojure
60
star
17

byok

A bare-metal x86 Forth interpreter & compiler
C
54
star
18

skull-canyon

Notes on setting up Ubuntu 18.04 (Bionic Beaver) on Intel NUC6i7KYK
46
star
19

luma.emulator

Provides a series of pseudo-display devices which allow the luma.core components to be used without running a physical device.
Python
43
star
20

inkspot

A small Clojure/ClojureScript library for creating colour swatches
Clojure
39
star
21

lindenmayer-systems

An L-system or Lindenmayer system is a parallel rewriting system, namely a variant of a formal grammar, most famously used to model the growth processes of plant development, but also able to model the morphology of a variety of organisms. Clojure / Heroku.
Clojure
38
star
22

clj-wordnet

An interface to the WordNet database using idiomatic Clojure
Clojure
35
star
23

markov-chains

A library (and application examples) of stochastic discrete-time Markov Chains (DTMC) in Clojure
Clojure
31
star
24

st7735fb

Schematics and build info for assembling a custom Raspberry Pi kernel with ST7735 TFT-LCD framebuffer drivers
Python
28
star
25

k8055

Velleman k8055 linux driver and GUI sources for the Raspberry Pi
C
27
star
26

wam

Gradual WAM implementation using Hassan Aït-Kaci's tutorial reconstruction
Clojure
25
star
27

hmc5883l

Python wrapper class for HMC5883L magnetometer (using smbus I2c)
Python
22
star
28

clustering

Implementation of K-Means, Self-Organising Maps, QT and Hierarchical clustering algorithms, in Clojure.
Clojure
21
star
29

weatherstation

TypeScript
16
star
30

project-euler

Clojure solutions to Project Euler problems
Clojure
14
star
31

turtle

A logo-style turtle graphics library for Clojure & ClojureScript (renders to SVG, bitmaps & HTML5 Canvas)
Clojure
11
star
32

wiringPi

A fork of Gordon Henderson's git://git.drogon.net/wiringPi but with python bindings
C
10
star
33

corewar

A clojure / clojurescript / core.async implementation of A. K. Dewdney's Core War
Clojure
9
star
34

linux-journal-archive

Copy of the Linux Journal archives (issues 1–293)
HTML
8
star
35

local-cast

Stream local video/audio content to a Chromecast on your network
JavaScript
7
star
36

maze

Maze generator and solver, in ClojureScript with a HTML5 canvas
Clojure
7
star
37

turmites

A turmite is a Turing machine which has an orientation as well as a current state and a "tape" that consists of an infinite two-dimensional grid of cells. ClojureScript / HTML5 Canvas / Heroku.
Clojure
6
star
38

yalix

Seven LISPs in seven languages
Python
5
star
39

task-scheduler

Fork/Join task scheduling in Clojure
Clojure
5
star
40

luma.docs

Python
5
star
41

ars-magna

A multi-word anagram solver, based on the article "Anagrams and Pangrams" from The Armchair Universe
Clojure
5
star
42

byok3

A forth interpreter and compiler implemented in scala using typelevel/cats
Scala
4
star
43

ambages

A small prolog interpreter, implemented in Clojure.
Clojure
4
star
44

table

Display ascii tables for almost any data structure with ease.
Clojure
4
star
45

apds9960

Python
4
star
46

mcp23017

Schematics and build info for assembling a Raspberry Pi breakout board with multiple MCP23017 input/output port expanders
Python
3
star
47

jwi

(Mavenized version of) JWI 2.3.3
Java
3
star
48

zaup

TOTP authentication using ZeroSeg
Python
3
star
49

8-bit-trip

Algorithmic music streaming
TypeScript
3
star
50

helpmate

A Clojure library for emitting SGML (HTML,SVG,XML,MathML) fragments
Clojure
3
star
51

implicit-equations

A graphing library for implicit equations, in Clojure
Clojure
3
star
52

colorforth

cvs->git conversion of http://colorforth.cvs.sourceforge.net/viewvc/colorforth/colorforth/
Assembly
3
star
53

loose-labels

An implementation of "Nice numbers for graph labels" from Graphics Gems, vol. 1
Clojure
2
star
54

TR4-monitor

Small utility script to display TR4 system information on a 2.42" SSD1309 OLED
Python
2
star
55

treebank-viz

SVG graph generation of treebank language parsing
Clojure
2
star
56

zaup2

A TOTP authenticator for the web
TypeScript
2
star
57

newell-teapot

Shadow of ftp://ftp.funet.fi/pub/sci/graphics/packages/objects/teaset.tar.Z
C
2
star
58

image-preview

CLI takes in an image file, and using ANSI escape sequences, outputs a low-fidelity preview of the image in the terminal.
Rust
2
star
59

pysensors3

Python3 bindings to libsensors (via ctypes)
Python
1
star
60

rg-matrix

Python library to drive a 32x16 red/green LED matrix
1
star
61

vim-locate

A vim plugin that integrates the unix locate database
Vim Script
1
star
62

henry

HTML
1
star
63

glsl-transpiler

A ClojureScript to GLSL cross compiler ... probably
1
star
64

webrot

Clojure, Noir and Clojurescript toy implementations for mandlebrot, julia & sierpinski fractals
Clojure
1
star
65

sound-flour

An experiment in collaborative broadcast streaming computer-generated music, in Clojure
Clojure
1
star
66

polyhedra

A Clojure/Clojurescript library for reading netlib polyhedra data files
Clojure
1
star
67

boyer-moore-search

Boyer-Moore string search library in Clojure
Clojure
1
star
68

ods-search-appliance

A JSON full-text search endpoint API onto NHS ODS data
Clojure
1
star
69

kebab

An ad-scrubbing web proxy, focusing on subverting commercial tracking and other general panoptic shenanigans. [Scala / Play 2.1]
CSS
1
star
70

proliant-microserver

1
star
71

led-blaster

C
1
star
72

nostalgia

A trip back though some personal 1980's & 90's computing memorabilia
1
star
73

cellular-automata

Migrating from CA code in webrot into separate stand-alone project
Clojure
1
star
74

cljs-dataview

A ClojureScript library for asynchronously fetching & dicing remote binary objects
Clojure
1
star
75

dotfiles

Essentials pour le vim exigeants basés programmeur informatique agiotage
Vim Script
1
star
76

speedtest-logger

Broadband speedtest logger
JavaScript
1
star