Example #1
0
	def __init__(self):
		Pi_rev = wiringpi2.piBoardRev()	#@TODO: use this?
		self.GPIOS = {
			'internal_buzzer': 11,
			'latch': 7,
			'unlock_LED': 15,
			'deny_LED': 13,
			'buzzer': 12, 
			'doorStatus1': 19,
			'doorStatus2': 21,
		}
		
		#set up I/O pins
		wiringpi2.wiringPiSetupPhys()
		wiringpi2.pinMode(self.GPIOS['unlock_LED'], 1)
		wiringpi2.pinMode(self.GPIOS['deny_LED'], 1)
		wiringpi2.pinMode(self.GPIOS['latch'], 1)
		wiringpi2.pinMode(self.GPIOS['internal_buzzer'], 1)
		wiringpi2.pinMode(self.GPIOS['doorStatus1'], 0)
		wiringpi2.pinMode(self.GPIOS['doorStatus2'], 0)
		
		GPIO.setup(9, GPIO.IN)  
		GPIO.setup(10, GPIO.IN)  
		#GPIO.add_event_detect(9, GPIO.FALLING, callback=self.arm_security, bouncetime=300)
		#Set up Hardware PWM - Only works on GPIO 18 (Phys 12)
		wiringpi2.pwmSetMode(0)				# set PWM to markspace mode
		wiringpi2.pinMode(self.GPIOS['buzzer'], 2)      # set pin to PWM mode
		wiringpi2.pwmSetClock(750)   			# set HW PWM clock division (frequency)
		wiringpi2.pwmWrite(self.GPIOS['buzzer'], 0)
		
		proc = subprocess.Popen(['nfc-list'], stderr=subprocess.PIPE)
		result = proc.stderr.read()
		self.PN532 = False if 'Timeout' in result else True
		if not self.PN532:
			self.nfc = NFC.MFRC522()
Example #2
0
 def initQTI(self,wiring=True):
     #pin = pinNum
     if wiring == True:
         wp.wiringPiSetup()
         wp.wiringPiSetupGpio()
         wp.wiringPiSetupPhys()
     else:
         GPIO.setmode(GPIO.BOARD)
Example #3
0
    def __init__(self, stepPin, dirPin):
        #initial a Bipolar_Stepper_Moter objects by assigning the pins
        wiringpi2.wiringPiSetupPhys()

        self.stepPin = stepPin
        self.dirPin = dirPin

        wiringpi2.pinMode(self.stepPin, 1)
        wiringpi2.pinMode(self.dirPin, 1)
        print "Stepper Configured"
Example #4
0
 def __init__(self,stepPin,dirPin):
 	#initial a Bipolar_Stepper_Moter objects by assigning the pins
     wiringpi2.wiringPiSetupPhys()
     
     self.stepPin=stepPin
     self.dirPin=dirPin
     
     wiringpi2.pinMode(self.stepPin,1)
     wiringpi2.pinMode(self.dirPin,1)
     print "Stepper Configured"   
Example #5
0
def setup():
    wiringpi.wiringPiSetupPhys()
    wiringpi.pinMode(OneW, OUTPUT)
    wiringpi.pinMode(OneB, OUTPUT)
    wiringpi.pinMode(OneG, OUTPUT)
    wiringpi.pinMode(OneY, OUTPUT)
    wiringpi.pinMode(OneR, OUTPUT)
    wiringpi.pinMode(TwoW, OUTPUT)
    wiringpi.pinMode(TwoB, OUTPUT)
    wiringpi.pinMode(TwoG, OUTPUT)
    wiringpi.pinMode(TwoY, OUTPUT)
    wiringpi.pinMode(TwoR, OUTPUT)
Example #6
0
    def __init__(self, lock):
        threading.Thread.__init__(self)
        self.__lock = lock

        # SPI (MCP3008)
        self.__adc = MCP3008(SPI_const.CS0, 0, self.__lock)

        # Hardware PWM
        wipi.wiringPiSetupPhys()
        wipi.pinMode(12, 2)   # TODO: have pin as parameter to __init__()

        self.__running = True
