Giter VIP home page Giter VIP logo

luma.examples's Introduction

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
sys_info_extended.py Display detailed system information in graph format
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.

luma.examples's People

Contributors

dependabot-preview[bot] avatar ediflyer avatar jpoppe avatar matemaciek avatar mlos avatar ntnlabs avatar nvtkaszpir avatar rlaace423 avatar rm-hull avatar somu1795 avatar squeezeday avatar thijstriemstra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

luma.examples's Issues

Module requirements not installed for some examples

pi@devpi ~/l/examples> ./carousel.py
Traceback (most recent call last):
  File "./carousel.py", line 18, in <module>
    import psutil
ImportError: No module named psutil

Simple fix, but maybe it an be included in the installer?

pi_logo.py doesn't work?

pi@devpi ~/l/examples> ./pi_logo.py
Display: ssd1306
Interface: i2c
Dimensions: 128 x 64
----------------------------------------
Traceback (most recent call last):
  File "./pi_logo.py", line 36, in <module>
    main()
  File "./pi_logo.py", line 23, in main
    posn = ((device.width - logo.width) // 2, 0)
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 608, in __getattr__
    raise AttributeError(name)
AttributeError: width

I wonder what happened?

running second OLED screen on SPI1 example

I have two SSD1351 screens. I've tested them with code from Adafruit and they both are working. The first screen is connected to SPI0 and is working fine with luma examples.

The second screen is connected to SPI1 on GPIO20 (MOSI), GPIO21 (SCLK), GPIO16 (CE2) and is sharing DC and Reset with the first screen on pins 5 and 6.

In the documentation there's an option called --gpio GPIO. I'm not sure how to use it. I've tried putting in --gpio gpio20 and --gpio 20 and neither works. What would be the correct settings?

ValueError: The channel sent is invalid

Hi,

I'm trying to run the example project using a SSD1322 display on a FriendlyCore OS on a NanoPi NEO Air.

Running sudo python examples/sys_info.py -f conf/myconfig.cfg I'm getting an error:

Version: luma.oled 2.3.1 (luma.core 1.5.0)
Display: ssd1322
Interface: spi
Dimensions: 256 x 64
------------------------------------------------------------
Traceback (most recent call last):
  File "examples/sys_info.py", line 111, in <module>
    device = get_device()
  File "/home/pi/luma.examples/examples/demo_opts.py", line 63, in get_device
    device = cmdline.create_device(args)
  File "/usr/local/lib/python2.7/dist-packages/luma/core/cmdline.py", line 178, in create_device
    device = Device(Serial(), **vars(args))
  File "/usr/local/lib/python2.7/dist-packages/luma/core/cmdline.py", line 160, in spi
    gpio=self.gpio or GPIO)
  File "/usr/local/lib/python2.7/dist-packages/luma/core/interface/serial.py", line 255, in __init__
    bitbang.__init__(self, gpio, transfer_size, DC=gpio_DC, RST=gpio_RST)
  File "/usr/local/lib/python2.7/dist-packages/luma/core/interface/serial.py", line 153, in __init__
    self._DC = self._configure(kwargs.get("DC"))
  File "/usr/local/lib/python2.7/dist-packages/luma/core/interface/serial.py", line 164, in _configure
    self._gpio.setup(pin, self._gpio.OUT)
ValueError: The channel sent is invalid on a NanoPi

I have the following config defined:

--display=ssd1322
--interface=spi
--width=256
--height=64
--interface=spi
--spi-bus-speed=16000000
--spi-device=0
--gpio-data-command=201
--gpio-reset=1

I believe the FriendlyARM OS comes with the RPI.GPIO python package preinstalled which should have the right physical/gpio pin mappings. During the luma.examples pip install I was keeping an eye on the install output and have seen no output that would suggest that the RPI.GPIO module was overwritten.

I think I have the wiring set up correctly, using the NHD-2.8-25664UCB2 display.

I wonder what the error message really means and what I could do to debug the problem forward.
Any help would be appreciated, thanks.

