Distribute CharLCD package

We are almost ready to go public with CharLCD package. First some refactoring and next we will build dist package.


Our four files that are main classes (in charlcd package) have names that starts form lcd_ . I think lcd_ is not needed. It repeats package name. Lets remove it.

Next delete old piader_1, I wanted to keep it but still don’t know why 🙂

Rename and fix functions in demo/lcd_virtual_buffered.py

Next I found that function stream in buffered.py is not working correctly. I copied it from direct and one small change and function fixed.

Same problem with stream in virtual buffered.

Refactor function names in all demo files.

Add anti-multiple-initialization to I2C and gpio driver.

Lots of documentation fixes.


This game is a good demo but still needs some tweaking. First we need to change initialization so start points and width/height will be calculated from received lcd. One important thing, only screens with height above 2 and width above 5 can be used.

We are using two lcds, one for game and one for score. We will make second screen obligatory.

Finally we need to rebuild controls so it will work without another script but still will use network.

New file responsible for keyboard read (local_key.py):

# -*- coding: utf-8 -*-

"""Simple key read"""
__author__ = 'Bartosz Kościów'

import socket
import termios, fcntl, sys, os
fd = sys.stdin.fileno()

oldterm = termios.tcgetattr(fd)
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, newattr)

oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)

TCP_IP = ''
TCP_PORT = 5005

class Keyboard(object):
    """Read keyboard"""
    def __init__(self):
        self.conn_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.conn_socket.connect((TCP_IP, TCP_PORT))

    def read(self):
            key = sys.stdin.read(1)
            if key == 'a':
            if key == 'd':
            if key == ' ':
        except IOError: pass

    def send(self, event):
        """send event to game"""

    def shutdown(self):
        """restore console"""
        termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
        fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)

Import this file in game.py and in __init__ add

self.local_keyboard = keyboard.Keyboard()

Last two changes go to game function, add read between time and tick:

start = time.time()

and into finally:



First question: where to keep package. For now bitbucket. Later I will move it to PyPi repository.

I thought that distributing is simple, easy and so. Wrong. It got some work required to be done.

We need to create setup.py, setup.cfg, MANIFEST.in and LICENSE file. But the most important of all, create good documentations.

Thanks to https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/ I was able to learn deploying.

Two most important commands:

python setup.py sdist
python setup.py bdist_wheel

Get with pip

Now we are able to install package by typing:

pip install git+https://bitbucket.org/kosci/charlcd.git


Package is alive ! If you want to use it just do it.
There is also a new section, see top menu.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.