当前位置: 首页>>代码示例>>Python>>正文


Python pymata.PyMata类代码示例

本文整理汇总了Python中PyMata.pymata.PyMata的典型用法代码示例。如果您正苦于以下问题:Python PyMata类的具体用法?Python PyMata怎么用?Python PyMata使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PyMata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setupLED

def setupLED():
  global PWM_pin
  global board
  PWM_pin = 5
  # use pin D5 as pwm to adjest LED.
  board = PyMata('/dev/ttyS0', verbose = True)
  board.set_pin_mode(PWM_pin, board.PWM, board.DIGITAL)
  print "Start PWM test by pin D5"
开发者ID:huanglw1333,项目名称:linkit_smart,代码行数:8,代码来源:mcs_LED_PWM_control.py

示例2: __init__

 def __init__(self, port_id='/dev/ttyACM0', bluetooth=True, verbose=True):
     # PyMata is an old style class so you can't use super.
     PyMata.__init__(self, port_id, bluetooth, verbose)
     # Setup handler for response data.
     # Note that the data length (1) appears to be unused for these sysex
     # responses.
     self._command_handler.command_dispatch.update({CP_COMMAND: [self._response_handler, 1]})
     # Setup configured callbacks to null.
     self._accel_callback = None
     self._tap_callback = None
     self._temp_callback = None
     self._cap_callback = None
开发者ID:jdgwartney,项目名称:CircuitPlaygroundFirmata,代码行数:12,代码来源:circuitplayground.py

示例3: smartkitdata

class smartkitdata(object):
    def __init__(self):
        self.board = PyMata(ARDUINO_ADDRESS)
        self.board.set_pin_mode(1, self.board.INPUT, self.board.ANALOG)
        self._data = self.gen_data()

    def get_data(self):
        return pd.DataFrame(self._data)[-60:]

    def update_data(self):
        self._data = np.vstack([self._data, self.gen_data()])

    def gen_data(self):
        return np.array(self.board.analog_read(1))
开发者ID:FLODA-org,项目名称:prototype-pro40,代码行数:14,代码来源:smartkitdata_testfirmata.py

示例4: __init__

    def __init__(self, address, blink_rate, brightness):

        # create an instance of PyMata - we are using an Arduino UNO
        """

        @param address: I2C address of the device
        @param blink_rate: desired blink rate
        @param brightness: brightness level for the display
        """
        self.firmata = PyMata("/dev/ttyACM0")

        self.board_address = address
        self.blink_rate = blink_rate
        self.brightness = brightness
        self.clear_display_buffer()

        # configure firmata for i2c on an UNO
        self.firmata.i2c_config(0, self.firmata.ANALOG, 4, 5)

        # turn on oscillator
        self.oscillator_set(self.OSCILLATOR_ON)

        # set blink rate
        self.set_blink_rate(self.blink_rate)

        # set brightness
        self.set_brightness(self.brightness)
开发者ID:Haobot,项目名称:PyMata,代码行数:27,代码来源:bicolor_display_controller.py

示例5: __init__

    def __init__(self):
        # Initialize fingers and wrist pos
        self.t_pos = 0
        self.i_pos = 0
        self.m_pos = 0
        self.r_pos = 0
        self.l_pos = 0
        self.w_pos = 90

        # Initialize sensor values
        self.t_sen = 0
        self.i_sen = 0
        self.m_sen = 0
        self.r_sen = 0
        self.l_sen = 0

        # Initialize the arduino
        self.arduino = PyMata("/dev/ttyACM0", verbose=True)

        # Initialize the servos and sensors on arduino
        for pin in SERVO_PINS:
            self.arduino.servo_config(pin)
            sensor_pin = 0
            self.arduino.enable_analog_reporting(sensor_pin)
            sensor_pin += 1

        # Initialize the hand states
        self.curstate = 'open'
        self.states = {}
        self.transitionTable = {}
开发者ID:HtooWai,项目名称:RoboticHand,代码行数:30,代码来源:FSMFinger1.py