Example #7
0
    def __init__(self, lock):
        threading.Thread.__init__(self)
        self.__lock = lock

        # SPI (MCP3008)
        self.__adc = MCP3008(SPI_const.CS0, 0, self.__lock)

        # Hardware PWM
        wipi.wiringPiSetupPhys()
        wipi.pinMode(12, 2)  # TODO: have pin as parameter to __init__()

        self.__running = True
    def __init__(self, pin, lock):
        threading.Thread.__init__(self)
        self.__pin  = pin
        self.__lock = lock

        # SPI (MCP3008)
        self.__adc = MCP3008(SPI_const.CS0, 0, self.__lock)

        # Hardware PWM
        wipi.wiringPiSetupPhys()
        wipi.pinMode(self.__pin, 2)

        self.__running = True
Example #9
0
def setup():
    wiringpi.wiringPiSetupPhys()
    # assign pins
    wiringpi.pinMode(RST, OUTPUT)
    wiringpi.pinMode(A0, OUTPUT)
    wiringpi.pinMode(A1, OUTPUT)
    wiringpi.pinMode(A2, OUTPUT)
    wiringpi.pinMode(A3, OUTPUT)
    wiringpi.pinMode(CE, OUTPUT)
    wiringpi.pinMode(WR, OUTPUT)
    wiringpi.pinMode(latch, OUTPUT)
    wiringpi.pinMode(SER, OUTPUT)
    wiringpi.pinMode(CLK, OUTPUT)
    resetdisplay()
    def __init__(self, pid, default_value=None, max_value=None):
        super(GPIOPWMPin, self).__init__(pid)

        if default_value is None:
            self.default_value = self.DEFAULT_VALUE
        else:
            self.default_value = default_value

        if max_value is None:
            self.max_value = self.MAX_VALUE
        else:
            self.max_value = max_value

        wiringpi.wiringPiSetupPhys()
        wiringpi.softPwmCreate(pid, self.default_value, self.max_value)
Example #11
0
def setup():
    wiringpi.wiringPiSetupPhys()
    # assign pins
    wiringpi.pinMode(RST, OUTPUT)
    wiringpi.pinMode(A0, OUTPUT)
    wiringpi.pinMode(A1, OUTPUT)
    wiringpi.pinMode(A2, OUTPUT)
    wiringpi.pinMode(A3, OUTPUT)
    wiringpi.pinMode(CE, OUTPUT)
    wiringpi.pinMode(WR, OUTPUT)
    wiringpi.pinMode(latch, OUTPUT)
    wiringpi.pinMode(SER, OUTPUT)
    wiringpi.pinMode(CLK, OUTPUT)
    wiringpi.pinMode(DSP0, OUTPUT)
    wiringpi.pinMode(DSP1, OUTPUT)
    resetdisplay()
Example #12
0
 def setup(self, **kwargs):
     """ Initialise this particular Dock instance
 """
     # Initialise wiringpi2
     wiringpi2.wiringPiSetupPhys()
     # Set up the hardware interfaces
     global SLOTS
     self.slots = dict()
     for slot in SLOTS:
         info = SLOTS[slot]
         # Initialise the hardware
         if info[3] <> 0:
             wiringpi2.pinMode(info[3], 1)
         if info[4] <> 0:
             wiringpi2.pinMode(info[4], 0)
         if info[5] <> 0:
             wiringpi2.pinMode(info[5], 0)
         # Create the slot instance
         self.slots[slot] = info[0](info)
Example #13
0
def init_board():
  wiringpi.wiringPiSetupPhys()
  wiringpi.pinMode(7, 1)
  wiringpi.pinMode(11, 1)
  wiringpi.pinMode(13, 1)
### need to insert code to blank display so that the next line doesn't flash all segments until data is displayed
  wiringpi.pinMode(12, 2)
  wiringpi.pwmWrite(12, disp_numbrt)
  try:
    for x in [disp_home, disp_away]:
      i2c.write_byte_data(x, 0x04, 0x05)                                  # Turns MAX6953 on and sets fast blink
      i2c.write_i2c_block_data(x, 0x01, [disp_teambrt, disp_teambrt])     # Sets brightness for the team name
      i2c.write_byte_data(x, 0x03, 0x01)                                  # Sets SCANLIMIT to 4
  except:
    init_board()
    return
  disp_ready.set()
  print "Board Initialized"
  return
