Esempio n. 1
0
 def _set_cursor_mode(self, value):
     #         if not value in CursorMode:
     #             print ('ValueError(Cursor mode must be of ``CursorMode`` type.)')
     self._cursor_mode = int(value)
     self.command(LCD_DISPLAYCONTROL | self._display_mode
                  | self._cursor_mode)
     hwtimers.sleep_micros(50)
Esempio n. 2
0
 def _set_display_enabled(self, value):
     if value:
         self._display_mode = LCD_DISPLAYON 
     else:
         self._display_mode = LCD_DISPLAYOFF
     self.command(LCD_DISPLAYCONTROL | self._display_mode | self._cursor_mode)
     hwtimers.sleep_micros(50)
Esempio n. 3
0
 def _set_display_enabled(self, value):
     if value:
         self._display_mode = LCD_DISPLAYON
     else:
         self._display_mode = LCD_DISPLAYOFF
     self.command(LCD_DISPLAYCONTROL | self._display_mode
                  | self._cursor_mode)
     hwtimers.sleep_micros(50)
Esempio n. 4
0
    def _set_cursor_pos(self, value):
#         if not hasattr(value, '__getitem__') or len(value) != 2:
#             raise ValueError('Cursor position should be determined by a 2-tuple.')
        if value[0] not in range(self.lcd[0]) or value[1] not in range(self.lcd[1]):
            msg = 'Cursor position {pos!r} invalid on a {lcd.rows}x{lcd.cols} LCD.'
#             raise ValueError(msg.format(pos=value, lcd=self.lcd))
        row_offsets = [0x00, 0x40, self.lcd[1], 0x40 + self.lcd[1]]
        self._cursor_pos = value
        self.command(LCD_SETDDRAMADDR | row_offsets[value[0]] + value[1])
        hwtimers.sleep_micros(50)
Esempio n. 5
0
 def shift_display(self, amount):
     """Shift the display. Use negative amounts to shift left and positive
     amounts to shift right."""
     if amount == 0:
         return
     if amount > 0:
         direction = LCD_MOVERIGHT
     else:
         direction = LCD_MOVELEFT
     for i in range(abs(amount)):
         self.command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | direction)
         hwtimers.sleep_micros(50)
Esempio n. 6
0
 def shift_display(self, amount):
     """Shift the display. Use negative amounts to shift left and positive
     amounts to shift right."""
     if amount == 0:
         return
     if amount >0 :
         direction = LCD_MOVERIGHT 
     else :
         direction = LCD_MOVELEFT
     for i in range(abs(amount)):
         self.command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | direction)
         hwtimers.sleep_micros(50)
Esempio n. 7
0
    def _microSample(self):
        # """
        # .. method:: _microSample()

        # Starts a loop to acquire samples every _samplingTime microseconds
        # """
        while True:
            if self._samplingTime:
                self._getValue(self._samplingGetType)
                hwtimers.sleep_micros(self._samplingTime)
            else:
                break
Esempio n. 8
0
    def _set_cursor_pos(self, value):
        #         if not hasattr(value, '__getitem__') or len(value) != 2:
        #             raise ValueError('Cursor position should be determined by a 2-tuple.')
        if value[0] not in range(self.lcd[0]) or value[1] not in range(
                self.lcd[1]):
            msg = 'Cursor position {pos!r} invalid on a {lcd.rows}x{lcd.cols} LCD.'


#             raise ValueError(msg.format(pos=value, lcd=self.lcd))
        row_offsets = [0x00, 0x40, self.lcd[1], 0x40 + self.lcd[1]]
        self._cursor_pos = value
        self.command(LCD_SETDDRAMADDR | row_offsets[value[0]] + value[1])
        hwtimers.sleep_micros(50)
Esempio n. 9
0
    def sendRaw(self,x):
        """
        .. method:: sendRaw(data)

            Sends raw data by taking as input a list of pulses duration in microseconds. The first represents the duration of IR firing phase (state 1) while the the second is the IR LED  OFF phase (state 0) and so on.
       
        """
    
        state = 1
        for pulse in x: 
            npulse=pulse//self.period
            #print("npulse",npulse)
            if state:
                pwm.write(self.senderPin,self.period,self.duty,MICROS,npulse)
            else:
                hwtimers.sleep_micros(pulse)
            state = state^1