示例6: __init__

    def __init__(self,  name, broker, port, keepalive, state_topic, command_topic, qos, retain,
                 payload_on, payload_off, optimistic, value_template,serial_port,switch_pin):
        self._switch_pin = switch_pin
        self._board = PyMata(serial_port,False,verbose=True)
        self._board.set_pin_mode(self._switch_pin,self._board.OUTPUT,self._board.DIGITAL)

        A0 = 7
        def pin_callback(data):
            print("Analog Data: ",
                  " Pin: ", data[PIN_NUMBER],
                  " Pin Mode: ", data[PIN_MODE],
                  " Data Value: ", data[DATA_VALUE])
            self._board.set_analog_latch(A0,self._board.ANALOG_LATCH_GT,500,pin_callback)


        # self._board.set_pin_mode(A0, self._board.INPUT, self._board.ANALOG)
        # self._board.set_sampling_interval(100)
        # self._board.set_analog_latch(A0,self._board.ANALOG_LATCH_GT,500,pin_callback)

        # while True:
        #     time.sleep(0.1)
        #     value = self._board.analog_read(A0)
        #     print(value)

        self._mqtt = mqtt.Client()

        self._switch = None
        self._state_topic = state_topic
        self._command_topic = command_topic
        self._qos = qos
        self._retain = retain
        self._payload_on = payload_on
        self._payload_off = payload_off
        self._optimistic = optimistic
        self._state = False

        def on_message( _mqtt, userdata, msg):
            topic = msg.topic,
            qos = msg.qos,
            payload = msg.payload.decode('utf-8'),
            payload = payload[0]
            print(msg.topic+" "+payload)

            if payload == payload_on:
                self.turn_on()
            elif payload == payload_off:
                self.turn_off()

        self._mqtt.on_message = on_message
        self._mqtt.connect(broker, port, keepalive)
        self._mqtt.subscribe(command_topic,qos)
        self._mqtt.loop_forever()
开发者ID:zwb800,项目名称:home-assistant,代码行数:52,代码来源:mqtt_pymata.py

示例7: __init__

	def __init__(self, port = '/dev/ttyACM0'):

		#Warn experimenter that ports are going to switch on, before they are turned off again after initialization
		raw_input('WARNING: Switch off your instruments, all ports are going to turn on. Press ANY KEY to continue')
		self.board = PyMata(port)

		#Look at pymata.py and pymata_command_handler.py if you want to follow the logic. PyMata instances have a _command_handler 			instance in them - this _command_handler instance has two variables - total_pins_discovered and  				number_of_analog_pins_discovered. This sets digital pins 0 to (total_pins_discovered - number_of 			analog_pins_discovered - 1) to 0
		dio = self.board._command_handler.total_pins_discovered - self.board._command_handler.number_of_analog_pins_discovered

		for i in range(dio):
			self.board.digital_write(i, 0)
		
		print 'It is safe to turn your instruments on now. All digital ports have been switched off'
开发者ID:wachutka,项目名称:Blech_Lab,代码行数:13,代码来源:blech_board_pymata.py

示例8: search_port

 def search_port(self):
     #returns all serial COM-Ports
     possible_ports = serial_ports() 
     print 
     for com_port in possible_ports:
         logging.info('com port = %s' % com_port)
         try:
             # instantiate PyMata
             self.firmata = PyMata(com_port)  # pragma: no cover
             self.com_port = com_port
             return 1
         except Exception:
             print('Could not instantiate PyMata - is your Arduino plugged in?')
             logging.exception('Could not instantiate PyMata on Port %s' % com_port)
     return 0
开发者ID:mirko314,项目名称:s2a_fm,代码行数:15,代码来源:s2a_fm.py