PS: I did try this on an Armbian OS too (not the FriendlyARM Ubuntu, which doesn't have the RPi.GPIO module preinstalled, I got a similar error there too, only it said ValueError: The channel sent is invalid on a Raspberry Pi (this makes me believe that the RPI.GPIO library should be working fine?)

display neopixel not working

test_get_device_led_matrix_all also fails on Rpi2:

_____________________________________________________ test_get_device_led_matrix_all _____________________________________________________

capsys = <_pytest.capture.CaptureFixture instance at 0x7491c440>

    def test_get_device_led_matrix_all(capsys):
        """
        Load supported led_matrix devices one by one.
        """
        for display in display_types.get('led_matrix'):
            try:
>               get_device(['--display', display])

tests/test_demo_opts.py:129: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
examples/demo_opts.py:157: in get_device
    device = Device(Serial(), **vars(args))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <luma.led_matrix.device.neopixel object at 0x74920ed0>, dma_interface = <luma.core.serial.spi object at 0x74920e70>, width = 128
height = 64, cascaded = None, rotate = 0, mapping = None
kwargs = {'bcm_backlight': 18, 'bcm_data_command': 24, 'bcm_reset': 25, 'bgr': False, ...}

    def __init__(self, dma_interface=None, width=8, height=4, cascaded=None,
                 rotate=0, mapping=None, **kwargs):
        super(neopixel, self).__init__(const=None, serial_interface=noop)
    
        # Derive (override) the width and height if a cascaded param supplied
        if cascaded is not None:
            width = cascaded
            height = 1
    
        self.cascaded = width * height
        self.capabilities(width, height, rotate, mode="RGB")
        self._mapping = list(mapping or range(self.cascaded))
        assert(self.cascaded == len(self._mapping))
        self._ws2812 = dma_interface or self.__ws2812__()
>       self._ws2812.init(width * height)
E       AttributeError: 'spi' object has no attribute 'init'

.tox/py27/local/lib/python2.7/site-packages/luma/led_matrix/device.py:197: AttributeError

On rpi2:

$ python examples/3d_box.py --display neopixel
Traceback (most recent call last):
  File "examples/3d_box.py", line 129, in <module>
    device = get_device()
  File "/home/pi/projects/pi-test/luma.examples/examples/demo_opts.py", line 157, in get_device
    device = Device(Serial(), **vars(args))
  File "/home/pi/projects/pi-test/luma.led_matrix/luma/led_matrix/device.py", line 197, in __init__
    self._ws2812.init(width * height)
AttributeError: 'spi' object has no attribute 'init'

On Ubuntu machine I get:

$ python examples/3d_box.py --display neopixel
usage: 3d_box.py [-h] [--config CONFIG]
                 [--display {ssd1306,ssd1322,ssd1325,ssd1331,sh1106,pcd8544,st7735,max7219,neopixel,capture,gifanim,pygame}]
                 [--width WIDTH] [--height HEIGHT] [--rotate {0,1,2,3}]
                 [--interface {i2c,spi}] [--i2c-port I2C_PORT]
                 [--i2c-address I2C_ADDRESS] [--spi-port SPI_PORT]
                 [--spi-device SPI_DEVICE] [--spi-bus-speed SPI_BUS_SPEED]
                 [--bcm-data-command BCM_DATA_COMMAND] [--bcm-reset BCM_RESET]
                 [--bcm-backlight BCM_BACKLIGHT]
                 [--block-orientation {horizontal,vertical}]
                 [--mode {1,RGB,RGBA}]
                 [--framebuffer {diff_to_previous,full_frame}]
                 [--bgr {True,False}]
                 [--transform {identity,led_matrix,none,scale2x,seven_segment,smoothscale}]
                 [--scale SCALE] [--duration DURATION] [--loop LOOP]
                 [--max-frames MAX_FRAMES]
3d_box.py: error: SPI device not found

Test demo_opts

We should add unit tests to make sure nothing breaks in the argument parser.

Some examples not working on Rasp Pi 3 with SH1106 128x64

Hi, Just installed luma.core and luma.oled and now working through the luma.examples. Most of them work no problem and are fantastic!!!. A few have issues - I don't have the experience to determine why and whether it is my pi.

The examples that are not working are:

  1. tv_snow.py
  2. terminal.py
  3. carousel.py
  4. welcome.py

I changed demo_opts.py to default to sh1106.
Below I have shown what happens when I run these 4.

  1. tv_snow.py

python tv_snow.py
Traceback (most recent call last):
File "tv_snow.py", line 49, in
main()
File "tv_snow.py", line 38, in main
draw.multiline_text(offset, "Please do\nnot adjust\nyour set", fill="white", align="center", spacing=-1)
AttributeError: ImageDraw instance has no attribute 'multiline_text'

  1. terminal py

python terminal.py or (python terminal.py --height 64)
Traceback (most recent call last):
File "terminal.py", line 82, in
main()
File "terminal.py", line 32, in main
term.println("Uses any font to output text using a number of different print methods.")
File "/usr/local/lib/python2.7/dist-packages/luma/core/virtual.py", line 219, in println
self.puts(text)
File "/usr/local/lib/python2.7/dist-packages/luma/core/virtual.py", line 245, in puts
self.putch(char, flush=self.animate)
File "/usr/local/lib/python2.7/dist-packages/luma/core/virtual.py", line 256, in putch
self.newline()
File "/usr/local/lib/python2.7/dist-packages/luma/core/virtual.py", line 292, in newline
self._canvas.rectangle((0, copy.height, self._device.width, self._device.height), fill=self.bgcolor)
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 608, in getattr
raise AttributeError(name)
AttributeError: height

  1. carousel.py

python carousel.py
Traceback (most recent call last):
File "carousel.py", line 19, in
from hotspot import memory, uptime, cpu_load, clock, network, disk
File "/home/pi/luma.examples/examples/hotspot/memory.py", line 7, in
from hotspot.common import bytes2human, right_text, title_text, tiny_font
File "/home/pi/luma.examples/examples/hotspot/common.py", line 9, in
tiny_font = ImageFont.truetype("examples/fonts/FreePixel.ttf", 10)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 240, in truetype
return FreeTypeFont(font, size, index, encoding)
File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 137, in init
self.font = core.getfont(font, size, index, encoding)
IOError: cannot open resource

  1. welcome.py

python welcome.py
ImageDraw instance has no attribute 'multiline_textsize'
ImageDraw instance has no attribute 'multiline_textsize'
ImageDraw instance has no attribute 'multiline_textsize'
ImageDraw instance has no attribute 'multiline_textsize'
ImageDraw instance has no attribute 'multiline_textsize'
ImageDraw instance has no attribute 'multiline_textsize'
ImageDraw instance has no attribute 'multiline_textsize'
ImageDraw instance has no attribute 'multiline_textsize'
ImageDraw instance has no attribute 'multiline_textsize'
ImageDraw instance has no attribute 'multiline_textsize'

Can you advise.

ST7735 --backlight-active low all black

Using --backlight-active low appears to turn off the display i.e. is all black. --backlight-active high is the same as not setting this value at all and you are able to see images fine. When the display is not being accessed by Luma or when powered up it's an all white background.

Also, I noticed that dim/bright portion of demo.py does nothing.

I2C device not found on address: 0x3C

I followed your instructions and getting error:
I2C device not found on address: 0x3C

Result of the i2cdetect -y 1:

00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                     

Could you give me a tip where to look for a source of the problem?

scale option

would be nice to be able to scale and position the demo. I have a 1.8 inch screen that is covered by a hole that's about 60% the size.

invalid choice 'st7735'

Has support been removed for st7735?
I get error:

demo.py: error: argument --display/-d: invalid choice: 'st7735' (choose from 'ssd1306', 'ssd1322', 'ssd1325', 'ssd1327', 'ssd1331', 'ssd1351', 'sh1106', 'max7219', 'ws2812', 'neopixel', 'neosegment', 'apa102', 'capture', 'gifanim', 'pygame', 'asciiart', 'asciiblock')

How to draw.text a variable?

I refer to the example script in demo.py. I want to display a variable, how do I go about doing that?

I included var which is my variable after the string of fixed text like this: draw.text((device.width - padding - size[0], top + 32), 'Variable status is:', var, fill="white")

But I got an error on terminal:

TypeError: text() got multiple values for keyword argument 'fill'

I also tried draw.text((device.width - padding - size[0], top + 32), 'Variable status is: %s', fill="white") %var

How can I print variables in a draw.text function?

jetset_willy.py doesn't work?

pi@devpi ~/l/examples> ./jetset_willy.py
Display: ssd1306
Interface: i2c
Dimensions: 128 x 64
----------------------------------------
Traceback (most recent call last):
  File "./jetset_willy.py", line 100, in <module>
    main()
  File "./jetset_willy.py", line 54, in main
    sheet = spritesheet(**data)
  File "/usr/local/lib/python2.7/dist-packages/luma/core/sprite_system.py", line 78, in __init__
    self.image = self.image.crop((regX, regY, self.image.width - regX, self.image.height - regY))
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 608, in __getattr__
    raise AttributeError(name)
AttributeError: width

Noob guide

I have everything installed, but I'm struggling with the command-line options and receive this error each time:

Traceback (most recent call last):
File "demo.py", line 16, in
from demo_opts import device
File "/home/pi/luma.examples/examples/demo_opts.py", line 12, in
import luma.core.emulator
ImportError: No module named luma.core.emulator

Any chance of a walkthrough using the PCD8544 LCD as an example?

Thanks

Example settings summary

It would be useful to print a small summary of the settings when running an example, e.g.:

display: ssd1306, interface: i2c

And maybe if any of the default settings are not in use also print the value for these settings.

Installation instructions do not work

I followed:
$ sudo usermod -a -G i2c,spi,gpio pi
$ sudo apt-get install python-dev python-pip libfreetype6-dev libjpeg-dev
$ sudo apt-get purge python-pip
$ sudo -H pip install --upgrade pip

However, the last command results in:
sudo: pip: command not found

How can I open a luma script from another python script using subprocess

I would like to ask about how I can launch a luma oled script from a parent script. I have used:

import subprocess # to use subprocess 

p = subprocess.Popen(['python', 'demo_oled_v01.py --display ssd1351 --width 128 --height 128 --interface spi --gpio-data-command 20'])

in my parent script but I got an error stating:

python: can't open file 'demo_oled_v01.py --display ssd1351 --width 128 --height 128 --interface spi --gpio-data-command 20': [Errno 2] No such file or directory

I suspect that adding the parameters --display ssd1351 --width 128 --height 128 --interface spi --gpio-data-command 20 after .py may be causing difficulty in launching the oled script. These parameters are otherwise essential for me to include for launching with bash commands on terminal. How can I use subprocess with the required luma library parameters to launch a SSD1351 based script?

SSD1331 no display

Using ODROID C1+ and the following works fine:

import time
from RPi import GPIO
from luma.core.interface.serial import spi
from luma.core.render import canvas
from luma.oled.device import ssd1331

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
serial = spi(port=0, device=0, gpio=GPIO, gpio_DC=18, gpio_RST=22)
device = ssd1331(serial)

with canvas(device) as draw:
    draw.rectangle(device.bounding_box, outline="white")
    draw.text((3, 3), "Hello", fill="white")

time.sleep(10)

Running any of the examples with the following and nothing displays:

sudo python examples/invaders.py -d ssd1331 -i spi --spi-port 0 --spi-device 0 --gpio-data-command 18 --gpio-reset 22 --width 96 --height 64
Version: luma.oled 2.3.1 (luma.core 1.2.1)
Display: ssd1331
Interface: spi
Dimensions: 96 x 64
------------------------------------------------------------

Don't hardcode display support

The arguments in the example options parser should be dynamically populated. Basically every lib should advertise what display modes/interfaces are available.

luma.core.render.canvas, text() (PIL ImageDraw) requires UTF-8 default font?

Hi again, I encountered another minor problem when playing with the examples.
I just noticed that I might be running 2017-08-16-raspbian-stretch-lite which might explain some missing dependencies .. or missing fonts...

The problem

pi@raspberry:~/luma.examples/examples $ python3 bounce.py -d ssd1322 --width 256                                                                                     --height 64 -i spi
Display: ssd1322
Interface: spi
Dimensions: 256 x 64
----------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/PIL/ImageDraw.py", line 220, in t                                                                                    ext
    mask, offset = font.getmask2(text, self.fontmode, *args, **kwargs)
AttributeError: 'ImageFont' object has no attribute 'getmask2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bounce.py", line 81, in <module>
    main()
  File "bounce.py", line 72, in main
    c.text((2, 0), fps, fill="white")
  File "/usr/local/lib/python3.5/dist-packages/PIL/ImageDraw.py", line 224, in t                                                                                    ext
    mask = font.getmask(text, self.fontmode, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/PIL/ImageFont.py", line 114, in g                                                                                    etmask
    return self.font.getmask(text, mode)
SystemError: <built-in method getmask of ImagingFont object at 0x23fce80> return                                                                                    ed NULL without setting an error

One of the first search hits suggests that a Unicode-capable font is required (but I did not research further, so it may be another cause), and here's my path to resolving it at the examples source (in the logical order):

Find out what fonts can be used

pi@raspberry:~/luma.examples/examples $ sudo apt-get install fontconfig
...
pi@raspberry:~/luma.examples/examples $ fc-list
/usr/share/fonts/truetype/dejavu/DejaVuSerif-Bold.ttf: DejaVu Serif:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf: DejaVu Sans Mono:style=Book
/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book
/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf: DejaVu Sans:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf: DejaVu Sans Mono:style=Bold
/usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf: DejaVu Serif:style=Book

Use one of these in the example:

pi@raspberry:~/luma.examples/examples $ git diff bounce.py
diff --git a/examples/bounce.py b/examples/bounce.py
index 7e10916..d9f46cc 100755
--- a/examples/bounce.py
+++ b/examples/bounce.py
@@ -59,6 +59,9 @@ def main(num_iterations=sys.maxsize):

     regulator = framerate_regulator(fps=0)

+    from PIL import ImageFont
+    font = ImageFont.truetype("DejaVuSans.ttf")
+
     while num_iterations > 0:
         with regulator:
             num_iterations -= 1
@@ -69,7 +72,7 @@ def main(num_iterations=sys.maxsize):
                 for b in balls:
                     b.update_pos()
                     b.draw(c)
-                c.text((2, 0), fps, fill="white")
+                c.text((2, 0), fps, fill="white", font=font)

             if frame_count % 20 == 0:
                 fps = "FPS: {0:0.3f}".format(regulator.effective_FPS())
pi@raspberry:~/luma.examples/examples $ python3 bounce.py -d ssd1322 --width 256 --height 64 -i spi
Display: ssd1322
Interface: spi
Dimensions: 256 x 64
----------------------------------------
^C

Quick search shows font setting only in:

On the other hand, greyscale.py also renders text but does not show this issue.

Sorry I can't pinpoint this further.

pi@raspberry:~/luma.examples $ git show
commit 06aade8489bdf95c693fdf0323c541bfbbb04385
Author: Thijs Triemstra <info@***.nl>
Date:   Fri Oct 27 10:09:21 2017 +0200

    flake8 config update (#64)

pi@raspberry:~/luma.examples $ pip3 show luma.oled
Name: luma.oled
Version: 2.2.12
Summary: A small library to drive an OLED device with either SSD1306, SSD1322, SSD1325, SSD1331 or SH1106 chipset
Home-page: https://github.com/rm-hull/luma.oled
Author: Richard Hull
Author-email: richard.hull@***.org
License: MIT
Location: /usr/local/lib/python3.5/dist-packages
Requires: luma.core
pi@raspberry:~/luma.examples $ pip3 show luma.core
Name: luma.core
Version: 1.0.3
Summary: A component library to support SBC display drivers
Home-page: https://github.com/rm-hull/luma.core
Author: Richard Hull
Author-email: richard.hull@***.org
License: MIT
Location: /usr/local/lib/python3.5/dist-packages
Requires: spidev, RPI.GPIO, pillow, smbus2

cmdline.py doesn't work?

Not sure what it's supposed to do?

pi@devpi ~/l/examples> ./cmdline.py
Failed to execute process './cmdline.py'. Reason:
exec: Exec format error
The file './cmdline.py' is marked as an executable but could not be run by the operating system.
pi@devpi ~/l/examples> python cmdline.py
pi@devpi ~/l/examples>

failing rpi tests

platform linux2 -- Python 2.7.9, pytest-3.0.6, py-1.4.32, pluggy-0.4.0 -- /home/pi/projects/pi-test/luma.examples/.tox/py27/bin/python2.7
cachedir: .cache
rootdir: /home/pi/projects/pi-test/luma.examples, inifile: 
plugins: cov-2.4.0
collected 12 items 

tests/test_demo_opts.py::test_support PASSED
tests/test_demo_opts.py::test_create_parser PASSED
tests/test_demo_opts.py::test_load_config_file_parse PASSED
tests/test_demo_opts.py::test_get_device_config_file_missing PASSED
tests/test_demo_opts.py::test_get_device_config__file_success PASSED
tests/test_demo_opts.py::test_get_choices_unknown_module PASSED
tests/test_demo_opts.py::test_get_device_unknown PASSED
tests/test_demo_opts.py::test_get_device_emulator_all PASSED
tests/test_demo_opts.py::test_get_device_led_matrix_all FAILED
tests/test_demo_opts.py::test_get_device_lcd_all FAILED
tests/test_demo_opts.py::test_get_device_oled_all FAILED
tests/test_demo_opts.py::test_get_device_oled_interface_unknown PASSED

================================================================ FAILURES ================================================================
_____________________________________________________ test_get_device_led_matrix_all _____________________________________________________

capsys = <_pytest.capture.CaptureFixture instance at 0x749794e0>

    def test_get_device_led_matrix_all(capsys):
        """
        Load supported led_matrix devices one by one.
        """
        for display in display_types.get('led_matrix'):
            with pytest.raises(SystemExit):
>               get_device(['--display', display])
E               Failed: DID NOT RAISE <type 'exceptions.SystemExit'>

tests/test_demo_opts.py:129: Failed
________________________________________________________ test_get_device_lcd_all _________________________________________________________

capsys = <_pytest.capture.CaptureFixture instance at 0x749798c8>

    def test_get_device_lcd_all(capsys):
        """
        Load supported lcd devices one by one.
        """
        for display in display_types.get('lcd'):
            with pytest.raises(SystemExit):
>               get_device(['--display', display])

tests/test_demo_opts.py:142: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
examples/demo_opts.py:150: in get_device
    device = Device(Serial(), **vars(args))
.tox/py27/local/lib/python2.7/site-packages/luma/lcd/device.py:64: in __init__
    self.contrast(0xB0)
.tox/py27/local/lib/python2.7/site-packages/luma/lcd/device.py:95: in contrast
    self.command(0x21, 0x14, value | 0x80, 0x20)
.tox/py27/local/lib/python2.7/site-packages/luma/core/device.py:39: in command
    self._serial_interface.command(*cmd)
.tox/py27/local/lib/python2.7/site-packages/luma/core/serial.py:84: in command
    list(cmd))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <smbus2.smbus2.SMBus object at 0x753ec4d0>, i2c_addr = 60, register = 0, data = [33, 20, 176, 32]

    def write_i2c_block_data(self, i2c_addr, register, data):
        # type: (int, int, list) -> None
        """
            Write a block of byte data to a given register
            :param i2c_addr: i2c address
            :param register: Start register
            :param data: List of bytes
            """
        length = len(data)
        if length > I2C_SMBUS_BLOCK_MAX:
            raise ValueError("Data length cannot exceed %d bytes" % I2C_SMBUS_BLOCK_MAX)
        self._set_address(i2c_addr)
        msg = i2c_smbus_ioctl_data.create(
            read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_I2C_BLOCK_DATA
        )
        msg.data.contents.block[0] = length
        msg.data.contents.block[1:length + 1] = data
>       ioctl(self.fd, I2C_SMBUS, msg)
E       IOError: [Errno 121] Remote I/O error

.tox/py27/local/lib/python2.7/site-packages/smbus2/smbus2.py:274: IOError
________________________________________________________ test_get_device_oled_all ________________________________________________________

capsys = <_pytest.capture.CaptureFixture instance at 0x73ec7b48>

    def test_get_device_oled_all(capsys):
        """
        Load supported oled devices one by one.
        """
        for display in display_types.get('oled'):
            with pytest.raises(SystemExit):
>               get_device(['--display', display])

tests/test_demo_opts.py:155: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
examples/demo_opts.py:142: in get_device
    device = Device(Serial(), **vars(args))
.tox/py27/local/lib/python2.7/site-packages/luma/oled/device.py:153: in __init__
    self._const.NORMALDISPLAY)
.tox/py27/local/lib/python2.7/site-packages/luma/core/device.py:39: in command
    self._serial_interface.command(*cmd)
.tox/py27/local/lib/python2.7/site-packages/luma/core/serial.py:84: in command
    list(cmd))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <smbus2.smbus2.SMBus object at 0x73efc390>, i2c_addr = 60, register = 0, data = [174, 213, 128, 168, 63, 211, ...]

    def write_i2c_block_data(self, i2c_addr, register, data):
        # type: (int, int, list) -> None
        """
            Write a block of byte data to a given register
            :param i2c_addr: i2c address
            :param register: Start register
            :param data: List of bytes
            """
        length = len(data)
        if length > I2C_SMBUS_BLOCK_MAX:
            raise ValueError("Data length cannot exceed %d bytes" % I2C_SMBUS_BLOCK_MAX)
        self._set_address(i2c_addr)
        msg = i2c_smbus_ioctl_data.create(
            read_write=I2C_SMBUS_WRITE, command=register, size=I2C_SMBUS_I2C_BLOCK_DATA
        )
        msg.data.contents.block[0] = length
        msg.data.contents.block[1:length + 1] = data
