Beispiel #1
0
    def __init__(self,
                 pins=[],
                 rs_pin=None,
                 en_pin=None,
                 debug=False,
                 **kwargs):
        """ Initializes the GPIO-driven HD44780 display

        All GPIOs passed as arguments will be used with BCM mapping.        

        Kwargs:
           * ``pins``: list of GPIO pins for driving display data bits in format [DB4, DB5, DB6, DB7]
           * ``en_pin``: EN pin GPIO number. Please, make sure it's pulled down to GND (10K is OK). Otherwise, block might start filling up the screen unexpectedly.
           * ``rs_pin``: RS pin GPIO number,
           * ``debug``: enables printing out LCD commands.
           * ``**kwargs``: all the other arguments, get passed further to HD44780 constructor

        """
        self.debug = debug
        self.rs_pin = rs_pin
        self.en_pin = en_pin
        self.pins = pins
        GPIO.setmode(GPIO.BCM)
        if not self.debug:
            GPIO.setwarnings(False)
        GPIO.setup(self.en_pin, GPIO.OUT)
        GPIO.setup(self.rs_pin, GPIO.OUT)
        for pin in self.pins:
            GPIO.setup(pin, GPIO.OUT)
        HD44780.__init__(self, debug=self.debug, **kwargs)
Beispiel #2
0
    def __init__(self, pins = [], rs_pin = None, en_pin = None, debug = False, **kwargs):
        """ Initializes the GPIO-driven HD44780 display

        All GPIOs passed as arguments will be used with BCM mapping.        

        Kwargs:
           * ``pins``: list of GPIO pins for driving display data bits in format [DB4, DB5, DB6, DB7]
           * ``en_pin``: EN pin GPIO number. Please, make sure it's pulled down to GND (10K is OK). Otherwise, block might start filling up the screen unexpectedly.
           * ``rs_pin``: RS pin GPIO number,
           * ``debug``: enables printing out LCD commands.
           * ``**kwargs``: all the other arguments, get passed further to HD44780 constructor

        """
        self.debug = debug
        self.rs_pin = rs_pin
        self.en_pin = en_pin
        self.pins = pins
        GPIO.setmode(GPIO.BCM)
        if not self.debug:
            GPIO.setwarnings(False)
        GPIO.setup(self.en_pin, GPIO.OUT)
        GPIO.setup(self.rs_pin, GPIO.OUT)
        for pin in self.pins:
            GPIO.setup(pin, GPIO.OUT)
        HD44780.__init__(self, debug = self.debug, **kwargs)
Beispiel #3
0
 def __init__(self, bus=1, addr=0x27, debug=False, **kwargs):
     self.bus_num = bus
     self.bus = smbus.SMBus(self.bus_num)
     if type(addr) in [str, unicode]:
         addr = int(addr, 16)
     self.addr = addr
     self.debug = debug
     self.i2c_init()
     HD44780.__init__(self, debug=self.debug, **kwargs)
Beispiel #4
0
    def __init__(self, port=None, speed=9600, debug=False**kwargs):
        """Initialises the ``Screen`` object.  
                                                                               
        Kwargs:                                                                  
                                                                                 
            * ``port``: serial port path
            * ``speed``: serial port speed
            * ``debug``: enables printing out LCD commands.
            * ``**kwargs``: all the other arguments, get passed further to HD44780 constructor

        """
        self.port_path = port
        self.speed = speed
        self.port = Serial(self.port_path, self.speed)
        self.debug = debug
        HD44780.__init__(self, debug=self.debug, **kwargs)
Beispiel #5
0
    def __init__(self, port=None, speed=9600, debug=False **kwargs):
        """Initialises the ``Screen`` object.  
                                                                               
        Kwargs:                                                                  
                                                                                 
            * ``port``: serial port path
            * ``speed``: serial port speed
            * ``debug``: enables printing out LCD commands.
            * ``**kwargs``: all the other arguments, get passed further to HD44780 constructor

        """
        self.port_path = port
        self.speed = speed
        self.port = Serial(self.port_path, self.speed)
        self.debug = debug
        HD44780.__init__(self, debug=self.debug, **kwargs)