Example #14
0
 def setup(self, **kwargs):
   """ Initialise this particular Dock instance
   """
   # Initialise wiringpi2
   wiringpi2.wiringPiSetupPhys()
   # Set up the hardware interfaces
   global SLOTS
   self.slots = dict()
   for slot in SLOTS:
     info = SLOTS[slot]
     # Initialise the hardware
     if info[3] <> 0:
       wiringpi2.pinMode(info[3], 1)
     if info[4] <> 0:
       wiringpi2.pinMode(info[4], 0)
     if info[5] <> 0:
       wiringpi2.pinMode(info[5], 0)
     # Create the slot instance
     self.slots[slot] = info[0](info)
Example #15
0
def main():

  # use BCM GPIO numbers
  wp.wiringPiSetupPhys()
  # enable PWM0
  wp.pinMode(12,2)
  # switch from default mode to mark:space mode
  wp.pwmSetMode(PWM_MODE_MS)
  wp.pwmSetClock(200)
  wp.pwmWrite(12, 0)

  while True:
    try:
  wp.pwmWrite(12, 2)
      time.sleep(3)
      # turn then wait
      wp.pwmWrite(12,128)
      time.sleep(3)
      # turn then wait
      wp.pwmWrite(12, 256)
      time.sleep(3)
Example #16
0
    def __init__(self):
        # Set up the wiringpi object to use physical pin numbers
        wp.wiringPiSetupPhys()

        # Initialize the DRDY pin
        wp.pinMode(self.DRDY_PIN, wp.INPUT)

        # Initialize the reset pin
        wp.pinMode(self.RESET_PIN, wp.OUTPUT)
        wp.digitalWrite(self.RESET_PIN, wp.HIGH)

        # Initialize PDWN pin
        wp.pinMode(self.PDWN_PIN, wp.OUTPUT)
        wp.digitalWrite(self.PDWN_PIN, wp.HIGH)

        # Initialize CS pin
        wp.pinMode(self.CS_PIN, wp.OUTPUT)
        wp.digitalWrite(self.CS_PIN, wp.HIGH)

        # Initialize the wiringpi SPI setup
        spi_success = wp.wiringPiSPISetup(self.SPI_CHANNEL, self.SPI_FREQUENCY) 
        debug_print("SPI success " + str(spi_success))
Example #17
0
def findDistance(TYPE):
    ON=1
    OFF=0
    IN=0
    OUT=1
    PULSE=0.00001
    SPEED_OF_SOUND=34029

    if TYPE == "front":
        TRIG = 15
        ECHO = 13
    elif TYPE == "back":
        TRIG = 16
        ECHO = 18
    elif TYPE != "stop":
        return False
    else: return True

    wiringpi2.wiringPiSetupPhys()
    wiringpi2.pinMode(TRIG, OUT)
    wiringpi2.pinMode(ECHO, IN)
    wiringpi2.digitalWrite(TRIG, OFF)

    wiringpi2.digitalWrite(TRIG, ON)
    time.sleep(PULSE)
    wiringpi2.digitalWrite(TRIG, OFF)
    starttime=time.time()
    stop=starttime
    start=starttime

    while wiringpi2.digitalRead(ECHO)==0 and start<starttime+2:
        start=time.time()
    while wiringpi2.digitalRead(ECHO)==1 and stop<starttime+2:
        stop=time.time()
    delta=stop-start
    resultDistance=delta*SPEED_OF_SOUND
    return resultDistance/2.0
Example #18
0
import wiringpi2
import sys
pin = 31

#wiringpi2.wiringPiSetup()
#wiringpi2.wiringPiSetupSys()
#wiringpi2.wiringPiSetupGpio()
wiringpi2.wiringPiSetupPhys()
wiringpi2.pinMode(pin,2)  #PWM_OUTPUT