>       ioctl(self.fd, I2C_SMBUS, msg)
E       IOError: [Errno 121] Remote I/O error

.tox/py27/local/lib/python2.7/site-packages/smbus2/smbus2.py:274: IOError
=================================================== 3 failed, 9 passed in 5.75 seconds ===================================================
ERROR: InvocationError: '/home/pi/projects/pi-test/luma.examples/.tox/py27/bin/coverage run -m py.test -vv'

error: argument --framebuffer: invalid choice: 'conf/st7735.conf'

$ python examples/3d_box.py --f conf/st7735.conf 
usage: 3d_box.py [-h] [--config CONFIG] [--display] [--width WIDTH]
                 [--height HEIGHT] [--rotate] [--interface]
                 [--i2c-port I2C_PORT] [--i2c-address I2C_ADDRESS]
                 [--spi-port SPI_PORT] [--spi-device SPI_DEVICE]
                 [--spi-bus-speed SPI_BUS_SPEED]
                 [--gpio-data-command GPIO_DATA_COMMAND]
                 [--gpio-reset GPIO_RESET] [--gpio-backlight GPIO_BACKLIGHT]
                 [--block-orientation] [--mode] [--framebuffer] [--bgr]
                 [--h-offset H_OFFSET] [--v-offset V_OFFSET]
                 [--backlight-active]
