def __init__(self, devices=1, intensity=5, scanlimit=7): '''Constructor ScanLimit set to 7 Intensity set to 5 out of 0:15 Uses GPIOs 23, 24 25 as DIN, CS, and CLK respectively''' GP = GPIOProcessor() global DIN global CS global CLK DIN = GP.getPin34() # Gpio CS = GP.getPin33() # Gpio CLK = GP.getPin32() # Gpio DIN.out() CS.out() CLK.out() global numOfDevices numOfDevices = devices for i in range(0,numOfDevices): self.shutDown(False,i+1) for i in range(0,numOfDevices): self.setScanLimit(scanlimit,i+1) for i in range(0,numOfDevices): self.setIntensity(intensity,i+1) self.clearDisplays() global Characters Characters = AL()
FULL_STEP_SEQUENCE = [ [1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 1], [1, 0, 0, 1], ] try: steps_made = 0 pins = [ GP.getPin31(), GP.getPin32(), GP.getPin33(), GP.getPin34(), ] for p in pins: p.out() right = GP.getPin27() right.input() left = GP.getPin26() left.input() reset = GP.getPin24() reset.input() sequence = FULL_STEP_SEQUENCE i = 0 direction = 0
from GPIOLibrary import GPIOProcessor import time import math GP = GPIOProcessor() try: # Stepper Motor Controls A1 = GP.getPin34() # Green A2 = GP.getPin24() # Black B1 = GP.getPin33() # White B2 = GP.getPin26() # Yellow A1.out() A2.out() B1.out() B2.out() # Delay time T = 0.001 # Stepper Sequence (Forward ; Reverse) SS = [[[0,1,0,1],[1,0,0,1],[1,0,1,0],[0,1,1,0]], [[0,1,0,1],[0,1,1,0],[1,0,1,0],[1,0,0,1]]] # Forward/Reverse Indicator (0 - Forward, 1 - Reverse) FR = 0 # Step Angle SA = 1.8 # 1.8 degrees per step
from GPIOLibrary import GPIOProcessor import time import math GP = GPIOProcessor() try: # Stepper Motor Controls A1 = GP.getPin34() # Green A2 = GP.getPin24() # Black B1 = GP.getPin33() # White B2 = GP.getPin26() # Yellow A1.out() A2.out() B1.out() B2.out() # Delay time T = 0.001 # Stepper Sequence (Forward ; Reverse) SS = [[[0, 1, 0, 1], [1, 0, 0, 1], [1, 0, 1, 0], [0, 1, 1, 0]], [[0, 1, 0, 1], [0, 1, 1, 0], [1, 0, 1, 0], [1, 0, 0, 1]]] # Forward/Reverse Indicator (0 - Forward, 1 - Reverse) FR = 0 # Step Angle SA = 1.8 # 1.8 degrees per step
import time import math GP = GPIOProcessor() # GPIO assignment # TRIG Pin 23 # ECHO Pin 27 # GREEN Pin 24 # YELLOW Pin 25 # RED Pin 26 try: # Create GPIO variables trig = GP.getPin34() echo = GP.getPin27() green = GP.getPin24() yellow = GP.getPin25() red = GP.getPin26() trig.out() echo.input() green.out() yellow.out() red.out() # Duration of Activation (seconds) D = 10 # Approximate Speed of Sound (cm/s)
class UltrasonicHCSR04: """ Sensor Class maps DragonBoard 410c GPIO pins for Debian to the HC-SR04 ultra-sonic sensor. Approximate Speed of Sound through Air at 20 degrees centigrade 343 metres per second. For "Shallow Water Sensor" Approximate Speed of Sound through Water at 15 degrees centigrade 1464 metres per second. """ def __init__(self): self.speed = 343 # metres per second (m/s) through Air # self.speed = 1464 # metres per second (m/s) through Water self.depth = 0 """ Trig (blue wire) : Pin 33 -> OpAmp Node 2 -> Ultra-sonic sensor Trig Echo (red wire) : Ultra-sonic sensor Echo -> Pin 30 """ self.gp = GPIOProcessor() self.trig = self.gp.getPin33() self.echo = self.gp.getPin34() self.trig.out() self.echo.input() def get_depth(self): return self.depth def set_depth(self, new_depth): self.depth = new_depth def check_depth(self): """ Activate the sensor to send sound ping (Trig) and receive the echo (Echo) underwater, measuring the time interval and calculating and storing the value in depth. """ try: print "Activating Shallow Water Sensor ..." self.trig.low() # time.sleep(0.000002) # at least 2 micro-seconds time.sleep(0.5) # At least 2 micro-seconds. 0.5 tested and working. self.trig.high() time.sleep(0.0001) # At least 5 micro-seconds. 100 tested and working. self.trig.low() print "Pulse sent." # defining variables pulse_start = time.time() pulse_end = time.time() # Wait for pulse to be sent, then # save start time. # Note : Adding counter to break while loop due to weird glitch. counter = 10000 while self.echo.getValue() == 0 and counter > 0: pulse_start = time.time() counter -= 1 # print "counter :", counter if self.echo.getValue() == 1: print "Received echo." while self.echo.getValue() == 1: pulse_end = time.time() if counter == 0: print "No echo received for long period. Return to Manager and start again." self.set_depth(0) return False # Calculate total pulse duration # print "pulse_end time :", pulse_end # print "pulse_start time : ", pulse_start pulse_duration = pulse_end - pulse_start # print "pulse_duration time :", pulse_duration # Use pulse duration to calculate distance # Remember that the pulse has to go there and come back distance = round((pulse_duration * self.speed) / 2, 2) # print "distance :", distance self.set_depth(distance) return True except KeyboardInterrupt(): print "Keyboard interrupt received. Cleaning up ..." self.gp.cleanup() return False
from GPIOLibrary import GPIOProcessor import time GP = GPIOProcessor() try: # Set up GPIO vcc = GP.getPin34() vcc.out() while True: print 'Turn on? [y/n]' r = raw_input() if r == 'y': vcc.high() # Sensor is on print 'Sensor is on.' print 'Exit? [y]' r = raw_input() if r == 'y': vcc.low() else: break finally: GP.cleanup()
# Stepper motor switching sequence seq = [[1, 0, 0, 0], [1, 1, 0, 0], [0, 1, 0, 0], [0, 1, 1, 0], [0, 0, 1, 0], [0, 0, 1, 1], [0, 0, 0, 1], [1, 0, 0, 1]] stepAngle = 5.625 delay = 0.0003 #delay = 1 GP = GPIOProcessor() try: # Use pins 231, 33, 30, and 34 to control motor out0 = GP.getPin29() # Blue out1 = GP.getPin33() # Pink out2 = GP.getPin30() # Yellow out3 = GP.getPin34() # Orange outl = [out0, out1, out2, out3] outl.reverse() # Set the pin direction to out for k in range(4): outl[k].out() # Rotation in degrees degrees = 90 steps_per_deg = 4076.0 / 360.0 steps = math.floor(steps_per_deg * degrees) for k in range(steps): # print("Step: {0:2d}".format(k))
from GPIOLibrary import GPIOProcessor import time GP = GPIOProcessor() try: Pin34 = GP.getPin34() Pin34.out() for k in range(0, 10): Pin34.high() time.sleep(0.5) Pin34.low() time.sleep(0.5) finally: GP.cleanup()
from GPIOLibrary import GPIOProcessor import time GP = GPIOProcessor() try: receiverPin = GP.getPin33() senderPin = GP.getPin34() receiverPin.out() senderPin.input() for i in range(0, 10): Pin34.high() time.sleep(0.5) Pin34.low() time.sleep(0.5) finally: GP.cleanup()
import time GP = GPIOProcessor() # GPIO Assignments #Din = 27 #A1 = 34 Green #A2 = 33 White #A3 = 24 Black #A4 = 26 Yellow #PIR = 29 #Ind = 30 Din = GP.getPin27() Din.input() A1 = GP.getPin34() A1.out() A2 = GP.getPin33() A2.out() A3 = GP.getPin24() A3.out() A4 = GP.getPin26() A4.out() PIR = GP.getPin29() PIR.out() PIR.low() Ind = GP.getPin30() Ind.out() Ind.low() # Remote Average Pulse
# Stepper motor switching sequence seq = [[1,0,0,0], [1,1,0,0], [0,1,0,0], [0,1,1,0], [0,0,1,0], [0,0,1,1], [0,0,0,1], [1,0,0,1]] stepAngle = 5.625 delay = 0.0003 #delay = 1 GP = GPIOProcessor() try: # Use pins 231, 33, 30, and 34 to control motor out0 = GP.getPin29() # Blue out1 = GP.getPin33() # Pink out2 = GP.getPin30() # Yellow out3 = GP.getPin34() # Orange outl = [out0, out1, out2, out3] outl.reverse() # Set the pin direction to out for k in range(4): outl[k].out() # Rotation in degrees degrees = 90 steps_per_deg =4076.0/360.0 steps = math.floor(steps_per_deg * degrees) for k in range(steps): # print("Step: {0:2d}".format(k))
from GPIOLibrary import GPIOProcessor import time GP = GPIOProcessor() try: Pin34 = GP.getPin34() Pin34.out() for i in range(0,10): Pin34.high() time.sleep(0.5) Pin34.low() time.sleep(0.5) finally: GP.cleanup()