while 1:
	#wiringpi2.pwmWrite(pin,128)
	print "===== set clock"
	wiringpi2.pwmSetClock(0) # 24M/120 * 256 = 781HZ 
	wiringpi2.delay(1000)
	wiringpi2.pwmSetClock(1);# 24M/180 * 256 = 520.8HZ 
	wiringpi2.delay(1000)
	wiringpi2.pwmSetClock(2);# 24/240 * 256 = 390HZ
	wiringpi2.delay(1000)
	#wiringpi2.pwmSetRange(255);
#	wiringpi2.pwmWrite(pin,1);
#	wiringpi2.delay(1000)
#	wiringpi2.pwmWrite(pin,128);
#	wiringpi2.delay(1000)
#	wiringpi2.pwmWrite(pin,255)
#	wiringpi2.delay(1000)
#	print "================>>>>"
#	pwmSetMode(0);
	#wiringpi2.pwmWrite(pin,128)
Example #19
0
import wiringpi2 as wp 
wp.wiringPiSetupPhys()

import os
if os.geteuid() != 0:
    print('WARNING: Not root')

INPUT = 0
OUTPUT = 1
PWM = 2
PUD_DOWN = 1
PUD_UP = 2

output_pins = []

# controls a victor
# must use the hardware pwm on physical pin 12
class Victor(object):
    def __init__(self, freq = 100.0):
        self.freq = freq
        output_pins.append(12)
        wp.pinMode(12, PWM)
        wp.pwmSetRange(4000) #range can go up to 4096, 4000 is good because it's large and a multiple of 100
        clock = 19.2e6 / (4000.0 * freq) #set the divisor so the frequency comes out right
        wp.pwmSetClock(int(clock)) #this function needs an int
	wp.pwmSetMode(0) # necessary or else it's in a weird mode where nothing works
	wp.pwmWrite(12, 0) # stop for safety

    def set(self, speed):
        if speed > 1.0:
            speed = 1.0
Example #20
0
 def GPIOsetup(self):
     wiringpi2.wiringPiSetupPhys()
     for gpio in self.pins:
         wiringpi2.pinMode(gpio, OUT)
