def Get_WPI_12(COM): Serial = pyfirmata.ArduinoMega(COM) for i in range(0, 9): print('.', end=" ") Pause_Time(.05) it = pyfirmata.util.Iterator(Serial) it.start() print('WPI Ready\n') return Serial
def __init__(self, robotName): board = pyfirmata.ArduinoMega('/dev/ttyACM0') self.name = robotName if (robotName == "Lovebird"): self.leftPower = board.get_pin("d:2:p") self.rightPower = board.get_pin("d:3:p") self.leftDir = board.get_pin("d:22:o") self.rightDir = board.get_pin("d:23:o") elif (robotName == "Tessle"): self.leftPower = board.get_pin("d:2:s") self.rightPower = board.get_pin("d:3:s")
def __init__(self, usingvision, usingpixhawk, usingsim): # setting up board serial port print("Communicating with Arduino...") # something so the serial buffer doesn't overflow self.board = pyfirmata.ArduinoMega( '/dev/serial/by-id/usb-Arduino__www.arduino.cc__0042_55839313438351417131-if00') self.iterator = pyfirmata.util.Iterator(self.board) self.iterator.start() print("Communication with Arduino started...") self.YawOffset = 0 self.PitchOffset = 0 self.RollOffset = 0 self.EastOffset = 0 self.NorthOffset = 0 self.DownOffset = 0 self.UsingVision = usingvision self.UsingPixHawk = usingpixhawk self.UsingSim = usingsim if self.UsingVision: import Theos_Really_Good_Detection_Script as obj_det self.VisionAI = obj_det.Detector("TensorFlow_Graph/Tflite", False) print("MovementCommander is using Vision AI...") else: print("MovementCommander is not using Vision AI...") if self.UsingPixHawk: from pixhawk_data import PixHawk self.PixHawk = PixHawk() print("MovementCommander is using PixHawk...") else: print("MovementCommander is not using PixHawk...") if self.UsingSim: from advancedtelemetry import Telemetry self.TelemetrySim = Telemetry() print("MovementCommander is using Telemetry...") else: print("MovementCommander is not using Telemetry...") # thruster hardpoint classes self.ThrusterLB = ThrusterDriver(2, self.board) # left back self.ThrusterLF = ThrusterDriver(4, self.board) # left front self.ThrusterRB = ThrusterDriver(3, self.board) # right back self.ThrusterRF = ThrusterDriver(5, self.board) # right front self.ThrusterBL = ThrusterDriver(6, self.board) # back left self.ThrusterBR = ThrusterDriver(7, self.board) # back right self.ThrusterFL = ThrusterDriver(8, self.board) # front left self.ThrusterFR = ThrusterDriver(9, self.board) # front right print("Wait 3 to arm thrusters...") time.sleep(3)
def getArduino(vid, pid): import pyfirmata import sys ArduinoPort = find_usb(vid, pid) if not ArduinoPort: print("Arduino non collegato--------------- Exit") sys.exit() else: print("Arduino collegato a ..... : ", ArduinoPort) board = pyfirmata.ArduinoMega(ArduinoPort) return board
def __init__(self): self.__init_constants() self.__init_globals() self.__init_map() ## init self.board = pyfirmata.ArduinoMega('/dev/ttyUSB0') self.__init_motor() self.__init_infrared() # refresh GPIO input it = pyfirmata.util.Iterator(self.board) it.start() sleep(0.1)
def __init__(self, portti, moottori_x, moottori_y, moottori_z): """ The constructor. The parameters: portti: the name of the USB-port. The name can be determined, for example, via the Device Manager or the Arduino IDE. The rest: the motor-objects that take care of moving the carriage on the x-, y-, and z-axes. Konstruktori. Parametreinä PC:ssä käytetty usb-portti ja x-, y- ja z-akseleilla kelkan liikuttelusta vastaavat moottorit. Portin nimi selviää esim. Device Managerin tai Arduino IDE:n kautta. """ self.portti = portti self.kortti = pyfirmata.ArduinoMega(portti) self.moottori_x = moottori_x self.moottori_y = moottori_y self.moottori_z = moottori_z self.viive = 2.6 * 1e-6 # pulse interval min. 2.5 µs self.viive_y = 4 * 1e-6 # y-moottori hyötyy hieman pitemmästä viiveestä # the y-motor benefits from a slightly longer delay self.iteraattori = pyfirmata.util.Iterator(self.kortti) self.iteraattori.start() self.kortti.digital[ self.moottori_x.rajakytkin_0 ].mode = pyfirmata.INPUT self.kortti.digital[ self.moottori_x.rajakytkin_1 ].mode = pyfirmata.INPUT self.kortti.digital[ self.moottori_y.rajakytkin_0 ].mode = pyfirmata.INPUT self.kortti.digital[ self.moottori_y.rajakytkin_1 ].mode = pyfirmata.INPUT self.kortti.digital[ self.moottori_z.rajakytkin_0 ].mode = pyfirmata.INPUT self.kortti.digital[ self.moottori_z.rajakytkin_1 ].mode = pyfirmata.INPUT
def arduino(lists): try: board = pyfirmata.ArduinoMega('COM3') except: pass for item in lists: if item.startswith("o"): pin_number = str(''.join(filter(str.isdigit,item))) #pin_on = 0 try: board.digital[Python_to_arduino.get(pin_number)].write(1) except: pass print('high', Python_to_arduino.get(pin_number)) if item.startswith("w"): waiting = int(''.join(filter(str.isdigit,item))) try: time.sleep(waiting/1000) except: pass print('wait', waiting) if item.startswith("c"): pin_number2 = str(''.join(filter(str.isdigit,item))) #pin_off = 0 try: board.digital[Python_to_arduino.get(pin_number2)].write(0) except: pass print('low', Python_to_arduino.get(pin_number2)) try: board.exit() except: pass
AngleDegy = 0 AngleDegz = 0 # Camera picam camera = PiCamera() camera.resolution = (640, 480) camera.framerate = 32 rawCapture = PiRGBArray(camera, size=(640, 480)) fourcc = cv2.cv.CV_FOURCC(*'XVID') # cv.videowriter times = datetime.datetime.now() videoOut = cv2.VideoWriter("UUV" + str(times) + ".avi", fourcc, 20.0, (640, 480)) # Videowriter # allow the camera to warmup time.sleep(0.1) try: hardware = pyfirmata.ArduinoMega("/dev/ttyUSB0") except: print("connecting the backup protocol") try: hardware = pyfirmata.ArduinoMega("/dev/ttyUSB1") except: print("All hardware not connected") XLservo = hardware.get_pin('d:8:s') XRservo = hardware.get_pin('d:9:s') YUservo = hardware.get_pin('d:10:s') YBservo = hardware.get_pin('d:11:s') def read_byte(reg): return bus.read_byte_data(address, reg)
import pyfirmata import time #defining mail variables port = 465 #for ssl smtp_server = 'smtp.gmail.com' sender_email = '*****@*****.**' #enter your email address to send alert from password = '******' #enter password of sender email account receiver_email = '*****@*****.**' #enter email address to receive alert alert_message = '''\ Subject: Alert! Motion sensor tripped!''' #defining pyfirmata variables board = pyfirmata.ArduinoMega('COM4') pir_output = board.get_pin('d:7:i') it = pyfirmata.util.Iterator(board) #user-defined functions def send_email(): print ('Motion Detected! Sending Email') context = ssl.create_default_context() #create secure ssl connection with smtplib.SMTP_SSL(smtp_server, port, context=context) as server: #using 'with smtplib.SMTP_SSL() as server: makes sure that the connection is automatically colsed at the end of the indented code block. server.login(sender_email, password) server.sendmail(sender_email, receiver_email, alert_message) def buzzLED_pulse(): board.digital[13].write(1) board.digital[12].write(1) time.sleep(0.2) #change to increase/decrease on state
file = open("RoboticsScrypt.csv","a+") # Add the full processing constance processing scrypt def Knobcontrol(self): print("Dial value = %i" % (self.dial.value())) blink.write(self.dial.value()/10) # Hardware linking control brigtness of the LED test def AnalogRead(self): for _ in itertools.count(): AnalogReadA1 = hardware.analog[0].read() self.progressBar_2.setValue(AnalogReadA1*500) print(AnalogReadA1) if __name__ == "__main__": import sys import os try: hardware = pyfirmata.ArduinoMega('/dev/ttyACM0') print("Hardware robotics assembly line connected successfully !") except: print("Hardware connection fail please reconnect and check connection port !") it = pyfirmata.util.Iterator(hardware) it.start() blink = hardware.get_pin('d:13:p') hardware.analog[0].enable_reporting() #AnalogReadA1 = hardware.analog[0].read() blink.write(0) time.sleep(0.1) for i in range(0,10): blink.write(i) time.sleep(0.2) time.sleep(0.1) for i in range(0,10,-1):
import pyfirmata import pygame import time from pygame.locals import * pygame.init() # controller setup joysticks = [] for i in range(pygame.joystick.get_count()): joysticks.append(pygame.joystick.Joystick(i)) joysticks[-1].init() controller = joysticks[0] # The port changes from linux to windows, with windows having multiple COM ports board = pyfirmata.ArduinoMega('COM3') # this is (one of) windows ports #board = pyfirmata.ArduinoMega('/dev/ttyACM0') # this is linux port # setting pins onboard_led = board.get_pin('d:13:o') l_motor_pin = board.get_pin('d:11:p') r_motor_pin = board.get_pin('d:12:p') motor_toggle_pin = board.get_pin('d:24:o') while (1): pygame.event.pump() # puts rover in "stop" state if no input, avoids rover from "running away" motor_toggle_pin.write(0) l_motor_pin.write(.49804) r_motor_pin.write(.49804)
import time import pyfirmata import os import threading from ardupin import * from configku import * board = pyfirmata.ArduinoMega(ARDUINO_COM_PORT) #board = pyfirmata.Arduino('COM3') it = pyfirmata.util.Iterator(board) it.start() #RELAY/PENENDANG PENENDANG = board.get_pin(PENENDANG_PIN) MODE_PENENDANG = board.get_pin(MODE_PENENDANG_PIN) #INFRARED IR_KIRI = board.get_pin(IR_PIN_KIRI) IR_KIRI2 = board.get_pin(IR_PIN_KIRI2) IR_TENGAH = board.get_pin(IR_PIN_TENGAH) IR_KANAN = board.get_pin(IR_PIN_KANAN) IR_KANAN2 = board.get_pin(IR_PIN_KANAN2) #MOTOR RPWM_DRIBLE = board.get_pin(RPWM_DRIBLE_PIN) LPWM_DRIBLE = board.get_pin(LPWM_DRIBLE_PIN) EON1_DRIBLE = board.get_pin(EON1_DRIBLE_PIN) EON2_DRIBLE = board.get_pin(EON2_DRIBLE_PIN) RPWM_KANAN = board.get_pin(RPWM_KANAN_PIN) LPWM_KANAN = board.get_pin(LPWM_KANAN_PIN) EON1_KANAN = board.get_pin(EON1_KANAN_PIN) EON2_KANAN = board.get_pin(EON2_KANAN_PIN)
dog_cascade = cv2.CascadeClassifier('/usr/share/opencv/opencv/data/Dogcascade-/cascade.xml') time.sleep(1) r = 0 # 3D space angle convert function radians to degrees angleDegX = 0 angleDegY = 0 angleDegZ = 0 c = 0 # Gyro scope address #Register power_mgmt_1 = 0x6b power_mgmt_2 = 0x6c #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #Hardware connection part try: hardware = pyfirmata.ArduinoMega('/dev/ttyACM0') # Hardware try connection except: print("Hardware STM32 not found !") print("Prepare for seccond protocol ....") try: connection = SerialManager() # Firmware update hardware serial finder catbot = ArduinoApi(connection=connection) except: print("All hardware fail connection") # GPS try: gps = serial.Serial("/dev/ttyS0",115200) #GPS connection except: print("GPS device notfound !") x = str(gps.read(1200))
# 需要Arduino先烧入StandFirmata # 请修改串口编号为实际Arduino串口编号 # 设置舵机的高点和低点 单位:角度 # 范围 0-180° servo_high = 45 servo_low = 37 # 修改串口编号 如果Arduino驱动正确,在Arduino IDE可以看到串口编号 serial_int = 'COM3' # 如果是Arduino UNO 使用这一条 # board = pyfirmata.Arduino(serial_int) # 如果是Arduino Mega 使用这一条 pyfirmata库暂不支持Nano board = pyfirmata.ArduinoMega(serial_int) servo_pin = board.get_pin('d:3:s') # 使用3号输出口 可以自行调整 iter8 = pyfirmata.util.Iterator(board) iter8.start() servo_pin.write(servo_high) # 舵机控制函数 def arduino_servo_run(t): servo_pin.write(servo_low) time.sleep(t + 0.05) servo_pin.write(servo_high)
def getThread(self): existingThreads = self.GUI.threadList return existingThreads def checkIfAlive(self): fram = self.GUI.frame try: val = fram.winfo_exists() except: val = False return val """setting up which usb port is the arduino connected to""" board = pyfirmata.ArduinoMega('COM3') # might want to change this based on your pc """Initialize communication with the arduino board""" it = pyfirmata.util.Iterator(board) it.start() time.sleep(0.01) """Initialize the player""" player = AdditiveStream() """Arrays for storing some initial data""" notes = [65.41, 73.42, 82.41, 92.50, 103.83, 116.54] pins = ['a:0:i', 'a:1:i', 'a:2:i', 'a:3:i', 'a:4:i', 'a:5:i'] # array of pins leds = [2, 3, 4, 5, 6, 7] piezoThreads = [] samplerate = 44100
GPIO.setup(feed3, GPIO.OUT) GPIO.setup(feed4, GPIO.OUT) GPIO.setup(feed5, GPIO.OUT) GPIO.setup(feed6, GPIO.OUT) #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> # Reset pin function for the relay control GPIO.setup(r1, GPIO.OUT) GPIO.setup(r2, GPIO.OUT) GPIO.setup(r3, GPIO.OUT) GPIO.setup(r4, GPIO.OUT) GPIO.setup(r5, GPIO.OUT) GPIO.setup(r6, GPIO.OUT) # Handleling the first hardware connection support try: hardware = pyfirmata.ArduinoMega( "/dev/ttyUSB0") #USB serial connection hardware print("Successfully connect hardware 1") # Initial setting logic low FanT1 = hardware.get_pin('d:2:p') p1 = hardware.get_pin('d:3:p') p2 = hardware.get_pin('d:4:p') p3 = hardware.get_pin('d:9:p') p4 = 5 p5 = 6 GPIO.setup(p4, GPIO.OUT) # Setting the GPIO pin 5 out GPIO.setup(p5, GPIO.OUT) # Setting the GPIO pins 6 out p6 = hardware.get_pin('d:12:p') FanT1.write(0) p1.write(0) p2.write(0) p3.write(0)
# for UI: import PySimpleGUI as sg # for working with Arduino: import pyfirmata as pf # any preferred appearance of the UI: theme = 'DarkBlack1' # set the theme: sg.theme(theme); del theme # Boolean to check connection connected = False # Variable to keep board's type and dictionaries for ports board_type = " " digital_ports = pwm_ports_values = pwm_ports = dict() gitoverflow = [ [sg.T("Github: Muhammadrasul446", size=(28, 1))], [sg.T("Stackoverflow: user:13490404", size=(28, 1))] ] twittedin = [ [sg.T("Twitter: A_M_R_4_4_6", size=(28, 1))], [sg.T("Linkedin: 6644821a9", size=(28, 1))] ] # Window layout for selecting boards select_win_lay = [ [sg.T('Select your board:')], [sg.Button("Nano/Uno/Leonardo")], [sg.Button("Mega/Mega2560")] ] window = sg.Window("Select your board", select_win_lay) # keep the window open:
import pyfirmata import time import numpy as np import math from multiprocessing import Process import itertools try: hardware = pyfirmata.ArduinoMega("/dev/ttyACM0") print("Catbot main body hardware connection successfully connected !") except: print("Hardware connection error resouting the serial communication...") try: hardware = pyfirmata.ArduinoMega("/dev/ttyACM1") print("Main body hardware serial rerouting connection successfully!") except: print("Main serial error please check the physical hardware!") # USB try: hardware2 = pyfirmata.Arduino("/dev/ttyUSB0") print("Catbot seccond body hardware connection successfully connected !") except: print( "Hardware seccond connection error resouting the serial communication..." ) try: hardware2 = pyfirmata.Arduino("/dev/ttyUSB0") print("Main body hardware serial rerouting connection successfully!") except: print("Seccond serial error please check the physical hardware!") #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# # Copyright © 2015 cameron <cameron@Megatron-Dev> # # Distributed under terms of the MIT license. """ This is the second script for building the face tracker. """ import cv2 import pyfirmata import time face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') port = "/dev/ttyACM0" board = pyfirmata.ArduinoMega(port) board.digital[11].mode = pyfirmata.SERVO # Pan Servo board.digital[10].mode = pyfirmata.SERVO # Tilt Servo board.digital[11].write(90) board.digital[10].write(90) pan_increment = 0 tilt_increment = 0 video_capture = cv2.VideoCapture(0) while True: ret, frame = video_capture.read() gray_image = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.1,
lower = { 'green': (66, 122, 129), 'blue': (97, 100, 117), 'yellow': (23, 59, 119) } #assign new item lower['blue'] = (93, 10, 0) upper = { 'green': (86, 255, 255), 'blue': (117, 255, 255), 'yellow': (54, 255, 255) } # define standard colors for circle around the object colors = {'green': (0, 255, 0), 'blue': (255, 0, 0), 'yellow': (0, 255, 217)} AngleCam = 0 #pts = deque(maxlen=args["buffer"]) hardware = pyfirmata.ArduinoMega("/dev/ttyACM0") # hardware connection base = hardware.get_pin('d:5:s') shoulder = hardware.get_pin('d:6:s') elbow = hardware.get_pin('d:7:s') wrist = hardware.get_pin('d:4:s') wristrotate = hardware.get_pin('d:8:s') gripper = hardware.get_pin('d:9:s') # if a video path was not supplied, grab the reference # to the webcam #cv2.namedWindow("Window") camera = cv2.VideoCapture(0) # otherwise, grab a reference to the video file # keep looping
import pyfirmata import time uno = pyfirmata.Arduino('/dev/ttyUSB_UNO') mega = pyfirmata.ArduinoMega('/dev/ttyUSB_MEGA') servo = dict() servo[1] = uno.get_pin('d:5:s') servo[2] = uno.get_pin('d:6:s') servo[3] = mega.get_pin('d:8:s') servo[4] = mega.get_pin('d:9:s') n = 2 servo[n].write(70) time.sleep(0.5) servo[n].write(80) time.sleep(0.5) servo[n].write(90) time.sleep(0.5) servo[n].write(80) time.sleep(0.5) servo[n].write(70) time.sleep(0.5) #servo[n].write(95) #time.sleep(0.5) # time.sleep(0.5) # servo[n].write(90) # time.sleep(0.5) # servo[n].write(45)
from modules.getStatus import getInfo from modules.gear import gearUp from modules.gear import gearDown #IMPORTA IP DE TRABAJO PARA INICIAR PRUEBAS DE CONEXIÓN jsondata = open('/var/www/html/sys/settings.json', 'r') ipdata = json.load(jsondata) xhost = ipdata[0]["ip"] #VARIABLES GENERALES DE SISTEMA #init = ftest(xhost) #PRUEBA GENERAL DE CONEXIÓN CON XPLANE #ESCANEO DE PUERTOS ABIERTOS b0 = pyfirmata.ArduinoMega('/dev/ttyACM0') #Linux #b0 = pyfirmata.ArduinoMega('/dev/ttyS0') #Linux en VM #b0 = pyfirmata.ArduinoMega('COM3') #WINDOWS it = pyfirmata.util.Iterator(b0) it.start() #Se inician los puertos del starter module xpout = list(range(2, 12)) xpin = list(range(15, 49)) refout = getOutput() refin = getInput() for pt in xpout: b0.digital[pt].mode = pyfirmata.OUTPUT
except Exception as e: printMsg(e) finally: pass try: raspberryPi = socket.socket(socket.AF_INET, socket.SOCK_STREAM) raspberryPi.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) raspberryPi.bind((PI_IP,PI_PORT)) raspberryPi.listen(2) except Exception as e: printMsg(e) else: printMsg("connection opend") while 1: try: arduino = pyfirmata.ArduinoMega(PORT) except Exception as e: printMsg(e) break; else: printMsg("arduino connected") printMsg("8888") printMsg("waiting for gui client") printMsg("pwm : 4, derectionPin : 3, torquePin : 2") while 1: try: guiClient, guiClientAddress = raspberryPi.accept() printMsg(guiClientAddress) except Exception as e: printMsg(e) else:
Gregory Ferguson """ import socket import threading import pyfirmata import time import struct # raspberry pi's static ip HOST = '192.168.4.1' FORWARD = 'ABS_RZ' BACKWARD = 'ABS_Z' # setting up the board board = pyfirmata.ArduinoMega('/dev/ttyACM0') l_motor_pin = board.get_pin('d:11:p') r_motor_pin = board.get_pin('d:12:p') motor_toggle_pin = board.get_pin('d:24:o') def Serial_Send(data, ser): #Once you have the data in bytes, send to embedded system. encoded_data = [] for i in range(0, len(data)): length = len(data[i]) data[i] = data[i].encode('utf-8') encoded_data.append(struct.pack(str(length) + 's', data[i])) print(encoded_data)