Пример #1
0
def CriaPinos(mini = 2, maxi = 9,tipo = 'p', minis = 10, maxis = 12, tipos = 's'):      #TIPO: O:OUTPUT | I:INPUT | P:PWM
    
    arduino = ArduinoMega('COM13')
    
    for p in range(mini,maxi):
        AP["pino" + str(p)] = arduino.get_pin('d:{}:{}'.format(p,tipo))
    for s in range(minis,maxis):
        AS["pino" + str(s)] = arduino.get_pin('d:{}:{}'.format(s,tipos))
Пример #2
0
import RPi.GPIO as GPIO
from pyfirmata import Arduino, ArduinoMega, util
import time

GPIO.setmode(GPIO.BCM)

#def arduino board for onboard comms
board = ArduinoMega('/dev/ttyACM0')

#in1-4 are for the arduino to interface with motor controller
#these determine direction of current
in1pin = board.get_pin('d:22:o')
in2pin = board.get_pin('d:24:o')
in3pin = board.get_pin('d:26:o')
in4pin = board.get_pin('d:28:o')

#for arduino again, this is PWM to attain speed control
enablePin1 = board.get_pin('d:6:p')
enablePin2 = board.get_pin('d:7:p')

#determines encoder pins
input_A = 17
input_B = 22

input_C = 18
input_D = 23