Example #21
0
	def run(self,config):		
		self.config = config

		while(1):
			p.rint("LIGHT, thread started","l")
			self.alive = True


			# Create NeoPixel object with appropriate configuration.
			if(str(self.config.with_lights) == "1"):
				p.rint("LIGHT, configured with NEO usage","l")
				if(self.neo_support and self.neo_loaded!=1):
					p.rint("LIGHT, neopixel supported, starting","l")
					strip = Adafruit_NeoPixel(self.neo_LED_COUNT, self.neo_LED_PIN, self.neo_LED_FREQ_HZ, self.neo_LED_DMA, self.neo_LED_INVERT, self.neo_LED_BRIGHTNESS)
					# Intialize the library (must be called once before other functions).
					strip.begin()
					strip.show()
					self.neo_loaded = 1 	# avoid loading it twice
				elif(self.neo_support):
					p.rint("LIGHT, neopixel already loaded","l")
				else:
					p.rint("LIGHT, ERROR neopixel not supported","l")
			elif(str(self.config.with_lights) == "2"):
				p.rint("LIGHT, configured with PWM usage","l")
				if(self.pwm_support):
					p.rint("LIGHT, PWM supported, starting","l")
					wiringpi.wiringPiSetupPhys()
					wiringpi.pinMode(12,2)
				else:
					p.rint("LIGHT, ERROR PWM not supported","l")
			elif(str(self.config.with_lights) == "3"):
				p.rint("LIGHT, configured with i2c usage","l")
				if(self.i2c_support and self.i2c_loaded!=1):
					p.rint("LIGHT, i2c supported, starting","l")
					salsa = arduino_bridge.connection()
					salsa.setup_pwm_output(0)
					salsa.setup_pwm_output(1)
					salsa.setup_pwm_output(2)
					salsa.setup_pwm_output(3)
					self.i2c_loaded = 1
				elif(self.i2c_loaded == 1):
					p.rint("LIGHT, i2c already loaded","l")
				else:
					p.rint("LIGHT, ERROR i2c not supported","l")
			else:
				p.rint("LIGHT, started without pwm and neo and i2c","l")
				p.rint("LIGHT, selection was "+str(self.config.with_lights),"l")

			while self.alive:
				### ------------ check if we have something to do ------------ ###
				if(len(self.light_dimming_q) > 0):
					for data in self.light_dimming_q:
						if(data[0]<=time.time()):
							light_action=data
							self.light_dimming_q.remove(data)
							if(light_action[1]==-1 and light_action[2]==-1 and light_action[3]==-1):
								self.return_to_old(light_action[4])
							else:
								self.dimm_to(light_action[1],light_action[2],light_action[3],light_action[4])
				### ------------ check if we have something to do ------------ ###

				if(self.l.state==1):						# state= 1 means dimming is active
					if(time.time()>=self.l.last_ts+self.l.ms_step/1000):	# last_ts holds time of last event, ms_step the time between two dimm steps, 
											# if that sum is smaller than NOW - we have work
						self.l.last_ts=time.time()			# refresh last_ts to now
						differ_r=self.l.s_r-self.l.t_r			# caluclate the difference of each color between the start and the end color
						differ_g=self.l.s_g-self.l.t_g
						differ_b=self.l.s_b-self.l.t_b
						differ_time=(self.l.t_t-self.l.s_t)		# calulate the total time between the start and end 
											#(this should be the same as the "dimm time" specified by the user)
						if(differ_time>0):			# if the user set instant switch, this time will be 0. avoid division by zero
							ratio=(time.time()-self.l.s_t)/(self.l.t_t-self.l.s_t)	# ratio of the time that has passed, should be 0..1
						else:
							ratio=1
						if(ratio<1):				# if ratio is below 1 we are still in the middle of the dimming
							if(LED_DEBUG):
								print(".", end="")
							self.l.c_r=int(self.l.s_r-ratio*differ_r)	# refresh the r,g,b parts to the current dimm ratio (minus since we did a "self.l.s_r - self.l.t_r")
							self.l.c_g=int(self.l.s_g-ratio*differ_g)
							self.l.c_b=int(self.l.s_b-ratio*differ_b)

						else:					# ratio is bigger than one, time has passed, set it to target color
							self.l.c_r=int(self.l.t_r)
							self.l.c_g=int(self.l.t_g)
							self.l.c_b=int(self.l.t_b)
							self.l.state=0 			# stop further dimming
							if(LED_DEBUG):
								print("LED stop at "+str(time.time())+" "+str(self.l.c_r)+"/"+str(self.l.c_g)+"/"+str(self.l.c_b))


						self.l.c_r=max(min(255,self.l.c_r),0)		# avoid that we set a value bigger then 255 or smaller then 0
						self.l.c_g=max(min(255,self.l.c_g),0)
						self.l.c_b=max(min(255,self.l.c_b),0)

						# neo pixel
						if(str(self.config.with_lights) == "1" and self.neo_support):
							for i in range(0,self.neo_LED_COUNT):
								strip.setPixelColor(i,Color(self.l.c_r,self.l.c_g,self.l.c_b))		# set value
							strip.show()
						# neo pixel
						# pwm controll on pin 12
						elif(str(self.config.with_lights) == "2" and self.pwm_support):
							wiringpi.pwmWrite(12, self.l.c_r*4)
						# pwm controll on pin 12
						# i2c controll
						elif(str(self.config.with_lights) == "3" and self.i2c_support):
							try:
								print(str(self.l.c_b))
								salsa.dimmTo(0,int(self.l.c_r/2.55),10) #  dimming is in % #R
								salsa.dimmTo(1,int(self.l.c_g/2.55),10) #  dimming is in % #G
								salsa.dimmTo(2,int(self.l.c_b/2.55),10) #  dimming is in % #B
								salsa.dimmTo(3,int(self.l.c_b/2.55),10) #  dimming is in % #B

							except:
								print("LIGHT i2c bus transaction crashed")
						# i2c controll

						# we can wait here a little while because we know that nothing will happen for us earlier than that anyway
						time.sleep(0.8*self.l.ms_step/1000) 		

				else:
					time.sleep(0.01) # sleep to avoid 100% cpu
				# while
		p.rint("LIGHT, thread stopped","l")
 def GPIOsetup(self):
   wiringpi2.wiringPiSetupPhys()
   for gpio in self.pins:
     wiringpi2.pinMode(gpio,IN)
     wiringpi2.pullUpDnControl(gpio,PULL_UP)    
