#---------------------------- #Initialize class instances for experiment: #---------------------------- #Turn off the GPIO warnings GPIO.setwarnings(False) #Set the mode of the pins (broadcom vs local) GPIO.setmode(GPIO.BCM) #set the enable pins for L and R stepper motors to 1 to prevent overheating GPIO.setup(L_enablePIN, GPIO.OUT, initial=1) GPIO.setup(R_enablePIN, GPIO.OUT, initial=1) #create Stepper class instances for left and right reward delivery water_L = core.stepper(L_enablePIN, L_directionPIN, L_stepPIN, L_emptyPIN) water_R = core.stepper(R_enablePIN, R_directionPIN, R_stepPIN, R_emptyPIN) #create lickometer class instances for left and right lickometers lick_port_L = core.lickometer(L_lickometer) lick_port_R = core.lickometer(R_lickometer) tone_go = core.tones(go_tone_freq, 0.75) camera = PiCamera() #---------------------------- #Initialize experiment #---------------------------- camera.start_preview(rotation=180, fullscreen=False, window=(0, -44, 350, 400))
#When the EasyDriver is initiated, the enable pin will be set to 0 (enabled) by #default, which will send power to the coils of the stepper motor and could lead #to overheating. The purpose of this script is simply to reset the enable pins #to 1 (disabled) to prevent this. This script should be run as soon as the #EasyDrivers are plugged in. import core import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) L_enablePIN = 23 #enable pin for left stepper motor L_directionPIN = 24 #direction pin for left stepper motor L_stepPIN = 25 #step pin for left stepper motor L_emptyPIN = 20 #empty switch pin for left stepper motor R_enablePIN = 10 #enable pin for right stepper motor R_directionPIN = 9 #direction pin for right stepper motor R_stepPIN = 11 #step pin for right stepper motor R_emptyPIN = 21 #empty switch pin for right stepper motor #Create instances of class core.stepper for right and left left = core.stepper(L_enablePIN, L_directionPIN, L_stepPIN, L_emptyPIN) right = core.stepper(R_enablePIN, R_directionPIN, R_stepPIN, R_emptyPIN) #Call Disable method from class stepper to set enablePIN to 1 (disabled) left.Disable() right.Disable() print('Disabled.')
GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) L_enablePIN = 23 #enable pin for left stepper motor L_directionPIN = 24 #direction pin for left stepper motor L_stepPIN = 25 #step pin for left stepper motor L_emptyPIN = 20 #empty switch pin for left stepper motor L_lickometer = 12 #input pin for lickometer (black wire) R_enablePIN = 10 #enable pin for right stepper motor R_directionPIN = 9 #direction pin for right stepper motor R_stepPIN = 11 #step pin for right stepper motor R_emptyPIN = 21 #empty switch pin for right stepper motor R_lickometer = 16 #input pin for lickometer (black wire) stepperL = core.stepper(L_enablePIN, L_directionPIN, L_stepPIN, L_emptyPIN) stepperR = core.stepper(R_enablePIN, R_directionPIN, R_stepPIN, R_emptyPIN) syringe = True while syringe == True: side = input('Which side? (L/R/Q): ') if side == 'L': steps = input('How many steps?: ') stepperL.Motor(1, steps) elif side == 'R': steps = input('How many steps?: ') stepperR.Motor(1, steps) elif side == 'Q': syringe = False
#Turn off the GPIO warnings GPIO.setwarnings(False) #Set the mode of the pins (broadcom vs local) GPIO.setmode(GPIO.BCM) #set the enable pins for L and R stepper motors to 1 to prevent overheating GPIO.setup(L_enablePIN, GPIO.OUT, initial=1) GPIO.setup(R_enablePIN, GPIO.OUT, initial=1) #initialize the mixer (for tones) at the proper sampling rate. mixer.init(frequency=44100) #create Stepper class instance water = core.stepper(L_enablePIN, L_directionPIN, L_stepPIN, L_emptyPIN) #create tone tone = core.tones(tone_freq, sample_tone_length, single_pulse_length) #1000Hz single pulse loop = True while loop == True: raw_input = input('Ready to play tone (ENTER) ') tone.Play() water.Reward() time.sleep(2)