Esempio n. 1
0
class ArduinoBoard(object):
    """ Represents an Arduino board. """

    def __init__(self, port):
        from PyMata.pymata import PyMata
        self._port = port
        self._board = PyMata(self._port, verbose=False)

    def set_mode(self, pin, direction, mode):
        """ Sets the mode and the direction of a given pin. """
        if mode == 'analog' and direction == 'in':
            self._board.set_pin_mode(pin,
                                     self._board.INPUT,
                                     self._board.ANALOG)
        elif mode == 'analog' and direction == 'out':
            self._board.set_pin_mode(pin,
                                     self._board.OUTPUT,
                                     self._board.ANALOG)
        elif mode == 'digital' and direction == 'in':
            self._board.set_pin_mode(pin,
                                     self._board.OUTPUT,
                                     self._board.DIGITAL)
        elif mode == 'digital' and direction == 'out':
            self._board.set_pin_mode(pin,
                                     self._board.OUTPUT,
                                     self._board.DIGITAL)
        elif mode == 'pwm':
            self._board.set_pin_mode(pin,
                                     self._board.OUTPUT,
                                     self._board.PWM)

    def get_analog_inputs(self):
        """ Get the values from the pins. """
        self._board.capability_query()
        return self._board.get_analog_response_table()

    def set_digital_out_high(self, pin):
        """ Sets a given digital pin to high. """
        self._board.digital_write(pin, 1)

    def set_digital_out_low(self, pin):
        """ Sets a given digital pin to low. """
        self._board.digital_write(pin, 0)

    def get_digital_in(self, pin):
        """ Gets the value from a given digital pin. """
        self._board.digital_read(pin)

    def get_analog_in(self, pin):
        """ Gets the value from a given analog pin. """
        self._board.analog_read(pin)

    def get_firmata(self):
        """ Return the version of the Firmata firmware. """
        return self._board.get_firmata_version()

    def disconnect(self):
        """ Disconnects the board and closes the serial connection. """
        self._board.reset()
        self._board.close()
Esempio n. 2
0
class ArduinoBoard(object):
    """ Represents an Arduino board. """

    def __init__(self, port):
        self._port = port
        self._board = PyMata(self._port, verbose=False)

    def set_mode(self, pin, direction, mode):
        """ Sets the mode and the direction of a given pin. """
        if mode == 'analog' and direction == 'in':
            self._board.set_pin_mode(pin,
                                     self._board.INPUT,
                                     self._board.ANALOG)
        elif mode == 'analog' and direction == 'out':
            self._board.set_pin_mode(pin,
                                     self._board.OUTPUT,
                                     self._board.ANALOG)
        elif mode == 'digital' and direction == 'in':
            self._board.set_pin_mode(pin,
                                     self._board.OUTPUT,
                                     self._board.DIGITAL)
        elif mode == 'digital' and direction == 'out':
            self._board.set_pin_mode(pin,
                                     self._board.OUTPUT,
                                     self._board.DIGITAL)
        elif mode == 'pwm':
            self._board.set_pin_mode(pin,
                                     self._board.OUTPUT,
                                     self._board.PWM)

    def get_analog_inputs(self):
        """ Get the values from the pins. """
        self._board.capability_query()
        return self._board.get_analog_response_table()

    def set_digital_out_high(self, pin):
        """ Sets a given digital pin to high. """
        self._board.digital_write(pin, 1)

    def set_digital_out_low(self, pin):
        """ Sets a given digital pin to low. """
        self._board.digital_write(pin, 0)

    def get_digital_in(self, pin):
        """ Gets the value from a given digital pin. """
        self._board.digital_read(pin)

    def get_analog_in(self, pin):
        """ Gets the value from a given analog pin. """
        self._board.analog_read(pin)

    def get_firmata(self):
        """ Return the version of the Firmata firmware. """
        return self._board.get_firmata_version()

    def disconnect(self):
        """ Disconnects the board and closes the serial connection. """
        self._board.reset()
        self._board.close()
Esempio n. 3
0
def signal_handler(sig, frame):
    print('You pressed Ctrl+C')
    if board is not None:
        board.reset()
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)

# Create a PyMata instance
board = PyMata("/dev/ttyACM0")

# Set the pin mode
board.servo_config(5)
board.set_pin_mode(12, board.OUTPUT, board.DIGITAL)
board.set_pin_mode(0, board.INPUT, board.ANALOG)

# Send query request to Arduino
board.capability_query()

# Some boards take a long time to respond - adjust as needed
time.sleep(5)
print("Pin Capability Report")
print(board.get_capability_query_results())

print("PyMata Digital Response Table")
print(board.get_digital_response_table())

print("PyMata Analog Response Table")
print(board.get_analog_response_table())
Esempio n. 4
0
def signal_handler(sig, frame):
    print('You pressed Ctrl+C')
    if board is not None:
        board.reset()
    sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)

# Create a PyMata instance
board = PyMata("/dev/ttyACM0")

# Set the pin mode
board.servo_config(5)
board.set_pin_mode(12, board.OUTPUT, board.DIGITAL)
board.set_pin_mode(0, board.INPUT, board.ANALOG)

# Send query request to Arduino
board.capability_query()

# Some boards take a long time to respond - adjust as needed
time.sleep(5)
print("Pin Capability Report")
print(board.get_capability_query_results())

print("PyMata Digital Response Table")
print(board.get_digital_response_table())

print("PyMata Analog Response Table")
print(board.get_analog_response_table())