def __init__(self):

            self.volts = float(5)

            self.result_voltage = 'nan'

            self.output = 'nan'

            self.output0 = 'nan'

            self.output1 = 'nan'

            self.port_a0 = 'nan'

            self.port_a1 = 'nan'

            self.message = "DAQ status update"

            self.board = Arduino('/dev/ttyUSB0')

            self.board.digital[13].write(1)

            self.it = util.Iterator(self.board)

            self.it.start()

            self.analog_0 = self.board.get_pin('a:0:i')
            self.analog_1 = self.board.get_pin('a:1:i')
            print("Stable Serial port timer")
            sleep(4)
Ejemplo n.º 2
0
    def setup_pins(self):
        # Given an arduino connected to firmata, create
        # variables to reference the different pins
        self.arduino_inputs = {
            k: self.arduino.analog[p]
            for k, p in self.arduino_config["sensors_pins"].items()
        }
        for pin in self.arduino_inputs.values():
            pin.enable_reporting()

        # Get pins for door open and door close [as analog outputs]
        self.speaker_commad_pin = self.arduino.get_pin('d:{}:o'.format(
            self.arduino_config['tone_pin']))
        self.door_open_pin = self.arduino.get_pin('d:{}:o'.format(
            self.arduino_config['door_open_pin']))

        self.door_status_pin = self.arduino.analog[
            self.arduino_config['door_status_pin']]
        # self.door_status_pin = self.arduino.get_pin('d:{}:o'.format(self.arduino_config['door_status_pin']))
        # self.door_status_pin.mode = INPUT
        self.door_status_pin.enable_reporting()

        # start board iteration
        it = util.Iterator(self.arduino)
        it.start()
 def open_serial(self):
     self.message = "Testing running now..."
     self.board = Arduino('/dev/ttyUSB0')
     self.board.digital[13].write(1)
     self.it = util.Iterator(self.board)
     self.it.start()
     print("Measure will start")
     sleep(3)
     self.analog_0 = self.board.get_pin('a:0:i')
     self.analog_1 = self.board.get_pin('a:1:i')
     sleep(2)
     # self.result()
     # self.result_a1()
     return "Serial open successful"
Ejemplo n.º 4
0
    def init_arduino(self):
        try:
            self.board = Arduino(Arduino.AUTODETECT)
        except:
            # pop-up window
            msg = QMessageBox()
            msg.setWindowTitle("arduino control")
            msg.setIcon(QMessageBox.Critical)
            msg.setText("problem to find the device")
            x = msg.exec_()

        self.iterator = util.Iterator(self.board)
        self.iterator.start()
        self.leftMagnet = self.board.get_pin('d:11:p')  # digital ('d:13:o')
        self.rightMagnet = self.board.get_pin('d:10:p')  # digital ('d:12:o')
Ejemplo n.º 5
0
    def _get_board(self,
                   board: Optional[str] = None,
                   board_type: Optional[str] = None,
                   baud_rate: Optional[int] = None,
                   timeout: Optional[float] = None):
        board_name = board or self.board or Arduino.AUTODETECT
        baud_rate = baud_rate or self.baud_rate
        timeout = timeout or self.timeout

        if board_name in self._boards:
            return self._boards[board_name]

        board_type = self._get_board_type(
            board_type) if board_type else self.board_type
        board = board_type(board_name, baudrate=baud_rate, timeout=timeout)
        self.logger.info('Connected to board {}'.format(board.name))
        self._boards[board_name] = board

        self._board_iterators[board.name] = util.Iterator(board)
        self._board_iterators[board.name].start()
        return board
Ejemplo n.º 6
0
# Import required libraries
from pyfirmata2 import Arduino, util
from time import sleep


# Define custom function to perform Blink action
def blinkLED(pin, message):
    print(message)
    board.digital[pin].write(1)
    sleep(1)
    board.digital[pin].write(0)
    sleep(1)


# Associate port and board with pyFirmata
#port = '/dev/ttyACM0'
port = '/dev/ttyS3'
#board = Arduino(Arduino.AUTODETECT)
board = Arduino(port)
# Use iterator thread to avoid buffer overflow
it = util.Iterator(board)
it.start()

# Define pins
redPin = 13
while True:
    board.digital[13].write(1)
    blinkLED(redPin, "message to the world")
    board.digital[13].write(0)