Example #23
0
rightPressed = False
leftPressed = False

coins = 0
STEP = 0
OVERRIDE = 100
# add this in /boot/config.txt (remove first # on every row)
#
# # uncomment to force a specific HDMI mode (this will force VGA)
# hdmi_group=2
# hdmi_mode=8

# http://raspi.tv/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio-part-2
import wiringpi2 as GPIO
GPIO.wiringPiSetupPhys()

# Wiring Joystick + buttons:
# door signal   gpio23  pin 33  open when high
# coin signal   gpio22  pin 31  active high

pinUp = 38
pinRight = 32
pinLeft = 36
pinDown = 40
pinShoot = 35
pinReady = 37

pinWiringDoorOcto = 33  # door open when HIGH

pinWiringPlugA = 8
Example #24
0
	def run(self,config):		
		self.config = config

		while(1):
			p.rint("LIGHT, thread started","l")
			self.alive = True

			self.config.with_neo=0
			self.config.with_pwm=0
			self.config.with_i2c=1

			# Create NeoPixel object with appropriate configuration.
			if(self.config.with_neo):
				p.rint("LIGHT, configured with NEO usage","l")
				if(self.neo_support and self.neo_loaded!=1):
					p.rint("LIGHT, neopixel supported, starting","l")
					strip = Adafruit_NeoPixel(self.neo_LED_COUNT, self.neo_LED_PIN, self.neo_LED_FREQ_HZ, self.neo_LED_DMA, self.neo_LED_INVERT, self.neo_LED_BRIGHTNESS)
					# Intialize the library (must be called once before other functions).
					strip.begin()
					strip.show()
					self.neo_loaded = 1 	# avoid loading it twice
				elif(self.neo_support):
					p.rint("LIGHT, neopixel already loaded","l")
				else:
					p.rint("LIGHT, ERROR neopixel not supported","l")
			elif(self.config.with_pwm):
				p.rint("LIGHT, configured with PWM usage","l")
				if(self.pwm_support):
					p.rint("LIGHT, PWM supported, starting","l")
					wiringpi.wiringPiSetupPhys()
					wiringpi.pinMode(12,2)
				else:
					p.rint("LIGHT, ERROR PWM not supported","l")
			elif(self.config.with_i2c and self.i2c_loaded!=1):
				p.rint("LIGHT, configured with i2c usage","l")
				if(self.i2c_support):
					p.rint("LIGHT, i2c supported, starting","l")
					bus = i2c.I2CMaster(1)
					self.i2c_loaded = 1
				else:
					p.rint("LIGHT, ERROR i2c not supported","l")
			else:
				p.rint("LIGHT, started without pwm and neo","l")

			while self.alive:
				### ------------ check if we have something to do ------------ ###
				if(len(self.light_dimming_q) > 0):
					for data in self.light_dimming_q:
						if(data[0]<=time.time()):
							light_action=data
							self.light_dimming_q.remove(data)
							if(light_action[1]==-1 and light_action[2]==-1 and light_action[3]==-1):
								self.return_to_old(light_action[4])
							else:
								self.dimm_to(light_action[1],light_action[2],light_action[3],light_action[4])
				### ------------ check if we have something to do ------------ ###

				if(self.l.state==1):						# state= 1 means dimming is active
					if(time.time()>=self.l.last_ts+self.l.ms_step/1000):	# last_ts holds time of last event, ms_step the time between two dimm steps, 
											# if that sum is smaller than NOW - we have work
						self.l.last_ts=time.time()			# refresh last_ts to now
						differ_r=self.l.s_r-self.l.t_r			# caluclate the difference of each color between the start and the end color
						differ_g=self.l.s_g-self.l.t_g
						differ_b=self.l.s_b-self.l.t_b
						differ_time=(self.l.t_t-self.l.s_t)		# calulate the total time between the start and end 
											#(this should be the same as the "dimm time" specified by the user)
						if(differ_time>0):			# if the user set instant switch, this time will be 0. avoid division by zero
							ratio=(time.time()-self.l.s_t)/(self.l.t_t-self.l.s_t)	# ratio of the time that has passed, should be 0..1
						else:
							ratio=1
						if(ratio<1):				# if ratio is below 1 we are still in the middle of the dimming
							if(LED_DEBUG):
								print(".", end="")
							self.l.c_r=int(self.l.s_r-ratio*differ_r)	# refresh the r,g,b parts to the current dimm ratio (minus since we did a "self.l.s_r - self.l.t_r")
							self.l.c_g=int(self.l.s_g-ratio*differ_g)
							self.l.c_b=int(self.l.s_b-ratio*differ_b)

						else:					# ratio is bigger than one, time has passed, set it to target color
							self.l.c_r=int(self.l.t_r)
							self.l.c_g=int(self.l.t_g)
							self.l.c_b=int(self.l.t_b)
							self.l.state=0 			# stop further dimming
							if(LED_DEBUG):
								print("LED stop at "+str(time.time())+" "+str(self.l.c_r)+"/"+str(self.l.c_g)+"/"+str(self.l.c_b))


						self.l.c_r=max(min(255,self.l.c_r),0)		# avoid that we set a value bigger then 255 or smaller then 0
						self.l.c_g=max(min(255,self.l.c_g),0)
						self.l.c_b=max(min(255,self.l.c_b),0)

						# neo pixel
						if(self.config.with_neo and self.neo_support):
							for i in range(0,self.neo_LED_COUNT):
								strip.setPixelColor(i,Color(self.l.c_r,self.l.c_g,self.l.c_b))		# set value
							strip.show()
						# neo pixel
						# pwm controll on pin 12
						elif(self.config.with_pwm and self.pwm_support):
							wiringpi.pwmWrite(12, self.l.c_r*4)
						# pwm controll on pin 12
						# i2c controll
						elif(self.config.with_i2c and self.i2c_support):
							if(1):#try:
								address = 4
								pin_r = 9
								pin_g = 6
								pin_b = 5
								

								bus.transaction(i2c.writing_bytes(address, 0xCE, pin_r,0x02, self.l.c_r, self.l.c_g, self.l.c_b))
								#bus.transaction(i2c.writing_bytes(address, 0xCE, pin_g,0x01, self.l.c_g))
								#bus.transaction(i2c.writing_bytes(address, 0xCE, pin_b,0x01, self.l.c_b))
							else:#xcept:
								print("LIGHT i2c bus transaction crashed")
						# i2c controll

						# we can wait here a little while because we know that nothing will happen for us earlier than that anyway
						time.sleep(0.8*self.l.ms_step/1000) 		

				else:
					time.sleep(0.01) # sleep to avoid 100% cpu
				# while
		p.rint("LIGHT, thread stopped","l")
 def __init__(self, pid):
     super(GPIOInputPin, self).__init__(pid)
     wiringpi.wiringPiSetupPhys()
     wiringpi.pinMode(pid, 0)