3d_box.py: error: argument --framebuffer: invalid choice: 'conf/st7735.conf' (choose from 'diff_to_previous', 'full_frame')

install

pi@raspberrypi:~ $ sudo apt purge python-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gir1.2-glib-2.0 libdbus-glib-1-2 libgirepository-1.0-1 libpython-all-dev
  python-all python-all-dev python-cffi-backend python-crypto
  python-cryptography python-dbus python-enum34 python-gi python-idna
  python-ipaddress python-keyring python-keyrings.alt python-pip-whl
  python-pkg-resources python-pyasn1 python-secretstorage python-setuptools
  python-six python-wheel python-xdg
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  python-pip*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 671 kB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 40766 files and directories currently installed.)
Removing python-pip (9.0.1-2+rpt1) ...
Processing triggers for man-db (2.7.6.1-2) ...
pi@raspberrypi:~ $ git clone https://github.com/rm-hull/luma.examples.git
Cloning into 'luma.examples'...
remote: Counting objects: 692, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 692 (delta 3), reused 3 (delta 2), pack-reused 678
Receiving objects: 100% (692/692), 5.30 MiB | 1.40 MiB/s, done.
Resolving deltas: 100% (424/424), done.
pi@raspberrypi:~ $ cd luma.examples
pi@raspberrypi:~/luma.examples $ sudo -H pip install -e .
sudo: pip: command not found
pi@raspberrypi:~/luma.examples $ ls
conf              examples     README.rst  setup.py  tox.ini
CONTRIBUTING.rst  LICENSE.rst  setup.cfg   tests
pi@raspberrypi:~/luma.examples $ sudo python setup.py
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: no commands supplied
pi@raspberrypi:~/luma.examples $ sudo python setup.py setup.cfg
invalid command name 'setup.cfg'
pi@raspberrypi:~/luma.examples $

