Esempio n. 1
0
 def connect(self):
     self.connection = nanpy.SerialManager(device=self.DEVICE)
     self.arduino = nanpy.ArduinoApi(connection=self.connection)
     a = self.arduino
     a.pinMode(self.PIN_LED, a.OUTPUT)
     a.pinMode(self.PIN_SWITCH, a.INPUT)
     self.connected = True
Esempio n. 2
0
    def __init__(self):
        """
		initialize pins as motor outputs
		"""

        self.DB1 = rospy.get_param('DB1')  # Driver Board #1 INH
        self.M1 = rospy.get_param('M1')  # DB #1 IN1 & IN2
        self.M2 = rospy.get_param('M2')  # DB #1 IN3 & IN4
        self.DB2 = rospy.get_param('DB2')  # DB #2 INH
        self.M3 = rospy.get_param('M3')  # DB #2 IN1 & IN2
        self.M4 = rospy.get_param('M4')  # DB #2 IN3 & IN4

        self.turbo = False  # turbo mode
        self.arch = os.environ['ARCHITECTURE']

        if self.arch == 'raspi':
            GPIO.setmode(GPIO.BOARD)  # use RasPi pin numbers
            GPIO.setwarnings(False)  # don't show setup warnings
            # set pins as outputs and initialize to False/Low
            GPIO.setup(self.DB1, GPIO.OUT, initial=False)
            GPIO.setup(self.M1, GPIO.OUT, initial=False)
            GPIO.setup(self.M2, GPIO.OUT, initial=False)
            GPIO.setup(self.DB2, GPIO.OUT, initial=False)
            GPIO.setup(self.M3, GPIO.OUT, initial=False)
            GPIO.setup(self.M4, GPIO.OUT, initial=False)

            # setup all pwm outputs
            self.frequency = 500.0  # pwm frequency
            self.PWM_M1 = GPIO.PWM(self.M1, self.frequency)
            self.PWM_M1.start(0.0)
            self.PWM_M2 = GPIO.PWM(self.M2, self.frequency)
            self.PWM_M2.start(0.0)
            self.PWM_M3 = GPIO.PWM(self.M3, self.frequency)
            self.PWM_M3.start(0.0)
            self.PWM_M4 = GPIO.PWM(self.M4, self.frequency)
            self.PWM_M4.start(0.0)

        else:
            no_connection = True
            while no_connection:
                try:
                    connection = nanpy.SerialManager()
                    self.a = nanpy.ArduinoApi(connection=connection)
                    no_connection = False
                except:
                    print("Failed to connect to Arduino")
            self.a.pinMode(self.DB1, self.a.OUTPUT)
            self.a.pinMode(self.M1, self.a.OUTPUT)
            self.a.pinMode(self.M2, self.a.OUTPUT)
            self.a.pinMode(self.DB2, self.a.OUTPUT)
            self.a.pinMode(self.M3, self.a.OUTPUT)
            self.a.pinMode(self.M4, self.a.OUTPUT)
Esempio n. 3
0
def find_arduino():
    import glob

    # Find /dev/cu.usbmodem* using the glob module:
    ports = glob.glob('/dev/cu.usbmodem*')
    if len(ports) == 1:
        import nanpy
        return nanpy.ArduinoApi(connection=nanpy.SerialManager(device=ports[0]))

    if len(ports) == 0:
        rumps.notification(title='On Air',
                           subtitle='Error detecting Arduino',
                           message='No Arduino device detected (plugged in?)')
    else:
        rumps.notification(title='On Air',
                           subtitle='Error detecting Arduino',
                           message='Multiple devices detected')
Esempio n. 4
0
import nanpy
import time

print("CONNECT")
# Initialise connection
# connection = nanpy.SerialManager(device="/dev/ttyUSB0")
connection = nanpy.SerialManager(device="/dev/ttyUSB0")
arduino = nanpy.ArduinoApi(connection=connection)

# Define pin's
D0 = 0  # D0/RX - PD0
D1 = 1  # D1/TX - PD1
D2 = 2  # D2 - PD2
D3 = 3  # D3 - PD3
D4 = 4  # D4 - PD4
D5 = 5  # D5 - PD5
D6 = 6  # D6 - PD6
D7 = 7  # D7 - PD7

D8 = 8  # D8 - PB0
D9 = 9  # D9 - PB1
D10 = 10  # D10 - PB2
D11 = 11  # D11 - PB3
D12 = 12  # D12 - PB4
D13 = 13  # D13 - PB5

A0 = 14  # D14 - A0 - PC0 - ADC[0]
A1 = 15  # D15 - A1 - PC1 - ADC[1]
A2 = 16  # D16 - A2 - PC2 - ADC[2]
A3 = 17  # D17 - A3 - PC3 - ADC[3]
A4 = 18  # D18 - A4 - PC4 - ADC[4] - SDA