Esempio n. 10
0
    def sendRaw(self, x):
        """
        .. method:: sendRaw(data)

            Sends raw data by taking as input a list of pulses duration in microseconds. The first represents the duration of IR firing phase (state 1) while the the second is the IR LED  OFF phase (state 0) and so on.
       
        """

        state = 1
        for pulse in x:
            npulse = pulse // self.period
            #print("npulse",npulse)
            if state:
                pwm.write(self.senderPin, self.period, self.duty, MICROS,
                          npulse)
            else:
                hwtimers.sleep_micros(pulse)
            state = state ^ 1
Esempio n. 11
0
 def _pulse_enable(self):
     """Pulse the `enable` flag to process data."""
     digitalWrite(self.pin_e, 0)
     hwtimers.sleep_micros(1)
     digitalWrite(self.pin_e, 1)
     hwtimers.sleep_micros(1)
     digitalWrite(self.pin_e, 0)
     hwtimers.sleep_micros(100)  # commands need > 37us to settle
Esempio n. 12
0
 def _pulse_enable(self):
     """Pulse the `enable` flag to process data."""
     digitalWrite(self.pin_e, 0)
     hwtimers.sleep_micros(1)
     digitalWrite(self.pin_e, 1)
     hwtimers.sleep_micros(1)
     digitalWrite(self.pin_e, 0)
     hwtimers.sleep_micros(100)  # commands need > 37us to settle
Esempio n. 13
0
    def __init__(self,
                 pin_rs=15,
                 pin_rw=18,
                 pin_e=16,
                 pins_data=[21, 22, 23, 24],
                 cols=20,
                 rows=4,
                 dotsize=8):
        """
        Character LCD controller.

        The default pin numbers are based on the BOARD numbering scheme (1-26).

        You can save 1 pin by not using RW. Set ``pin_rw`` to ``None`` if you
        want this.

        Args:
            pin_rs:
                Pin for register select (RS). Default: 15.
            pin_rw:
                Pin for selecting read or write mode (R/W). Set this to
                ``None`` for read only mode. Default: 18.
            pin_e:
                Pin to start data read or write (E). Default: 16.
            pins_data:
                List of data bus pins in 8 bit mode (DB0-DB7) or in 8 bit mode
                (DB4-DB7) in ascending order. Default: [21, 22, 23, 24].
            numbering_mode:
                Which scheme to use for numbering of the GPIO pins, either
                ``GPIO.BOARD`` or ``GPIO.BCM``.  Default: ``GPIO.BOARD`` (1-26).
            rows:
                Number of display rows (usually 1, 2 or 4). Default: 4.
            cols:
                Number of columns per row (usually 16 or 20). Default 20.
            dotsize:
                Some 1 line displays allow a font height of 10px.
                Allowed: 8 or 10. Default: 8.

        Returns:
            A :class:`CharLCD` instance.

        """

        # Set attributes
        print('start init')
        if len(pins_data) == 4:  # 4 bit mode
            self.data_bus_mode = LCD_4BITMODE
            block1 = [None] * 4
        elif len(pins_data) == 8:  # 8 bit mode
            self.data_bus_mode = LCD_8BITMODE
            block1 = pins_data[:4]

        block2 = pins_data[-4:]

        self.pin_e = pin_e
        self.pin_rw = pin_rw
        self.pin_rs = pin_rs
        self.pins = (pin_rs, pin_rw, pin_e, block1[0], block1[1], block1[2],
                     block1[3], block2[0], block2[1], block2[2], block2[3])
        self.lcd = (rows, cols, dotsize)
        print('Setup GPIO')

        for pin in self.pins:
            if pin != None:
                pinMode(pin, OUTPUT)
        print('Setup initial display configuration')
        # Setup initial display configuration
        displayfunction = self.data_bus_mode | LCD_5x8DOTS
        if rows == 1:
            displayfunction |= LCD_1LINE
        elif rows in [2, 4]:
            # LCD only uses two lines on 4 row displays
            displayfunction |= LCD_2LINE
        if dotsize == 10:
            # For some 1 line displays you can select a 10px font.
            displayfunction |= LCD_5x10DOTS

        # Create content cache
        self._content = [[0x20] * cols for _ in range(rows)]
        print('Initialization')
        # Initialization
        hwtimers.sleep_micros(50 * 1000)
        print('sleeped', pin_rs)
        digitalWrite(pin_rs, LOW)
        print(pin_rs, ' rs LOW')
        digitalWrite(pin_e, 0)
        print(pin_e, ' e LOW')
        if pin_rw is not None:
            digitalWrite(pin_rw, 0)
        print('Choose 4 or 8 bit')
        # Choose 4 or 8 bit mode
        if self.data_bus_mode == LCD_4BITMODE:
            # Hitachi manual page 46
            self._write4bits(0x03)
            hwtimers.sleep_micros(4500)
            self._write4bits(0x03)
            hwtimers.sleep_micros(4500)
            self._write4bits(0x03)
            hwtimers.sleep_micros(100)
            self._write4bits(0x02)
        elif self.data_bus_mode == LCD_8BITMODE:
            # Hitachi manual page 45
            self._write8bits(0x30)
            hwtimers.sleep_micros(4500)
            self._write8bits(0x30)
            hwtimers.sleep_micros(100)
            self._write8bits(0x30)