Font rendering scripts fail to execute.

The scripts which use fonts from the "fonts" folder included in examples, fail to execute.
It raises IOError - unknown file format.

Display: pcd8544
Interface: spi
Dimensions: 128 x 64
----------------------------------------
Traceback (most recent call last):
  File "welcome.py", line 233, in <module>
    main()
  File "welcome.py", line 198, in main
    fonts = [make_font("code2000.ttf", sz) for sz in range(24, 8, -2)]
  File "welcome.py", line 121, in make_font
    return ImageFont.truetype(font_path, size)
  File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 238, in truetype
    return FreeTypeFont(font, size, index, encoding)
  File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 127, in __init__
    self.font = core.getfont(font, size, index, encoding)
IOError: unknown file format

It seems, imagefont is unable to load fonts from anywhere else except the default folders, i.e -
"/usr/share/fonts/truetype/freefont/"
After copying the individual fonts to the above mentioned folder, the script works flawlessly, also the provided "code2000.ttf" font is corrupt, I downloaded a fresh copy of the "code2000.ttf" from internet , after copying to the default folder , it works.

ht1621 demo error

Error when trying the demo:

$ python examples/sevensegment_demo.py -d ht1621
/home/rpitest/pi-test/luma.core/luma/core/interface/serial.py:164: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  self._gpio.setup(pin, self._gpio.OUT)
Traceback (most recent call last):
  File "luma.examples/examples/sevensegment_demo.py", line 115, in <module>
    main()
  File "luma.examples/examples/sevensegment_demo.py", line 70, in main
    device = get_device()
  File "/home/rpitest/pi-test/luma.examples/examples/demo_opts.py", line 61, in get_device
    device = cmdline.create_device(args)
  File "/home/rpitest/pi-test/luma.core/luma/core/cmdline.py", line 176, in create_device
    device = Device(spi, **vars(args))