示例9: __init__

 def __init__(self):
     Thread.__init__(self)
     self.daemon = True
     self.board = PyMata()
     def signal_handler(sig, frame):
         self.stop_motors()
         self.board.reset()
         sys.exit(0)
     signal.signal(signal.SIGINT, signal_handler)
     self.board.set_pin_mode(self.MOTOR_1_PWM, self.board.PWM,    self.board.DIGITAL)
     self.board.set_pin_mode(self.MOTOR_1_A,   self.board.OUTPUT, self.board.DIGITAL)
     self.board.set_pin_mode(self.MOTOR_1_B,   self.board.OUTPUT, self.board.DIGITAL)
     self.board.set_pin_mode(self.MOTOR_2_PWM, self.board.PWM,    self.board.DIGITAL)
     self.board.set_pin_mode(self.MOTOR_2_A,   self.board.OUTPUT, self.board.DIGITAL)
     self.board.set_pin_mode(self.MOTOR_2_B,   self.board.OUTPUT, self.board.DIGITAL)
     self.board.set_pin_mode(self.MOTOR_3_PWM, self.board.PWM,    self.board.DIGITAL)
     self.board.set_pin_mode(self.MOTOR_3_A,   self.board.OUTPUT, self.board.DIGITAL)
     self.board.set_pin_mode(self.MOTOR_3_B,   self.board.OUTPUT, self.board.DIGITAL)
     self.dx, self.dy = 0, 0
开发者ID:egaia,项目名称:python-pythonize-robots-STOPPED,代码行数:19,代码来源:robot.py

示例10: __init__

    def __init__(self, options):
        super(Firmata, self).__init__(options)

        if 'port' not in options:
            raise self.ParameterRequired(
                'A port must be specified for Firmata connection.'
            )

        self.port = options.get('port')
        self.board = PyMata('/dev/ttyACM0', verbose=True)

        signal.signal(signal.SIGINT, self.signal_handler)

        self.pins = {
            'digital': [],
            'analog': [],
            'pwm': [],
            'servo': [],
            'i2c': [],
        }
开发者ID:zorg,项目名称:zorg-firmata,代码行数:20,代码来源:adaptor.py

示例11: __init__

    def __init__(self):
        # Initialize fingers and wrist pos
        self.finger_pos = [0, 0, 0, 0, 0, 90]

        # Initialize sensor values
        self.sensor_val = [0, 0, 0, 0, 0]

        # Initialize the arduino
        self.arduino = PyMata("/dev/ttyACM0", verbose=True)

        # Initialize the servos and sensors on arduino
        for servo_pin in SERVO_PINS:
            self.arduino.servo_config(servo_pin)
        for sensor_pin in SENSOR_PINS:
            self.arduino.enable_analog_reporting(sensor_pin)

        # Initialize the hand states
        self.curstate = 'open'
        self.states = {}
        self.transitionTable = {}
开发者ID:HtooWai,项目名称:RoboticHand,代码行数:20,代码来源:FSMFinger2.py

示例12: __init__

    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)]
        )
开发者ID:elyezer,项目名称:pingo,代码行数:20,代码来源:arduino.py

示例13: __init__

    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']]
        )
开发者ID:scls19fr,项目名称:pingo-py,代码行数:24,代码来源:firmata.py

示例14: __init__

 def __init__(self, port):
     from PyMata.pymata import PyMata
     self._port = port
     self._board = PyMata(self._port, verbose=False)
开发者ID:FanaHOVA,项目名称:home-assistant,代码行数:4,代码来源:arduino.py

示例15: PyMata

This example illustrates using callbacks for digital and analog input.

Monitor the current analog input and digital input of two pins.
"""

import signal
import sys
import time


from PyMata.pymata import PyMata


# Instantiate PyMata
board = PyMata("/dev/ttyACM0", verbose=True)

board.encoder_config(7,2)

# Set up pin modes for both pins with callbacks for each
board.set_pin_mode(5, board.PWM, board.DIGITAL)
board.set_pin_mode(6, board.PWM, board.DIGITAL)

board.analog_write(5, 255)
board.analog_write(6, 0)

time.sleep(2)
count = board.digital_read(2)
print count
time.sleep(2)
board.analog_write(5, 0)
开发者ID:solishi,项目名称:woodbot,代码行数:30,代码来源:test_motor_drive_woodbot.py


注:本文中的PyMata.pymata.PyMata类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。