Пример #1
0
 def _list_pins(self):
     pins = []
     for location, gpio_id in enumerate(pin_list):
         path = self._base_pin_path(gpio_id)
         if os.path.exists(path):
             pins.append(DigitalPin(self, location, gpio_id))
     return pins
Пример #2
0
    def __init__(self, port=None, baud_rate=MAX_BAUD_RATE):
        try:
            import pyfirmata
        except ImportError:
            msg = 'pingo.arduino.Arduino requires pyfirmata installed'
            raise SystemExit(msg)

        super(ArduinoFirmata, self).__init__()
        self.port = port
        self.baud_rate = baud_rate
        try:
            self.firmata = pyfirmata.Arduino(self.port,
                                             baudrate=self.baud_rate)
        except OSError:
            raise OSError('Could find %r' % self.port)

        self.serial_iterator = pyfirmata.util.Iterator(self.firmata)
        self.serial_iterator.daemon = True

        self.add_pins([
            DigitalPin(self, location) for location in range(LEN_DIGITAL_PINS)
        ] + [
            AnalogPin(self, 'A%s' % location, resolution=10)
            for location in range(LEN_ANALOG_PINS)
        ])
Пример #3
0
 def __init__(self):
     self._add_pins([
         DigitalPin(self, location)
         for location in range(self.LEN_DIGITAL_PINS)
     ] + [
         AnalogPin(self, 'A%s' % location, resolution=bits)
         for location, bits in enumerate(self.ANALOG_PIN_RESOLUTIONS)
     ])
Пример #4
0
    def __init__(self):

        digital_pins = [
            DigitalPin(self, location, gpio)
            for location, gpio in self.DIGITAL_PINS_MAP.items()
        ]

        self._add_pins(digital_pins)

        for p in digital_pins:
            print p.location, p.gpio_id
Пример #5
0
    def __init__(self, port=None):
        try:
            import pyfirmata
        except ImportError:
            msg = 'pingo.arduino.Arduino requires pyfirmata installed'
            raise SystemExit(msg)

        super(ArduinoFirmata, self).__init__()
        self.port = port
        try:
            self.firmata = pyfirmata.Arduino(self.port)
        except OSError:
            raise OSError('Could find %r' % self.port)

        self.add_pins(DigitalPin(self, location)
                      for location in range(LEN_DIGITAL_PINS))
Пример #6
0
    def __init__(self, port=None):
        try:
            from PyMata.pymata import PyMata
        except ImportError:
            msg = 'pingo.arduino.Arduino requires PyMata installed'
            raise ImportError(msg)

        super(ArduinoFirmata, self).__init__()
        self.port = port
        self.PyMata = PyMata(self.port)

        detected_digital_pins = len(
            self.PyMata._command_handler.digital_response_table)
        detected_analog_pins = len(
            self.PyMata._command_handler.analog_response_table)

        self._add_pins([
            DigitalPin(self, location)
            for location in range(detected_digital_pins)
        ] + [
            AnalogPin(self, 'A%s' % location, resolution=10)
            for location in range(detected_analog_pins)
        ])
Пример #7
0
    def __init__(self, port=None):
        try:
            from PyMata.pymata import PyMata as PyMata  # noqa
        except ImportError:
            msg = 'pingo.arduino.Arduino requires PyMata installed'
            raise ImportError(msg)

        super(ArduinoFirmata, self).__init__()
        self.port = port
        self.firmata_client = PyMata(self.port, verbose=VERBOSE)

        self.firmata_client.capability_query()
        time.sleep(10)  # TODO: Find a small and safe value
        capability_query_results = self.firmata_client.get_capability_query_results(
        )
        capability_dict = pin_list_to_board_dict(capability_query_results)

        self._add_pins([
            DigitalPin(self, location)
            for location in capability_dict['digital']
        ] + [PwmPin(self, location) for location in capability_dict['pwm']] + [
            AnalogPin(self, 'A%s' % location, resolution=10)
            for location in capability_dict['analog']
        ])
Пример #8
0
 def __init__(self):
     self.add_pins(DigitalPin(self, location)
                   for location in range(14))