TypeError: __init__() got multiple values for argument 'gpio'

New user with SH1106 and "mock" error

I followed the install instructions without any problems or errors. When I run "python test_sh1106.py" in the "luma.oled/tests" directory I get the following error.

pi@ChangeMe:~/luma.oled/tests $ python test_sh1106.py
Traceback (most recent call last):
  File "test_sh1106.py", line 10, in <module>
    from helpers import (serial, call, Mock, setup_function,  # noqa: F401
  File "/home/pi/luma.oled/tests/helpers.py", line 8, in <module>
    from mock import call, Mock  # noqa: F401
ImportError: No module named mock

Where did I go wrong?
Max

P.S. I'm new to programming and Git so if this is in the wrong place please let me know.
Using the current version of Jessie on a pi 2 B with all the updates

Support for 64x48 OLED Display

Hello,
Would it be possible to add a support for a 64x48 OLED display. I do not have much experience here. Can I add it manual?
Thanks

Questions on how the program "cleans up"

This is not an issue. I'd like to ask the maintainer some questions to clarify how this works? Is there any communication channel I can reach rm-hull?

I'd like to know how luma cleans up the display interfaces when done, i.e. blanks the screen and it also appears to sort of "release" the interface.

If I have a program running and using the interface (via the Adafruit SSD1306 driver) and then call a luma example, both work and compete (but work) for the display interface, but when I terminate the luma example, my program can no longer access the display.

Can anyone tell me the mechanism that prevents my program from continued use of the display?

Ideally, I'd like to give multiple programs access to the display (of course not at the same time). I'd be managing them myself (unless this driver has a way to manage that?) I plan to port my code using the Adafruit driver to the luma driver, but ideally, I'd like to sort this whole "clean up" but out first, so that programs still running in the background can regain control of the display.

Thanks!

Move device imports in demo_opts

Got the following traceback:

luma.examples $ python examples/3d_box.py -i spi
Traceback (most recent call last):
  File "examples/3d_box.py", line 16, in <module>
    from demo_opts import device
  File "/home/pi/projects/pi-test/luma.examples/examples/demo_opts.py", line 12, in <module>
    import luma.lcd.device
ImportError: No module named 'luma.lcd'

I was trying to test an OLED example and it shouldn't complain when an optional library cannot be found. Moving the relevant device import should work?

sevensegment_demo.py fails

pi@raspberrypi:~/Git/luma.examples/examples $ python sevensegment_demo.py
Version: luma.oled 2.3.1 (luma.core 1.2.1)
Display: ssd1306
Interface: i2c
Dimensions: 128 x 64
------------------------------------------------------------
Traceback (most recent call last):
  File "sevensegment_demo.py", line 115, in <module>
    main()
  File "sevensegment_demo.py", line 71, in main
    seg = sevensegment(device)
  File "/usr/local/lib/python2.7/dist-packages/luma/core/virtual.py", line 482, in __init__
    self.segment_mapper = segment_mapper or device.segment_mapper
AttributeError: 'ssd1306' object has no attribute 'segment_mapper'

Display image within canvas

From the examples I have seen and tried , so display a picture such as png, I need to use the device.display method. Is it possible to display an image within a canvas.

What I would like to do is to display an image inside
with canvas(device, dither=True) as draw:
so that I can have a mixture of text and png in one screen, similar to colors.py example but displaying the canvas and image at the same time.

Is it possible?

Thanks for this great library.

Performance numbers for ssd1322 screen

I'm building a digital dashboard and data logger for my car and have a couple of screens that are supported by Luma.

I have 2x ssd1306 128x64 1.3" screens on the Pi 3 I2C bus. Performance when testing with the Luma examples is 25ish FPS which is fine for the purposes of using them as supplementary data gauges.

I've also added the 256x64 ssd1322 as a main display which runs great (it's a lovely screen), but the performance data seems to think it's running at over 1500fps. Has anyone else submitted feedback on this screen? It seems quick, but I don't quite believe it's that quick!