#         else:
#             raise ValueError('Invalid data bus mode: {}'.format(self.data_bus_mode))
        print('Write configuration to display')
        # Write configuration to display
        self.command(LCD_FUNCTIONSET | displayfunction)
        hwtimers.sleep_micros(50)
        print('configure')
        # Configure display mode
        self._display_mode = LCD_DISPLAYON
        self._cursor_mode = LCD_CURSOROFF | LCD_BLINKOFF
        self.command(LCD_DISPLAYCONTROL | self._display_mode
                     | self._cursor_mode)
        hwtimers.sleep_micros(50)

        # Clear display
        self.clear()

        # Configure entry mode
        self._text_align_mode = LCD_ENTRYLEFT
        self._display_shift_mode = LCD_ENTRYSHIFTDECREMENT
        self._cursor_pos = (0, 0)
        self.command(LCD_ENTRYMODESET | self._text_align_mode
                     | self._display_shift_mode)
        hwtimers.sleep_micros(50)
        print('init done')
Esempio n. 14
0
 def _set_write_shift_mode(self, value):
     self._display_shift_mode = int(value)
     self.command(LCD_ENTRYMODESET | self._text_align_mode | self._display_shift_mode)
     hwtimers.sleep_micros(50)
Esempio n. 15
0
 def home(self):
     """Set cursor to initial position and reset any shifting."""
     self.command(LCD_RETURNHOME)
     self._cursor_pos = (0, 0)
     hwtimers.sleep_micros(2000)
Esempio n. 16
0
 def clear(self):
     """Overwrite display with blank characters and reset cursor position."""
     self.command(LCD_CLEARDISPLAY)
     self._cursor_pos = (0, 0)
     self._content = [[0x20] * self.lcd[1] for _ in range(self.lcd[0])]
     hwtimers.sleep_micros(2000)
Esempio n. 17
0
    def _set_cursor_mode(self, value):
#         if not value in CursorMode:
#             print ('ValueError(Cursor mode must be of ``CursorMode`` type.)')
        self._cursor_mode = int(value)
        self.command(LCD_DISPLAYCONTROL | self._display_mode | self._cursor_mode)
        hwtimers.sleep_micros(50)
Esempio n. 18
0
 def clear(self):
     """Overwrite display with blank characters and reset cursor position."""
     self.command(LCD_CLEARDISPLAY)
     self._cursor_pos = (0, 0)
     self._content = [[0x20] * self.lcd[1] for _ in range(self.lcd[0])]
     hwtimers.sleep_micros(2000)
Esempio n. 19
0
 def _set_write_shift_mode(self, value):
     self._display_shift_mode = int(value)
     self.command(LCD_ENTRYMODESET | self._text_align_mode
                  | self._display_shift_mode)
     hwtimers.sleep_micros(50)
Esempio n. 20
0
 def home(self):
     """Set cursor to initial position and reset any shifting."""
     self.command(LCD_RETURNHOME)
     self._cursor_pos = (0, 0)
     hwtimers.sleep_micros(2000)