GPIO.setup(input_A, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(input_B, GPIO.IN, pull_up_down=GPIO.PUD_UP)

GPIO.setup(input_C, GPIO.IN, pull_up_down=GPIO.PUD_UP)
Пример #3
0
# vim:fenc=utf-8
#
# Copyright © 2015 cameron <cameron@Megatron-Virtual>
#
# Distributed under terms of the MIT license.

"""
This is a second attempt to reading analog
"""

from pyfirmata import ArduinoMega, util
import time
import os

port = '/dev/ttyACM0'
board = ArduinoMega(port)
time.sleep(5)
it = util.Iterator(board)
it.start()
sensor = board.get_pin('a:0:i')

try:
    while True:
        value = sensor.read()
        print value
        print(type(value))
        time.sleep(1)
except KeyboardInterrupt:
    board.exit()
    os._exit()
Пример #4
0
def CriaPinos(mini = 2, maxi = 13,tipo = 'p'):      #TIPO: O:OUTPUT | I:INPUT | P:PWM
    
    arduino = ArduinoMega('COM3')
    for i in range(mini,maxi):
        AP["pino" + str(i)] = arduino.get_pin('d:{}:{}'.format(i,tipo))
Пример #5
0
useArduino = True

# Try to connect to the arduino board. If it fails, then we will use the keyboard.
# TODO: create something that finds which port the arduino is connected to...
try:
    arduino = ArduinoMega(ArduinoMegaPort)
    # arduino = ArduinoMega('/dev/ttyACM1')
    # arduino = ArduinoMega('/dev/ttyACM0')
    # arduino = ArduinoMega('COM7')
    time.sleep(0.2)
    iterator = util.Iterator(arduino)
    iterator.start()
    time.sleep(0.2)

    # Define all input pins
    PIN_ONE = arduino.get_pin("d:37:i")
    PIN_TWO = arduino.get_pin("d:36:i")
    PIN_THREE = arduino.get_pin("d:35:i")
    PIN_LEFT = arduino.get_pin("d:32:i")
    PIN_RIGHT = arduino.get_pin("d:31:i")
    PIN_UP = arduino.get_pin("d:34:i")
    PIN_DOWN = arduino.get_pin("d:33:i")
    PIN_BACK = arduino.get_pin("d:30:i")
    PIN_MOTION = arduino.get_pin("d:8:i")
    PIN_DOOR = arduino.get_pin("d:38:i")

    # Define all lights
    PIN_LED_B1 = arduino.get_pin("d:11:p")
    PIN_LED_B2 = arduino.get_pin("d:10:p")
    PIN_LED1 = arduino.get_pin("d:3:p")
    PIN_LED2 = arduino.get_pin("d:2:p")
Пример #6
0
from random import seed
from random import randint
from random import seed
from random import choice

# Initialize PyGame and PyFirmata

pygame.mixer.init()
board = ArduinoMega('COM7', baudrate=57600)
iterator = pyfirmata.util.Iterator(board)
iterator.start()
time.sleep(1)

# Button Pin Declarations

button2 = board.get_pin('d:2:i')
button4 = board.get_pin('d:4:i')
button6 = board.get_pin('d:6:i')
button8 = board.get_pin('d:8:i')
button10 = board.get_pin('d:10:i')
button12 = board.get_pin('d:12:i')

button30 = board.get_pin('d:30:i')
button32 = board.get_pin('d:32:i')
button34 = board.get_pin('d:34:i')
button36 = board.get_pin('d:36:i')
button38 = board.get_pin('d:38:i')
button40 = board.get_pin('d:40:i')
button42 = board.get_pin('d:42:i')
button44 = board.get_pin('d:44:i')
button46 = board.get_pin('d:46:i')
Пример #7
0
from pyfirmata import ArduinoMega
from pyfirmata import INPUT, OUTPUT, PWM
import RPi.GPIO as GPIO
import numpy as np
import argparse
import imutils
import cv2
import math
import pandas as pd
import matplotlib.pyplot as plt
import time
import serial  # import serial library
arduinoSerialData = serial.Serial('/dev/ttyACM0', 9600, timeout=10)

board = ArduinoMega('/dev/ttyACM0')
servoX = board.get_pin('d:3:s')
servoY = board.get_pin('d:2:s')
# for 1st Motor on ENA
ENA = 33
IN1 = 35
IN2 = 37

# set pin numbers to the board's
GPIO.setmode(GPIO.BOARD)

# initialize EnA, In1 and In2
GPIO.setup(ENA, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(IN1, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(IN2, GPIO.OUT, initial=GPIO.LOW)

# GPIO.output(IN1, GPIO.HIGH)
Пример #8
0
import requests
import nmap
import RPi.GPIO as GPIO
from pyfirmata import ArduinoMega
from pyfirmata.util import Iterator

board = ArduinoMega('/dev/ttyACM0')
GPIO.setmode(GPIO.BCM)
GPIO.setup(26,GPIO.IN)
iterator = Iterator(board)
iterator.start()
pinTemp = board.get_pin('a:0:i')

backend = "http://192.168.1.4:5000"
nm = nmap.PortScanner()

devices = {}
temp = 42.0
lumi = 42.0
people = 0
opt_temp = 0.0


def optimal_temp():
	global opt_temp
	opt_temp = 1.0


def sensors():
	global pinTemp
	global temp
Пример #9
0
import SocketServer
import time

#This code manages the robot itself.
#It also handles communication between the arduino and the motor controller
#Created by Alexis Renderos


GPIO.setmode(GPIO.BCM)

#def arduino board for onboard comms
board = ArduinoMega('/dev/ttyACM0')

#in1-4 are for the arduino to interface with motor controller
	#these determine direction of current
in1pin = board.get_pin('d:22:o')
in2pin = board.get_pin('d:24:o')
in3pin = board.get_pin('d:26:o')
in4pin = board.get_pin('d:28:o')

#for the arduino servo control::gripper
gripper = board.get_pin('d:9:s')

lOutputs = [in1pin, in2pin, in3pin, in4pin, leftSpeed, rightSpeed, gripper]

#for arduino again, this is PWM to attain speed control
enablePin1 = board.get_pin('d:6:p')
enablePin2 = board.get_pin('d:7:p')

global gripped
Пример #10
0
    import assistant_helpers
    import audio_helpers
    import browser_helpers
    import device_helpers

ASSISTANT_API_ENDPOINT = 'embeddedassistant.googleapis.com'
END_OF_UTTERANCE = embedded_assistant_pb2.AssistResponse.END_OF_UTTERANCE
DIALOG_FOLLOW_ON = embedded_assistant_pb2.DialogStateOut.DIALOG_FOLLOW_ON
CLOSE_MICROPHONE = embedded_assistant_pb2.DialogStateOut.CLOSE_MICROPHONE
PLAYING = embedded_assistant_pb2.ScreenOutConfig.PLAYING
DEFAULT_GRPC_DEADLINE = 60 * 3 + 5

port = '/dev/ttyACM0'
board = ArduinoMega(port)
sleep(1)
pin13 = board.get_pin('d:13:p')


class SampleAssistant(object):
    """Sample Assistant that supports conversations and device actions.

    Args:
      device_model_id: identifier of the device model.
      device_id: identifier of the registered device instance.
      conversation_stream(ConversationStream): audio stream
        for recording query and playing back assistant answer.
      channel: authorized gRPC channel for connection to the
        Google Assistant API.
      deadline_sec: gRPC deadline in seconds for Google Assistant API call.
      device_handler: callback for device actions.
    """
import pygame
from pygame.locals import *
import time
from pyfirmata import ArduinoMega, util

from OpenGL.GL import *
from OpenGL.GLU import *

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
body_cascade = cv2.CascadeClassifier('haarcascade_fullbody.xml')

board = ArduinoMega('COM4')
iterator = util.Iterator(board)
iterator.start()

S1 = board.get_pin('d:5:p')  #ght
D1 = board.get_pin('d:7:o')  #right
S2 = board.get_pin('d:4:p')  #ft
D2 = board.get_pin('d:6:o')  #left
time.sleep(1.0)


def left():
    for i in range(50):
        S1.write(i)
        D1.write(0)
        S2.write(i)  #left forward
        D2.write(0)


def right():
Пример #12
0
# from sensor_controller.MyColor import MyColor
import time


BLENDING_CONSTANT = 10

if __name__ == '__main__':
	

	"""
	Setup sensor input
	"""
	
	board = ArduinoMega(SERIAL_INPUT)
	eventGenerator = EventGenerator(board)
	cupXPin_r = board.get_pin('d:5:p')
	cupXPin_g = board.get_pin('d:7:p')
	cupXPin_b = board.get_pin('d:6:p')

	cupXColor = Color(rgb=(0.0, 0.0, 0.0))

	# Init
	board.digital[5].write(1)
	board.digital[6].write(1)
	board.digital[7].write(1)


	dt = 0.0

	# Use a predefined color sequence; either random colors, or a hue
	# gradient. These are Python generators, yielding Color objects.
Пример #13
0
#
# Copyright © 2015 cameron <cameron@Megatron-Virtual>
#
# Distributed under terms of the MIT license.

"""
This Python Script reads data from a soil moisture sensor
"""

from pyfirmata import ArduinoMega, util
from pyfirmata import INPUT
import time

port = "/dev/ttyACM0"
board = ArduinoMega(port)
sensor = board.get_pin("a:0:i")
# board.analog[0].mode = INPUT
it = util.Iterator(board)
it.start()
time.sleep(1)


def get_value():
    """
    This method takes an integer input for the pin to be read. Appropriate
    values range 0-15 for analog pins.
    """
    read_val = sensor.read()
    print(read_val)
    time.sleep(1.0)
Пример #14
0
from SESCdraw import _DRAW
from SESCfunc import _FCM, _FCE, _PASS, _MIN, _MAX, _CEN, _MOV
from pyfirmata import ArduinoMega, util

MESA = "SIMULACAO"
INICIAR = True

mega = ArduinoMega('COM3')
iterator = util.Iterator(mega)
iterator.start()

DM_pin_YGOL_ENE = mega.get_pin('d:18:o')
DM_pin_YGOL_DIR = mega.get_pin('d:19:o')
DM_pin_YGOL_PAS = mega.get_pin('d:20:o')
DM_pin_RGOL_ENE = mega.get_pin('d:21:o')
DM_pin_RGOL_DIR = mega.get_pin('d:22:o')
DM_pin_RGOL_PAS = mega.get_pin('d:23:o')
FC_pin_MGOL_MIN = mega.get_pin('d:24:i')
FC_pin_MGOL_MAX = mega.get_pin('d:25:i')
FC_pin_EGOL = mega.get_pin('d:26:i')

DM_pin_YDEF_ENE = mega.get_pin('d:27:o')
DM_pin_YDEF_DIR = mega.get_pin('d:28:o')
DM_pin_YDEF_PAS = mega.get_pin('d:29:o')
DM_pin_RDEF_ENE = mega.get_pin('d:30:o')
DM_pin_RDEF_DIR = mega.get_pin('d:31:o')
DM_pin_RDEF_PAS = mega.get_pin('d:32:o')
FC_pin_MDEF_MIN = mega.get_pin('d:33:i')
FC_pin_MDEF_MAX = mega.get_pin('d:34:i')
FC_pin_EDEF = mega.get_pin('d:35:i')
Пример #15
0
from time import sleep

# from pysine import sine
from pyfirmata import ArduinoMega
import time

upperbt = 60
lowerbt = 0
l = .3
h = .9
board = ArduinoMega('COM15')
servo1 = board.get_pin('d:7:s')  #
servo2 = board.get_pin('d:8:s')
servo3 = board.get_pin('d:6:s')  #
servo4 = board.get_pin('d:9:s')
servo5 = board.get_pin('d:5:s')  #
servo6 = board.get_pin('d:10:s')
servo7 = board.get_pin('d:4:s')  #
servo8 = board.get_pin('d:13:s')
servo9 = board.get_pin('d:2:s')  #
servo10 = board.get_pin('d:12:s')
servo11 = board.get_pin('d:3:s')  #
servo12 = board.get_pin('d:11:s')
airpin = board.get_pin('d:14:s')  # not used yet
# to initialize all values to zero angle
servo1.write(0)  #
servo2.write(0)
servo3.write(0)  #
servo4.write(0)
servo5.write(0)  #
servo6.write(0)
Пример #16
0
class Mux():
    muxChannel = [[0, 0, 0, 0], # channel 1
                  [1, 0, 0, 0], # channel 2
                  [0, 1, 0, 0], # channel 3
                  [1, 1, 0, 0], # channel 4
                  [0, 0, 1, 0], # channel 5
                  [1, 0, 1, 0], # channel 6
                  [0, 1, 1, 0], # channel 7
                  [1, 1, 1, 0], # channel 8
                  [0, 0, 0, 1], # channel 9
                  [1, 0, 0, 1], # channel 10
                  [0, 1, 0, 1], # channel 11
                  [1, 1, 0, 1], # channel 12
                  [0, 0, 1, 1], # channel 13
                  [1, 0, 1, 1], # channel 14
                  [0, 1, 1, 1], # channel 15
                  [1, 1, 1, 1]] # channel 16

    def __init__(self, cfg):
        # load the config
        self.cfg = cfg
        self.board = ArduinoMega(cfg['ARDUINO_PORT'])

        # iterator thread for reading analog pins
        # self.iter = util.Iterator(self.board)
        # self.iter.start()
        # print("iterator running.")

        # set the select pins as arduino digital pins
        self.s_pin_num = cfg['MUX_SELECT_PINS']
        self.s_pins = [self.board.get_pin('d:' + str(self.s_pin_num[0]) + ':o'),
                       self.board.get_pin('d:' + str(self.s_pin_num[1]) + ':o'),
                       self.board.get_pin('d:' + str(self.s_pin_num[2]) + ':o'),
                       self.board.get_pin('d:' + str(self.s_pin_num[3]) + ':o')]
        # set the signal pin
        # self.sig_pin = self.board.get_pin('d:' + str(cfg['MUX_SIG_PIN']) + ':o')

        # TODO: add some stuff to separate digital and analog pins
        self.sig_pin = self.board.get_pin('a:0:i')

        print("Mux connected.")

    def run(self):
        # TODO: Debugging
        for j in range(0, 5):
            for i in range(0, 3):
                print("channel: " + str(i))
                self.switch_mux(i, 1)

        # exit cleanly
        self.shutdown()

        return 0

    def switch_mux(self, channel, wait_s):
        """
        @about: switch mux signal pin to specified channel for specified time.
        @param: channel to switch the multiplexer to
        @param: wait_s delay time to stay at channel. sometimes the readings
                would take longer to "switch"
        """
        # write to selecter pins to specify the mux output channel
        for i in range(0, 4):
            self.s_pins[i].write(self.muxChannel[channel][i])

        time.sleep(wait_s)

        return 0

    def write_mux(self, channel, wait_s, pin_value):
        """
        @about: call switch mux to switch mux channel. Write to signal pin with
                pin_value.
        # TODO: used for debugging
        """
        # call switch_mux to change the mux channel
        self.switch_mux(channel, wait_s)

        # do something with the LED's
        self.sig_pin.write(pin_value)
        time.sleep(wait_s)
        self.sig_pin.write(0)

        return 0

    def read_analog_resistance(self):
        """
        @brief: (FOR DEBUGGING) read the analog input pin and calculate the resistance
                using a voltage divider
        """
        R_IN = 220.0
        V_IN = 5.0
        V_out = self.sig_pin.read() * V_IN # rescale it to the 5V bar
        R_out = (R_IN * V_out/V_IN) / (1.0 - (V_out/V_IN))
        print('R = %.2f' % R_out)

        return R_out

    def shutdown(self):
        """
        @brief: close connection to board.
        """
        self.board.exit()
        print('Closed connection to mux.')

        return 0
Пример #17
0
#
# Distributed under terms of the MIT license.

"""
This is an experiement to create a breathing LED using Firmata and an
Arduino
"""

from pyfirmata import ArduinoMega
from pyfirmata import OUTPUT, INPUT, PWM
import time

port = "/dev/ttyS3"
board = ArduinoMega(port)

ledPin = board.get_pin('d:2:p')


def increase_range(start, stop, step):
    r = start
    while r < stop:
        yield r
        r += step


def decrease_range(start, stop, step):
    down_step = start
    while down_step > stop:
        yield down_step
        down_step -= step