Simplify pygame dependency install instructions

Instead of mentioning the pygame deps in the instructions, use build-dep instead.

$ sudo apt-get build-dep pygame
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  libcaca-dev libcaca0 libdirectfb-1.2-9 libdirectfb-dev libdirectfb-extra libflac-dev libfluidsynth1 libmad0 libmad0-dev libmikmod-config libmikmod-dev libmikmod3 libogg-dev libopenal-data libopenal1 libportmidi-dev
  libportmidi0 libpython-all-dev libpython-dev libpython2.7-dev libsdl-image1.2 libsdl-image1.2-dev libsdl-mixer1.2 libsdl-mixer1.2-dev libsdl-ttf2.0-0 libsdl-ttf2.0-dev libsdl1.2-dev libsdl1.2debian libslang2-dev
  libsmpeg-dev libsmpeg0 libvorbis-dev libvorbisfile3 python-all python-all-dev python-dev python2.7-dev sharutils
0 upgraded, 38 newly installed, 0 to remove and 0 not upgraded.
Need to get 24.6 MB of archives.
After this operation, 45.5 MB of additional disk space will be used.
Do you want to continue? [Y/n]

update github description

in the github description, luma.emulator is missing:

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

Some tests failing on raspberry pi device

Tests die with this error on rpi2 (rpi3 only due to memory i suppose):