Beispiel #6
0
 def __init__(self, pins = [], rs_pin = None, en_pin = None, debug = False, **kwargs):
     """ Initializes the GPIO-driven HD44780 display
     
     Kwargs:
        * ``pins``: list of GPIO pins for driving display data bits: [DB4, DB5, DB6, DB7]"""
     self.debug = debug
     self.rs_pin = rs_pin
     self.en_pin = en_pin
     self.pins = pins
     GPIO.setmode(GPIO.BCM)
     if not self.debug:
         GPIO.setwarnings(False)
     GPIO.setup(self.en_pin, GPIO.OUT)
     GPIO.setup(self.rs_pin, GPIO.OUT)
     for pin in self.pins:
         GPIO.setup(pin, GPIO.OUT)
     HD44780.__init__(self, debug = self.debug, **kwargs)
Beispiel #7
0
    def __init__(self, bus=1, addr=0x20, debug=False, **kwargs):
        """Initialises the ``Screen`` object.  
                                                                               
        Kwargs:                                                                  
                                                                                 
            * ``bus``: I2C bus number.
            * ``addr``: I2C address of the board.
            * ``debug``: enalbes printing out LCD commands.
            * ``chinese``: flag enabling workarounds necessary for Chinese boards to enable LCD backlight.

        """
        self.bus_num = bus
        self.bus = smbus.SMBus(self.bus_num)
        if type(addr) in [str, unicode]:
            addr = int(addr, 16)
        self.addr = addr
        self.debug = debug
        HD44780.__init__(self, debug=self.debug, **kwargs)
Beispiel #8
0
    def __init__(self, bus=1, addr=0x27, debug=False, **kwargs):
        """Initialises the ``Screen`` object.  
                                                                               
        Kwargs:                                                                  
                                                                                 
            * ``bus``: I2C bus number.
            * ``addr``: I2C address of the board.
            * ``debug``: enables printing out LCD commands.
            * ``**kwargs``: all the other arguments, get passed further to HD44780 constructor

        """
        self.bus_num = bus
        self.bus = smbus.SMBus(self.bus_num)
        if type(addr) in [str, unicode]:
            addr = int(addr, 16)
        self.addr = addr
        self.debug = debug
        self.i2c_init()
        HD44780.__init__(self, debug=self.debug, **kwargs)
Beispiel #9
0
    def __init__(self, bus=1, addr=0x20, debug=False, **kwargs):
        """Initialises the ``Screen`` object.  
                                                                               
        Kwargs:                                                                  
                                                                                 
            * ``bus``: I2C bus number.
            * ``addr``: I2C address of the board.
            * ``debug``: enalbes printing out LCD commands.
            * ``chinese``: flag enabling workarounds necessary for Chinese boards to enable LCD backlight.

        """
        self.bus_num = bus
        self.bus = smbus.SMBus(self.bus_num)
        if type(addr) in [str, unicode]:
            addr = int(addr, 16)
        self.addr = addr
        self.debug = debug
        BacklightManager.init_backlight(self, **kwargs)
        HD44780.__init__(self, debug=self.debug, **kwargs)
Beispiel #10
0
    def __init__(self, bus=1, addr=0x27, debug=False, **kwargs):
        """Initialises the ``Screen`` object.  
                                                                               
        Kwargs:                                                                  
                                                                                 
            * ``bus``: I2C bus number.
            * ``addr``: I2C address of the board.
            * ``debug``: enables printing out LCD commands.
            * ``**kwargs``: all the other arguments, get passed further to HD44780 constructor

        """
        self.bus_num = bus
        self.bus = smbus.SMBus(self.bus_num)
        if type(addr) in [str, unicode]:
            addr = int(addr, 16)
        self.addr = addr
        self.debug = debug
        self.i2c_init()
        HD44780.__init__(self, debug=self.debug, **kwargs)
Beispiel #11
0
 def __init__(self, values, lcd_config):
     cfg = json.load(open(lcd_config)) if lcd_config else {}
     self._lcd = HD44780(**cfg.get("hd44780", {}))
     self._line_mapping = {}
     mapping = cfg.get("line_mapping", {1:0, 2:1, 3:2, 5:3, 4:4, 6:5})
     for key, value in mapping.items():
         self._line_mapping[int(key)] = int(value)
     self._outdated = datetime.timedelta(**cfg.get("outdated", {"hours": 1}))
     self._debug = cfg.get("debug", False)
     self._values = values
     for v in values.values():
         self.update(v)
