def test_layout_arduino_mega(self): pyfirmata.pyfirmata.serial.Serial = mockup.MockupSerial mega = pyfirmata.Board('', BOARDS['arduino_mega']) self.assertEqual(len(BOARDS['arduino_mega']['digital']), len(mega.digital)) self.assertEqual(len(BOARDS['arduino_mega']['analog']), len(mega.analog))
def get_the_board( layout=BOARDS['arduino'], base_dir='/dev/', identifier='tty.usbserial', ): """ Helper function to get the one and only board connected to the computer running this. It assumes a normal arduino layout, but this can be overriden by passing a different layout dict as the ``layout`` parameter. ``base_dir`` and ``identifier`` are overridable as well. It will raise an IOError if it can't find a board, on a serial, or if it finds more than one. """ boards = [] for device in os.listdir(base_dir): if device.startswith(identifier): try: board = pyfirmata.Board(os.path.join(base_dir, device), layout) except serial.SerialException: pass else: boards.append(board) if len(boards) == 0: raise IOError, "No boards found in %s with identifier %s" % ( base_dir, identifier) elif len(boards) > 1: raise IOError, "More than one board found!" return boards[0]
def setUp(self): # Test with the MockupSerial so no real connection is needed pyfirmata.pyfirmata.serial.Serial = mockup.MockupSerial # Set the wait time to a zero so we won't have to wait a couple of secs # each test pyfirmata.pyfirmata.BOARD_SETUP_WAIT_TIME = 0 self.board = pyfirmata.Board('', BOARDS['arduino']) self.board._stored_data = []
def setUp(self): system = platform.system() if system == 'Linux': # Rough estimation about where the device is. May fail. device = '/dev/ttyUSB0' self.board = pyfirmata.Board(device) # No Layout else: raise RuntimeError('System not supported.')
def test_layout_arduino_mega(self): pyfirmata.pyfirmata.serial.Serial = mockup.MockupSerial mockup.MockupSerial.preparedResponses = [] mockup.MockupSerial.preparedResponses.append(([ pyfirmata.START_SYSEX, pyfirmata.PIN_STATE_QUERY, None, pyfirmata.END_SYSEX ], self.respond_to_pin_state_query)) self.board = None self.board = pyfirmata.Board('', BOARDS['arduino_mega']) self.assertEqual(len(BOARDS['arduino_mega']['digital']), len(self.board.digital)) self.assertEqual(len(BOARDS['arduino_mega']['analog_real']), len(self.board.analog))
def setUp(self): # Test with the MockupSerial so no real connection is needed pyfirmata.pyfirmata.serial.Serial = mockup.MockupSerial mockup.MockupSerial.preparedResponses = [] mockup.MockupSerial.preparedResponses.append(([ pyfirmata.START_SYSEX, pyfirmata.PIN_STATE_QUERY, None, pyfirmata.END_SYSEX ], self.respond_to_pin_state_query)) # Set the wait time to a zero so we won't have to wait a couple of secs # each test pyfirmata.pyfirmata.BOARD_SETUP_WAIT_TIME = 0 self.board = pyfirmata.Board('', BOARDS['arduino']) self.board._stored_data = [] self.board.sp.clear()
def __init__(self, port): self._target = pyfirmata.Board(port, brainwave_layout) # Iterator keeps analog reads from overflowing the serial port buffer self._it = pyfirmata.util.Iterator(self._target) self._it.start() self._bed_heat = self._target.get_pin("d:%s:o" % BW_PIN_B_HEAT) self._ext_heat = self._target.get_pin("d:%s:o" % BW_PIN_E_HEAT) self._fan = self._target.get_pin("d:%s:o" % BW_PIN_FAN) # Make sure things start off right (i.e. off) self.assertBedHeat(False) self.assertExtruderHeat(False) self.assertFan(False) self.setupAxis(BW_X_AXIS) self.setupAxis(BW_Y_AXIS) self.setupAxis(BW_Z_AXIS) self.setupAxis(BW_E_AXIS) self._b_temp = self._target.get_pin("a:%s:i" % BW_PIN_B_TEMP) self._e_temp = self._target.get_pin("a:%s:i" % BW_PIN_E_TEMP)
def setup(self): self.logger.debug("Initializing Arduino subsystem") # Initialize configured self.boards try: if not os.access(self.device, os.R_OK): raise self.FileNotReadableError board = pyfirmata.Board(self.device, layout=pyfirmata.BOARDS[self.device_type]) self._board = board self.is_mocked = False except (self.FileNotReadableError, OSError) as e: if isinstance( e, self.FileNotReadableError) or e.errno == os.errno.ENOENT: self.logger.warning( 'Your arduino device %s is not available. Arduino will be mocked.', self.device) self._board = None self.is_mocked = True else: raise self._lock = Lock() if self._board: self._board.add_cmd_handler(pyfirmata.STRING_DATA, self._string_data_handler) self._iterator_thread = it = threading.Thread( target=threaded(self.system, iterate_serial, self._board)) it.daemon = True it.name = "PyFirmata thread for {dev}".format(dev=self.device) it.start() self.reset() self.configure_sample_rate() self.configure_instant_digital_reporting() self.configure_virtualwire() self.configure_lcd() self.configure_analog_reference() self._keep_alive()
def setUp(self): # Test with the MockupSerial so no real connection is needed pyfirmata.pyfirmata.serial.Serial = mockup.MockupSerial self.board = pyfirmata.Board('', BOARDS['arduino']) self.board._stored_data = [] # FIXME How can it be that a fresh instance sometimes still contains data?
del digital[18] digital = tuple(digital) analog = tuple(range(5)) schema = { # Use all analog pins: A0-A5(14-19). if do not use all change the number 20 'digital': digital, # Analog pins has been used as digital ones 'analog': analog, 'pwm': (3, 5, 6, 9, 10, 11), 'use_ports': True, 'disabled': (0, 1) # Rx, Tx, Crystal } # don't forget to change the serial port to suit # board = pyfirmata.Arduino('/dev/ttyACM2') board = pyfirmata.Board("/dev/ttyACM1", layout=schema) # start an iterator thread so # serial buffer doesn't overflow iter8 = pyfirmata.util.Iterator(board) iter8.start() # set up pin D3 as Servo Output # pin9 = board.get_pin('d:3:s') analog3 = board.get_pin('d:14:o') Echo = 4 Trig = analog_pin_to_digital(5) - 1 # Trig = 13 board.analog[Echo].mode = pyfirmata.INPUT # A4 board.digital[Trig].mode = pyfirmata.OUTPUT # A5 try: print(Distance_test())
for i in range(0, 10): port = '/dev/ttyACM' + str(i) if removeport1 != port and removeport2 != port: ports.append(port) # Ports /dev/ttyACM0 -> /dev/ttyACM10 else: print "Ignoring " + str( port) + " because it is assigned to door control system." arduinos = 2 boards = [] for port in ports: #if port == '/dev/ttyACM2': continue try: print "Trying port", port b = pyfirmata.Board(port, pyfirmata.boards.BOARDS['arduino']) print "Success connecting to", port boards.append(b) print "Found an arduino %s" % len(boards) if len(boards) >= arduinos: break except Exception, e: print "Failure to connect to", port, e while (len(boards) < arduinos): class pin():