tests/test_demo_opts.py::test_get_device_led_matrix_all ERROR: InvocationError: '/home/rpitest/pi-test/luma.examples/.tox/py27/bin/coverage run -m py.test -vv -r w'

'full' run (ignore missing py3.5 error):

py34 runtests: commands[1] | coverage run -m py.test -vv -r w
======================================== test session starts ========================================
platform linux -- Python 3.4.2, pytest-3.1.2, py-1.4.34, pluggy-0.4.0 -- /home/rpitest/pi-test/luma.examples/.tox/py34/bin/python3.4
cachedir: .cache
rootdir: /home/rpitest/pi-test/luma.examples, inifile:
plugins: cov-2.5.1
collected 9 items 

tests/test_demo_opts.py::test_display_settings PASSED
tests/test_demo_opts.py::test_get_device_config_file_missing PASSED
tests/test_demo_opts.py::test_get_device_config_file_success PASSED
tests/test_demo_opts.py::test_get_device_unknown PASSED
tests/test_demo_opts.py::test_get_device_emulator_all PASSED
tests/test_demo_opts.py::test_get_device_led_matrix_all ERROR: InvocationError: '/home/rpitest/pi-test/luma.examples/.tox/py34/bin/coverage run -m py.test -vv -r w'
py35 create: /home/rpitest/pi-test/luma.examples/.tox/py35
ERROR: InterpreterNotFound: python3.5

Don't see find any meaningful errors there..

Move extra dependencies to setup.py

Some examples have extra dependencies (e.g. picamera, psutil, feedparser, etc). Shouldn't these belong in the setup.py, and be installed when the examples are installed? It's more to install but easier for newbies.

Install failure

I finally have SSD1306 SPI working on CHIP! I tried to install luma.examples:

  • sudo apt-get install python-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev python-numpy subversion libportmidi-dev ffmpeg libswscale-dev libavformat-dev libavcodec-dev
  • git clone https://github.com/rm-hull/luma.examples.git
  • cd luma.examples
  • sudo -H pip install -e .

And get:

Obtaining file:///home/chip/luma.examples
    Complete output from command python setup.py egg_info:
    error in luma.examples setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers.
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /home/chip/luma.examples/

Luma.OLED RPI3 ImportError: No module named luma....

Sorry to be a pain but having spent an hour here and an hour there on this and followed through all the other people having similar issues, I still cannot get any of the examples to run on my RPI3 running the latest Raspian.

I've remove, installed, pulled the latest examples down and have...

luma.core (0.5.4)
luma.oled (2.2.5)

...both installed. I'm also using pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)

running python examples/demo.py gives:

Traceback (most recent call last):
  File "examples/demo.py", line 17, in <module>
    from luma.core.render import canvas
ImportError: No module named luma.core.render

and as another example, running python examples/welcome.py gives:

  File "examples/welcome.py", line 14, in <module>
    from luma.core.virtual import viewport, snapshot, range_overlap
ImportError: No module named luma.core.virtual

Any and all help would be much appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.