Ejemplo n.º 1
0
    def __init__(
        self,
        E: int,
        RS: int,
        D4: int,
        D5: int,
        D6: int,
        D7: int,
        command: bool,
        chars_per_line: int = 16,
        char_mode: bool = True,
    ):
        """
        Initialize and clear display
        """
        self.command = command
        self.E = E
        self.RS = RS
        self.D4 = D4
        self.D5 = D5
        self.D6 = D6
        self.D7 = D7
        self.hi_bits = {0x10: D4, 0x20: D5, 0x40: D6, 0x80: D7}
        self.lo_bits = {0x01: D4, 0x02: D5, 0x04: D6, 0x08: D7}
        self.chars_per_line = chars_per_line
        self.char_mode = char_mode

        GPIO.setwarnings(False)

        # Use BCM GPIO numbers
        GPIO.setmode(GPIO.BCM)

        # Set GPIO's to output mode
        for pin in [E, RS, D4, D5, D6, D7]:
            GPIO.setup(pin, GPIO.OUT)

        self.write(0x33, command)  # Initialize
        self.write(0x32, command)  # Set to 4-bit mode
        self.write(0x06, command)  # Cursor move direction
        self.write(0x0C, command)  # Turn cursor off
        self.write(0x28, command)  # 2 line display
        self.write(0x01, command)  # Clear display

        # Delay to allow commands to process
        time.sleep(0.0005)
Ejemplo n.º 2
0
    def __init__(self, cs_pin, clock_pin, data_pin, units="c", board=GPIO.BCM):
        """Initialize Soft (Bitbang) SPI bus

        Parameters:
        - cs_pin:    Chip Select (CS) / Slave Select (SS) pin (Any GPIO)
        - clock_pin: Clock (SCLK / SCK) pin (Any GPIO)
        - data_pin:  Data input (SO / MOSI) pin (Any GPIO)
        - units:     (optional) unit of measurement to return. ("c" (default) | "k" | "f")
        - board:     (optional) pin numbering method as per RPi.GPIO library (GPIO.BCM (default) | GPIO.BOARD)

        """
        self.cs_pin = cs_pin
        self.clock_pin = clock_pin
        self.data_pin = data_pin
        self.units = units
        self.data = None
        self.board = board

        # Initialize needed GPIO
        GPIO.setmode(self.board)
        GPIO.setup(self.cs_pin, GPIO.OUT)
        GPIO.setup(self.clock_pin, GPIO.OUT)
        GPIO.setup(self.data_pin, GPIO.IN)

        # Pull chip select high to make chip inactive
        GPIO.output(self.cs_pin, GPIO.HIGH)
Ejemplo n.º 3
0
 def cleanup(self):
     """Selective GPIO cleanup"""
     GPIO.setup(self.cs_pin, GPIO.IN)
     GPIO.setup(self.clock_pin, GPIO.IN)
Ejemplo n.º 4
0
    if config.max6675:
        from kilner.max6675 import MAX6675, MAX6675Error

        log.info("import MAX6675")
    sensor_available = True
except ImportError:
    log.exception(
        "Could not initialize temperature sensor, using dummy values!")
    sensor_available = False

try:
    from kilner.config import GPIO

    GPIO.setmode(GPIO.BCM)
    GPIO.setwarnings(False)
    GPIO.setup(config.gpio_heat, GPIO.OUT)
    #    GPIO.setup(config.gpio_cool, GPIO.OUT)
    #    GPIO.setup(config.gpio_air, GPIO.OUT)
    #    GPIO.setup(config.gpio_door, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    gpio_available = True
except ImportError:
    msg = "Could not initialize GPIOs, oven operation will only be simulated!"
    log.warning(msg)
    gpio_available = False


class Oven(threading.Thread):
    STATE_IDLE = "IDLE"
    STATE_RUNNING = "RUNNING"