Beispiel #12
0
def test_lcd_initialization():
    t = FakeTransport()
    lcd = HD44780(t, backlight=LCD_BACKLIGHT_OFF)
    lcd.init_lcd()

    expected = (
        toggle_enable(0b0011_0000) * 3 +
        # 4bits mode set
        toggle_enable(0b0010_0000) +
        # 4bits mode set, 2 lines, 8x5 font
        toggle_enable(0b0010_0000) + toggle_enable(0b1000_0000) +
        # display off
        toggle_enable(0b0000_0000) + toggle_enable(0b1000_0000) +
        # clear screen
        toggle_enable(0b0000_0000) + toggle_enable(0b0001_0000) +
        # entry mode set
        toggle_enable(0b0000_0000) + toggle_enable(0b0110_0000))

    assert t.bytes == expected
def main():
    with SMBusTransport(BUS, DEVICE_ADDRESS) as t:
        lcd = HD44780(t)

        lcd.init_lcd()

        lcd.execute(InstructionFactory.display_on_off(LCD_DISPLAY_ON))
        lcd.execute(InstructionFactory.set_ddram_address(0))
        lcd.execute(InstructionFactory.write_data(0b01001000))
        lcd.execute(InstructionFactory.write_data(0b01100101))
        lcd.execute(InstructionFactory.write_data(0b01101100))
        lcd.execute(InstructionFactory.write_data(0b01101100))
        lcd.execute(InstructionFactory.write_data(0b01101111))

        # From table 5: the first cgram starts at address 0
        lcd.execute(InstructionFactory.set_cgram_address(0b000000))
        lcd.execute(InstructionFactory.write_data(0b00000000))
        lcd.execute(InstructionFactory.write_data(0b00000010))
        lcd.execute(InstructionFactory.write_data(0b00011111))
        lcd.execute(InstructionFactory.write_data(0b00011110))
        lcd.execute(InstructionFactory.write_data(0b00011100))
        lcd.execute(InstructionFactory.write_data(0b00011000))
        lcd.execute(InstructionFactory.write_data(0b00010000))
        lcd.execute(InstructionFactory.write_data(0b00000000))

        lcd.execute(InstructionFactory.set_ddram_address(0x40))
        lcd.execute(InstructionFactory.write_data(0b00100000))
        lcd.execute(InstructionFactory.write_data(0b00100000))
        lcd.execute(InstructionFactory.write_data(0b00000000))
        lcd.execute(InstructionFactory.write_data(0b00000000))
        lcd.execute(InstructionFactory.write_data(0b00000000))
        lcd.execute(InstructionFactory.write_data(0b00000000))
        lcd.execute(InstructionFactory.write_data(0b00000000))
        lcd.execute(InstructionFactory.write_data(0b00000000))
        lcd.execute(InstructionFactory.write_data(0b00000000))
        lcd.execute(InstructionFactory.write_data(0b00000000))
Beispiel #14
0
#!/usr/bin/python

import RPi.GPIO as GPIO

from hd44780 import HD44780
from datetime import datetime
from time import sleep
import socket

if __name__ == '__main__':
    # init LCD
    lcd = HD44780(24, 23, [22, 10, 9, 11])

    # countdown each 0.05sec
    fact = 0.05
    range_max = int(10 / fact)

    # GPIO setup for input
    GPIO.setup(4, GPIO.IN)
    GPIO.setup(17, GPIO.IN)

    # first display host ip
    is_reset = False
    ip = socket.gethostbyname('rpi.local')
    lcd.message(" IP\n " + ip)

    # main loop
    while True:

        # GPIO17 on is game start
        while True:
Beispiel #15
0
from hd44780 import HD44780
from datetime import datetime
from time import sleep

lcd = HD44780()

while True:
    sleep(1)
    lcd.clear()
    lcd.message(datetime.now().strftime('  %I : %M : %S \n%a %b %d %Y'))