def gpiosetup():
  wiringpi2.wiringPiSetupPhys()
  wiringpi2.pinMode(TRIGGER,OUT)
  wiringpi2.pinMode(ECHO,IN)
  wiringpi2.digitalWrite(TRIGGER,OFF)
  time.sleep(0.5)
Example #27
0
def setup():
    wiringpi.wiringPiSetupPhys()
    for pin in pins:
        wiringpi.pinMode(pin, OUTPUT)
 def GPIOsetup(self):
     wiringpi2.wiringPiSetupPhys()
     wiringpi2.pinMode(PWM_PIN, PWM)
     wiringpi2.pwmWrite(PWM_PIN, ON_TIME)
     for gpio in self.pins:
         wiringpi2.pinMode(gpio, OUT)
Example #29
0
def motor_go(TYPE, angle=90):
    ON = 1
    OFF = 0
    IN = 0
    OUT = 1

    M1 = 38
    M2 = 40
    PWMA = 37
    M3 = 31
    M4 = 33
    PWMB = 32

    wiringpi2.wiringPiSetupPhys()
    wiringpi2.pinMode(M1, OUT)
    wiringpi2.pinMode(M2, OUT)
    wiringpi2.pinMode(M3, OUT)
    wiringpi2.pinMode(M4, OUT)
    wiringpi2.pinMode(PWMA, OUT)
    wiringpi2.pinMode(PWMB, OUT)

    def stop():
        wiringpi2.digitalWrite(M1, OFF)
        wiringpi2.digitalWrite(M2, OFF)
        wiringpi2.digitalWrite(M3, OFF)
        wiringpi2.digitalWrite(M4, OFF)

    def front():
        wiringpi2.digitalWrite(M1, ON)
        wiringpi2.digitalWrite(M2, OFF)
        wiringpi2.digitalWrite(M3, ON)
        wiringpi2.digitalWrite(M4, OFF)

    def back():
        wiringpi2.digitalWrite(M1, OFF)
        wiringpi2.digitalWrite(M2, ON)
        wiringpi2.digitalWrite(M3, OFF)
        wiringpi2.digitalWrite(M4, ON)

    def left():
        wiringpi2.digitalWrite(M1, ON)
        wiringpi2.digitalWrite(M2, OFF)
        wiringpi2.digitalWrite(M3, OFF)
        wiringpi2.digitalWrite(M4, ON)

    def right():
        wiringpi2.digitalWrite(M1, OFF)
        wiringpi2.digitalWrite(M2, ON)
        wiringpi2.digitalWrite(M3, ON)
        wiringpi2.digitalWrite(M4, OFF)

    wiringpi2.digitalWrite(PWMA, ON)
    wiringpi2.digitalWrite(PWMB, ON)

    if TYPE == "front":
        front()
        time.sleep(settings.cell_lenght / settings.robot_speed)
    elif TYPE == "back":
        back()
        time.sleep(settings.cell_lenght / settings.robot_speed)
    elif TYPE == "left":
        left()
        time.sleep(angle * settings.time_full_left)
    elif TYPE == "right":
        right()
        time.sleep(angle * settings.time_full_right)
    else:
        pass

    stop()
    wiringpi2.digitalWrite(PWMA, OFF)
    wiringpi2.digitalWrite(PWMB, OFF)