Esempio n. 21
0
    def __init__(self, pin_rs=15, pin_rw=18, pin_e=16, pins_data=[21, 22, 23, 24],
                       cols=20, rows=4, dotsize=8):
        """
        Character LCD controller.

        The default pin numbers are based on the BOARD numbering scheme (1-26).

        You can save 1 pin by not using RW. Set ``pin_rw`` to ``None`` if you
        want this.

        Args:
            pin_rs:
                Pin for register select (RS). Default: 15.
            pin_rw:
                Pin for selecting read or write mode (R/W). Set this to
                ``None`` for read only mode. Default: 18.
            pin_e:
                Pin to start data read or write (E). Default: 16.
            pins_data:
                List of data bus pins in 8 bit mode (DB0-DB7) or in 8 bit mode
                (DB4-DB7) in ascending order. Default: [21, 22, 23, 24].
            numbering_mode:
                Which scheme to use for numbering of the GPIO pins, either
                ``GPIO.BOARD`` or ``GPIO.BCM``.  Default: ``GPIO.BOARD`` (1-26).
            rows:
                Number of display rows (usually 1, 2 or 4). Default: 4.
            cols:
                Number of columns per row (usually 16 or 20). Default 20.
            dotsize:
                Some 1 line displays allow a font height of 10px.
                Allowed: 8 or 10. Default: 8.

        Returns:
            A :class:`CharLCD` instance.

        """

        # Set attributes
        print('start init')
        if len(pins_data) == 4:  # 4 bit mode
            self.data_bus_mode = LCD_4BITMODE
            block1 = [None] * 4
        elif len(pins_data) == 8:  # 8 bit mode
            self.data_bus_mode = LCD_8BITMODE
            block1 = pins_data[:4]

        block2 = pins_data[-4:]

        self.pin_e=pin_e
        self.pin_rw=pin_rw
        self.pin_rs=pin_rs
        self.pins=(pin_rs,pin_rw,pin_e,block1[0], block1[1], block1[2], block1[3],
                             block2[0], block2[1], block2[2], block2[3])
        self.lcd = (rows, cols, dotsize)
        print('Setup GPIO')

        for pin in self.pins:
            if pin!=None:
                pinMode (pin,OUTPUT)
        print('Setup initial display configuration')
        # Setup initial display configuration
        displayfunction = self.data_bus_mode | LCD_5x8DOTS
        if rows == 1:
            displayfunction |= LCD_1LINE
        elif rows in [2, 4]:
            # LCD only uses two lines on 4 row displays
            displayfunction |= LCD_2LINE
        if dotsize == 10:
            # For some 1 line displays you can select a 10px font.
            displayfunction |= LCD_5x10DOTS

        # Create content cache
        self._content = [[0x20] * cols for _ in range(rows)]
        print('Initialization')
        # Initialization
        hwtimers.sleep_micros(50*1000)
        print('sleeped',pin_rs)
        digitalWrite(pin_rs, LOW)
        print(pin_rs,' rs LOW')
        digitalWrite(pin_e, 0)
        print(pin_e,' e LOW')
        if pin_rw is not None:
            digitalWrite(pin_rw, 0)
        print('Choose 4 or 8 bit')
        # Choose 4 or 8 bit mode
        if self.data_bus_mode == LCD_4BITMODE:
            # Hitachi manual page 46
            self._write4bits(0x03)
            hwtimers.sleep_micros(4500)
            self._write4bits(0x03)
            hwtimers.sleep_micros(4500)
            self._write4bits(0x03)
            hwtimers.sleep_micros(100)
            self._write4bits(0x02)
        elif self.data_bus_mode == LCD_8BITMODE:
            # Hitachi manual page 45
            self._write8bits(0x30)
            hwtimers.sleep_micros(4500)
            self._write8bits(0x30)
            hwtimers.sleep_micros(100)
            self._write8bits(0x30)
#         else:
#             raise ValueError('Invalid data bus mode: {}'.format(self.data_bus_mode))
        print('Write configuration to display')
        # Write configuration to display
        self.command(LCD_FUNCTIONSET | displayfunction)
        hwtimers.sleep_micros(50)
        print('configure')
        # Configure display mode
        self._display_mode = LCD_DISPLAYON
        self._cursor_mode = LCD_CURSOROFF | LCD_BLINKOFF
        self.command(LCD_DISPLAYCONTROL | self._display_mode | self._cursor_mode)
        hwtimers.sleep_micros(50)

        # Clear display
        self.clear()

        # Configure entry mode
        self._text_align_mode = LCD_ENTRYLEFT
        self._display_shift_mode = LCD_ENTRYSHIFTDECREMENT
        self._cursor_pos = (0, 0)
        self.command(LCD_ENTRYMODESET | self._text_align_mode | self._display_shift_mode)
        hwtimers.sleep_micros(50)
        print('init done')