txoof / epdlib

Python library for creating and writing modular layouts for e-paper screens
GNU General Public License v3.0
16 stars 8 forks source link

Hello World minimum viable example #57

Closed VaporwareII closed 1 year ago

VaporwareII commented 1 year ago

Hi again, thanks for the help with PaperPi. I actually managed to wreck my last dev environment so I couldn't reply in time to the issue regarding installing under 64bit. I couldn't even get the pi to poweron then once I did the GPIO looked like it was fried lol.

I was looking upstream from PaperPi at your epdlib here and wanted to run a minimum viable example, but I am unskilled at python. Here are the steps I performed so far to install.

I git cloned the epdlib folder into my home directory, installed waveshare libraries at home/user/epdlib, set up the environment using create_devel_venv.sh, but failed to run the screen test because I was still located in the home/user/epdlib folder. once I cd epdlib to locate to home/user/epdlib/epdlib, then the command screen -m Screen worked. you might want to add that note for us absolute beginners.

I have successfully installed all the dependencies, program files seem to be in place, and tested the waveshare display, but I don't know where to start to actually use epdlib. If I wanted to take my 2.13_V3 waveshare display and put "Hello World" such that it fills the display, what steps do I need to do?

If I create a python file such as helloworld.py in the lowest epdlib folder how do I reference the waveshare libraries I installed? I suppose in the py file I would need to just reference epdlib/Block, Layout, and Screen?

Once I have hello world working in one orientation then I would start looking at the text block options using the Screen.py test script as an example and adding perhaps an image like the example layout file in the docs/Layout.md doc.

txoof commented 1 year ago

@VaporwareII

The development environment is really intended for those that will be developing for epdlib, not with epdlib. To get started with epdlib in a project you'll probably want to do the following:

From the docs:

EpdLib provides classes for interfacing with the screen (Screen), building layouts that will work at any resolution (Layout), and blocks that are used to assemble layouts (Block). EpdLib makes it trivial to build a project that will work on almost any WaveShare display without worrying about the resolution or recoding the display functions.

The best way to get a "Hello World" example up and running would be to scrape the main function out of the Screen module and use that as a template.

To get started, you need two things:

example I tested this with an HD screen and it worked as expected; YMMV.

# import from epdlib
from epdlib import Screen
from epdlib import Layout
from epdlib import Block
from epdlib import constants

import logging
from time import sleep

# obnoxious levels of debugging output that might help you diagnose problems
logging.root.setLevel('DEBUG')

# create screen and layout objects
my_screen = Screen(epd='epd2in13_V3')
my_layout = Layout(resolution=my_screen.resolution)

# define a layout with a single text block
layout = {
            'title': {                       # text only block
                'type': 'TextBlock',
                'image': None,               # do not expect an image
                'max_lines': 3,              # number of lines of text
                'width': 1,                  # 1/1 of the width - this stretches the entire width of the display
                'height': 1,               # 1/1 of the entire height
                'abs_coordinates': (0, 0),   # this block is the key block that all other blocks will be defined in terms of
                'hcenter': True,             # horizontally center text
                'vcenter': True,             # vertically center text 
                'relative': False,           # this block is not relative to any other. It has an ABSOLUTE position (0, 0)
                'font': str(constants.absolute_path/'../fonts/Font.ttc'), # path to font file - this font is included
                'font_size': None            # Calculate the font size because none was provided
            }
}
# assign the layout definition to the layout property of the Layout() object
my_layout.layout = layout

# tell the layout what to put in the 'title' block
my_layout.update_contents({'title': 'HELLO WORLD!'})

# concatenate all the images in the layout into a single large image (PIL.paste for those keeping score)
# and write it to the EPD
my_screen.writeEPD(my_layout.concat())
print('sleeping for 10 seconds')
sleep(10)
my_screen.clearEPD()

For more examples, check out the plugins in PaperPi. There are tons of more complex layouts and you can see how epdlib is used "in the real world." The Word Cock and moon_phase plugins are super simple to understand and the met_no plugin has some really complex layouts that use lines, borders, images, and text. All the layouts are stored in the plugin directories within the layout.py files.

VaporwareII commented 1 year ago

I recognised some of the layout syntax from setting up the moon phase plugin, I will keep working at it, thanks!

edit: Holy moly, your example worked immediately without any modification. Great work on the library that a proof of concept test can be generated that easily from my description. From here I will begin to learn the methods and arguments, and try to get all of that working in virtual environment. I remember setting up the venv with paperpi wasn't terrible, so it should come together quickly.

txoof commented 1 year ago

The example code is mostly lifted from the library. I'll add it to the README.

Glad it worked for you.