Example #30
0
 def GPIOsetup(self, pinbase=0, ADDR=IO_ADDR):
     wiringpi2.wiringPiSetupPhys()
     if (pinbase != 0):
         wiringpi2.mcp23017Setup(pinbase, ADDR)
     for gpio in self.pins:
         wiringpi2.pinMode(gpio, OUT)
Example #31
0
 def GPIOsetup(self):
   wiringpi2.wiringPiSetupPhys()
   wiringpi2.softPwmCreate(PWM_PIN_ENA,ON_TIME1,RANGE)
   wiringpi2.softPwmCreate(PWM_PIN_ENB,ON_TIME2,RANGE)
   for gpio in self.pins:
     wiringpi2.pinMode(gpio,OUT)
Example #32
0
        print "Failed to set motors!"
        i2cFD.flush()


def turnRight():
    setMotors(150, -150)
    time.sleep(0.1)
    stop()
    time.sleep(0.1)


LeftTrack = 0
RightTrack = 0

# Configure wiring pi
wiringpi.wiringPiSetupPhys()
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_GPIO)

# Open the i2C connection
i2cConnect = wiringpi.wiringPiI2CSetup(I2CAddress)
i2cFD = os.fdopen(i2cConnect, "rw", 0)

# Configure the GPIO
io.pinMode(SR04Trigger, io.OUTPUT)
io.pinMode(SR04Echo, io.INPUT)

io.digitalWrite(SR04Trigger, False)


def getDistance():
    start = 0
Example #33
0
def setup():
    wiringpi.wiringPiSetupPhys()
    for pin in pinlist:
        wiringpi.pinMode(pin, OUTPUT)
    resetdisplay()