Home

Awesome

papirus

Ruby gem to talk to the PaPiRus display from a Raspberry PI

Before you start playing make sure you got the display driver installed (gratis/edp-fuse) on your PI

ssh yourpi
sudo apt-get install libfuse-dev -y

git clone https://github.com/repaper/gratis.git
cd gratis
make rpi EPD_IO=epd_io.h PANEL_VERSION='V231_G2'
make rpi-install EPD_IO=epd_io.h PANEL_VERSION='V231_G2'
systemctl enable epd-fuse.service
systemctl start epd-fuse

You can find more detailed instructions and updates at the gratis repo

gem installation (add sudo if your not using RVM)

$ gem install papirus

Using with RMagic

First install rmagick

$ # Install native Image Magick library
$ (OSX) brew install imagemagick@6 && brew link imagemagick@6 --force
$ (debian/ubuntu) sudo apt-get install imagemagick
$ (Windows) no idea (did not use windows for 20 years, and would like to add some more)
$ # Install the gem that talks to the native Image Magick library
$ gem install rmagick

Using an irb session to play around:

$ irb
require 'papirus'
require 'papirus/rmagick'
display = PaPiRus::Display.new()
image = Magick::Image::read('/path/to/img/file.[png|jpg|etc]').first
display.show(data: image.to_bit_stream(display.width, display.height))

Using with ChunkyPNG

# install on
$ (OSX) brew install chunky_png
$ (debian/ubuntu) sudo apt-get install chunky_png
$ (Windows) no idea (did not use windows for 20 years, and would like to add some more)
$ gem install chunky_png

Load an image from a png file

$ irb
require 'papirus'
require 'papirus/chunky'
display = PaPiRus::Display.new()
image = ChunkyPNG::Image.from_file('out.png')
display.show(data: image.to_bit_stream(display.width, display.height))

The only problem here is the aspect ration of the image is not ok anymore. is a todo But for now you could also use Image magick's convert tool to rescale the image and place it in the middle

First, let's use Image Magick's convert tool to convert any image into an scaled, centered png

convert in.jpg -resize '264x176' -gravity center -extent '264x176' out.png

now, load it like explaned above and the image should be in the right aspect ration

Drawing circles with ChunkyPNG

irb
require 'papirus'
require 'papirus/chunky' # add's to_bit_stream function to chucky

#lets get a clean png of the size of the display to play with using chunky_png
image = ChunkyPNG::Image.new(display.width, display.height, ChunkyPNG::Color::WHITE)
#and we draw a circle on it which is about the size of the screen
image.circle(display.width/2, display.height/2, display.height/2-2)

have a look at chunkypng for more examples

#and last we dump the image as bitsteam to the display
display.show(data: image.to_bit_stream)

# now we could also change the circle and fast update the screen
image.replace!(ChunkyPNG::Image.new(display.width, display.height, ChunkyPNG::Color::WHITE))
image.circle(display.width/2, display.height/2, display.height/4)
display.show(data: image.to_bit_stream, 'F')

# or update the screen for multiple circles
display.clear
2.step(image.height/2-2, 5).each do |radius|
    image.replace!(ChunkyPNG::Image.new(display.width, display.height, ChunkyPNG::Color::WHITE))
    image.circle(display.width/2, display.height/2, radius)
    display.show(data: image.to_bit_stream, command: 'F')
end

there are multiple screen commands ['F', 'P', 'U', 'C']

Full update (with screen cleaning):

display.show(data: image.to_bit_stream(display.width, display.height))

Fast update:

display.show(data: image.to_bit_stream(display.width, display.height)), command: 'F')

Partial update:

display.show(data: image.to_bit_stream(display.width, display.height), command: 'P')

Testing without a PaPiRus display

If you want to test the gem, but don't have your PaPiRus available, you can do the following

clone this repo

$ bundle exec irb -r ./lib/papirus
# The gem will create the epd_path test folder (the folder needs to be somwhere in /tmp/) and will set it by default to the 2.0 panel
display = PaPiRus::Display.new(options:{epd_path: '/tmp/epd'})
# When you want to add the 2.7 display panel, you would do
display = PaPiRus::Display.new(options:{epd_path: '/tmp/epd', width: 264, height: 176, panel: 'EPD 2.7'})

Now play with the examples above

handy convert command

This Image Magick convert command creates a 1-bit 2-color png

convert in.jpg -resize '264x176' -gravity center -extent '264x176' -colorspace gray  -colors 2 -type bilevel out.png

Where

TODO

Other resources

Development

Contributing to papirus

Copyright

Copyright (c) 2017 Mischa Molhoek. See LICENSE.txt for further details.