Example #1
0
def resetdisplay():
    wiringpi.digitalWrite(RST, LOW)
    wiringpi.delayMicroseconds(1)
    wiringpi.digitalWrite(RST, HIGH)
    wiringpi.delayMicroseconds(150)
    wiringpi.digitalWrite(A3, HIGH)
    return
Example #2
0
 def SendRawTimings(self, timings):
     self.enableTransmit()
     for i in range(0, len(timings) / 2):
         t1 = timings[i]
         t2 = timings[i + 1]
         self.__transmitRaw(t1, t2)
     self.disableTransmit()
     wiringpi.delayMicroseconds(250000)
Example #3
0
def delayUs(us):
    """   
       Delay specified number of microseconds

       Params:
           [in] us - number of microseconds to delay
    
    """
    wiringpi2.delayMicroseconds(us)
Example #4
0
def delayUs(us):
    """   
       Delay specified number of microseconds

       Params:
           [in] us - number of microseconds to delay
    
    """
    wiringpi2.delayMicroseconds(us)
Example #5
0
    def move(self, direction1, delay):
		if direction1==1:
			wiringpi2.digitalWrite(self.dirPin, 1);
		else:
			wiringpi2.digitalWrite(self.dirPin, 0);    
		wiringpi2.digitalWrite(self.stepPin,0)
		wiringpi2.delayMicroseconds(int(delay//2))
		wiringpi2.digitalWrite(self.stepPin,1)
		wiringpi2.delayMicroseconds(int(delay//2))
Example #6
0
def writeByte(data):
    GPIO.pinMode(DQ, OUT)
    for i in range(8):
        GPIO.digitalWrite(DQ, L)
        if data & (1 << i):
            GPIO.digitalWrite(DQ, H)
        else:
            GPIO.digitalWrite(DQ, L)
        GPIO.delayMicroseconds(30)
Example #7
0
 def move(self, direction1, delay):
     if direction1 == 1:
         wiringpi2.digitalWrite(self.dirPin, 1)
     else:
         wiringpi2.digitalWrite(self.dirPin, 0)
     wiringpi2.digitalWrite(self.stepPin, 0)
     wiringpi2.delayMicroseconds(int(delay // 2))
     wiringpi2.digitalWrite(self.stepPin, 1)
     wiringpi2.delayMicroseconds(int(delay // 2))
Example #8
0
def resetdisplay():
    # some code to reset
    wiringpi.digitalWrite(RST, LOW)
    wiringpi.delayMicroseconds(1)
    wiringpi.digitalWrite(RST, HIGH)
    wiringpi.delayMicroseconds(150)
    wiringpi.digitalWrite(A3, HIGH)
    wiringpi.digitalWrite(DSP0, LOW)
    wiringpi.digitalWrite(DSP1, LOW)
    return
Example #9
0
def clear(fd):
	type = False
	writeByte = 0x00          # display on, cursor on (blink)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delay(5)
	return
Example #10
0
	def run(self):
		while True:
			if self.stopped == 1:
				pass
			elif self.stopped == 0:
				wpi.digitalWrite(self.steering_pin, 1)
				wpi.delayMicroseconds(self.steering_pulse)
				wpi.digitalWrite(self.steering_pin, 0)
				wpi.delayMicroseconds(self.steering_frequency - self.steering_pulse)
			else:
				break
Example #11
0
	def run(self):
		while True:
			if self.stopped == 0:
				time.sleep(1)
			elif self.stopped == 1:
				pass
				wpi.digitalWrite(self.pin, 1)
				wpi.delayMicroseconds(self.pulse)
				wpi.digitalWrite(self.pin, 0)
				wpi.delayMicroseconds(self.frequency - self.pulse)
			else:
				break
def flashLights(number, freq, width, cycles):
    if not freq == 0:
        for i in range(0,cycles):
            a.digitalWrite(number,a.LOW)
	    t_ = time.time()
#            wp.delay( float(width/timescale) )
	    wp.delayMicroseconds( 1000*(width/timescale) )
            a.digitalWrite(number,a.HIGH)
	    t = time.time()
#	    wp.delay( float((1-width)/(timescale*freq)) )
	    wp.delayMicroseconds( 1000*(1000 - width)/(timescale*freq) )
	    print(t-t_)
Example #13
0
 def _send_bit(self, value):
     """
     Sends the given logical bit
     """
     wiringpi2.digitalWrite(self.pin, self._toggle_pin_value())
     if value:
         wiringpi2.delayMicroseconds(self._get_long_delta())
         self.duration += self._delta_long
     else:
         wiringpi2.delayMicroseconds(self._get_short_delta())
         self.duration += self._delta_short
     self.toggles += 1
Example #14
0
    def __transmit(self, HighPulses, LowPulses):
        disabled_Receive = False
        ReceiverInterrupt_backup = self.__ReceiverInterrupt
        if self.__TransmitterPin != -1:
            if self.__ReceiverInterrupt != -1:
                #self.disableReceive()
                disabled_Receive = True

            wiringpi.digitalWrite(self.__TransmitterPin, HIGH)
            wiringpi.delayMicroseconds(self.__PulseLength * HighPulses)

            wiringpi.digitalWrite(self.__TransmitterPin, LOW)
            wiringpi.delayMicroseconds(self.__PulseLength * LowPulses)
Example #15
0
    def StartPolling(self):
        __rxstate = -1
        #print('polling started on pin %i' % self.__ReceiverInterrupt)
        while self.__ReceiverInterrupt != -1:

            wiringpi.delayMicroseconds(1)

            r = wiringpi.digitalRead(self.__ReceiverInterrupt)
            if r == 0: self.string += '_'
            elif r == 1: self.string += '-'
            if r != __rxstate:
                self.handleInterrupt()
                __rxstate = r
Example #16
0
    def __transmitRaw(self, timeH, timeL):
        disabled_Receive = False
        ReceiverInterrupt_backup = self.__ReceiverInterrupt
        if self.__TransmitterPin != -1:
            if self.__ReceiverInterrupt != -1:
                #self.disableReceive()
                disabled_Receive = True

            wiringpi.digitalWrite(self.__TransmitterPin, HIGH)
            wiringpi.delayMicroseconds(int(timeH))

            wiringpi.digitalWrite(self.__TransmitterPin, LOW)
            wiringpi.delayMicroseconds(int(timeL))
Example #17
0
    def _getStart(self):
        lastw = 0xffff
        while (True):
            w = self.link.getWord()
            if w == 0 and lastw == 0:
                wiringpi2.delayMicroseconds(10)
                return False
            elif w == PIXY_START_WORD and lastw == PIXY_START_WORD:
                return True
            elif w == PIXY_START_WORDX:
                logging.debug("reorder")
                self.link.getByte() # resync

            lastw = w
Example #18
0
def readData(pin):
    hum = 0
    temp = 0
    crc = 0
    GPIO.pinMode(pin, 1)
    GPIO.digitalWrite(pin, 1)
    GPIO.digitalWrite(pin, 0)
    GPIO.delay(20)
    GPIO.digitalWrite(pin, 1)
    GPIO.pinMode(pin, 0)
    GPIO.delayMicroseconds(40)
    if GPIO.digitalRead(pin) == 0:
        untilHigh(pin)
        for i in range(16):
            hum <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            hum += GPIO.digitalRead(pin)
        for i in range(16):
            temp <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            temp += GPIO.digitalRead(pin)
        for i in range(8):
            crc <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            crc += GPIO.digitalRead(pin)
        return [True, hum, temp, crc]
    else:
        return [False, hum, temp, crc]
Example #19
0
    def _getStart(self):
        lastw = 0xffff
        while (True):
            w = self.link.getWord()
            if w == 0 and lastw == 0:
                wiringpi2.delayMicroseconds(10)
                return False
            elif w == PIXY_START_WORD and lastw == PIXY_START_WORD:
                return True
            elif w == PIXY_START_WORDX:
                logging.debug("reorder")
                self.link.getByte()  # resync

            lastw = w
Example #20
0
def readByte():
    data = 0
    for i in range(8):
        GPIO.pinMode(DQ, OUT)
        GPIO.digitalWrite(DQ, L)
        GPIO.digitalWrite(DQ, H)
        GPIO.pinMode(DQ, IN)
        GPIO.delayMicroseconds(15)
        if GPIO.digitalRead(DQ) == H:
            data |= (1 << i)
        else:
            data &= ~(1 << i)
        GPIO.delayMicroseconds(30)
    return data
Example #21
0
def readData(pin):
    hum = 0
    temp = 0
    crc = 0
    GPIO.pinMode(pin, 1)
    GPIO.digitalWrite(pin, 1)
    GPIO.digitalWrite(pin, 0)
    GPIO.delay(20)
    GPIO.digitalWrite(pin, 1)
    GPIO.pinMode(pin, 0)
    GPIO.delayMicroseconds(40)
    if GPIO.digitalRead(pin) == 0:
        untilHigh(pin)
        for i in range(16):
            hum <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            hum += GPIO.digitalRead(pin)
        for i in range(16):
            temp <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            temp += GPIO.digitalRead(pin)
        for i in range(8):
            crc <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            crc += GPIO.digitalRead(pin)
        return [True, hum, temp, crc]
    else:
        return [False, hum, temp, crc]
Example #22
0
 def mt(self, target_pitch, m_speed):
     self.port.write("#AVL" + repr(m_speed) + "\r\n")
     io1.delayMicroseconds(8000)
     self.port.write("#ATA" + repr(target_pitch) + "\r\n")
     io1.delayMicroseconds(8000)
     self.port.write("#AVL" + self.speed + "\r\n")
     self.port.flush()
     #while True:    
     #    self.port.write("#AMS\r\n")
     #    rcv=self.readline(self.port)
     #    print rcv
     #    if rcv == "*AMS0\r\n":
     #        print "Table Move OK"
             #self.port.write("#AVL64000\r\n")
     return True
Example #23
0
 def t_zero(self, offset_len):
     #self.port.write("#ASL2\r\n")
     #io1.delayMicroseconds(1000)
     self.port.write("#AOS-1\r\n")
     io1.delayMicroseconds(1000000)
     while True:    
         self.port.write("#AMS\r\n")
         rcv=self.readline(self.port)
         print rcv
         if rcv == "*AMS0\r\n":
             break
     self.port.write("#APM" + repr(offset_len) + "\r\n")
     
     while True:    
         self.port.write("#AMS\r\n")
         io1.delayMicroseconds(9000)
         rcv=self.readline(self.port)
         print rcv
         if rcv == "*AMS0\r\n":
             break 
     self.port.write("#AZP\r\n")
     io1.delayMicroseconds(1000)
     #self.port.write("#ASL1\r\n")
     self.port.flush()
     print "String Zero OK"
     return True
def dSPIN_Xfer(data):
    wp.digitalWrite(hd.dSPIN_CS, wp.GPIO.LOW);

    for i in range(8):
        wp.digitalWrite(hd.dSPIN_CLK, wp.GPIO.LOW);

        if(data & 0x80):
            wp.digitalWrite(hd.dSPIN_MOSI, wp.GPIO.HIGH);
        else:
            wp.digitalWrite(hd.dSPIN_MOSI, wp.GPIO.LOW);
        wp.delayMicroseconds( hd.dSPIN_SPI_CLOCK_DELAY);

        data <<= 1;

        if(wp.digitalRead(hd.dSPIN_MISO)):
            data |= 1;

        wp.digitalWrite(hd.dSPIN_CLK, wp.GPIO.HIGH);

        wp.delayMicroseconds( hd.dSPIN_SPI_CLOCK_DELAY);

    wp.digitalWrite(hd.dSPIN_CS, wp.GPIO.HIGH);
    wp.delayMicroseconds( hd.dSPIN_SPI_CLOCK_DELAY );

    return data
Example #25
0
	def turn(turnangle,self):
		countTurns = 0 #keep
		angle = Compass.getAngle() #keep
		goal = angle + turnangle #keep
		if turnangle < 0 #keep
			turnspeed = 1300 #keep
		else #keep
			turnspeed = 1500 #keep
		#Start Turning
		TurnCounter.start()#PhotoInterrupter Counter
		wpi.digitalWrite(1,1)#S1
		wpi.delayMicroseconds(turnspeed)
		wpi.digitalWrite(1,0)
		#Turn robot until angle reaches goal to 10% error
		while True:
			if angle >= (0.95)*goal and angle <= (1.05)*goal
				countTurns = PhotoIntA.getCount()
				reset()
				break
			#overshoot checking
			if angle > goal and turnangle > 0
				#change direction
				wpi.digitalWrite(1,1)#S1
				wpi.delayMicroseconds(turnspeed-200)
				wpi.digitalWrite(1,0)
			if angle < goal and turnangle < 0
				#change direction
				wpi.digitalWrite(1,1)#S1
				wpi.delayMicroseconds(turnspeed+200)
				wpi.digitalWrite(1,0)
			angle = Compass.getAngle()
Example #26
0
    def gh(self, direction, rpm, offset_rev, ps_pin):
#------------------------------------------------------------------------
#set speed control variables
#------------------------------------------------------------------------
        rpm=float(rpm)
        offset_rev=float(offset_rev)
        peak_WaitTime = int(1000000 / (rpm / 60 * self.steps_per_rev) - 8)
        direction = int(direction)
        offset_steps = int(offset_rev * self.steps_per_rev)
#------------------------------------------------------------------------
#set speed control variables
#------------------------------------------------------------------------
        self.ps_pin = int(ps_pin)
        io1.pinMode(self.ps_pin,0)
#------------------------------------------------------------------------
#Set direction of rotation
#------------------------------------------------------------------------
        if direction == -1:
            io1.digitalWrite(self.d_pin,0)
        elif direction == 1:
            io1.digitalWrite(self.d_pin,1)
#------------------------------------------------------------------------

#------------------------------------------------------------------------
#Zero Step Counter
#------------------------------------------------------------------------
        StepCounter = 0
#------------------------------------------------------------------------

#------------------------------------------------------------------------
#Turn the motor by send pulse
#------------------------------------------------------------------------
        # Start offset loop
        while io1.digitalRead(self.ps_pin):
            io1.digitalWrite(self.p_pin,0)
            io1.delayMicroseconds(peak_WaitTime)        
            io1.digitalWrite(self.p_pin,1)
            StepCounter += 1
        io1.delayMicroseconds(50)
        
        if direction == -1:
            io1.digitalWrite(self.d_pin,1)
        elif direction == 1:
            io1.digitalWrite(self.d_pin,0)

        # Start offset loop        
        StepCounter = 0
        while StepCounter < offset_steps:
            io1.digitalWrite(self.p_pin,0)
            io1.delayMicroseconds(peak_WaitTime)        
            io1.digitalWrite(self.p_pin,1)
            StepCounter += 1

        StepCounter = 0
        self.motor_address = 0
        return True
Example #27
0
def init18b20():
    GPIO.pinMode(DQ, OUT)
    GPIO.digitalWrite(DQ, H)
    GPIO.digitalWrite(DQ, L)
    GPIO.delayMicroseconds(480)  # 480-960(us)
    GPIO.pinMode(DQ, IN)
    GPIO.delayMicroseconds(30)  # 15-60(us)
    while True:
        if GPIO.digitalRead(DQ) == H:
            break
    GPIO.delayMicroseconds(150)  # 60-240(us)
    GPIO.digitalWrite(DQ, H)
Example #28
0
def LCD8bit(writeByte, type, fd):	
	writeByte = writeByte>>4#clear the lower nibble since it isn't used
	writeByte = writeByte<<4
	if(type):
		value = 4 #set bit 2
		writeByte = writeByte|value# set CD to 1 for data (bit2)

	  #=====================================================write
	wp.wiringPiI2CWriteReg8(fd, reg, writeByte)

	wp.delayMicroseconds(10)

	value = 8
	writeByte = writeByte|value #pulse enable pin (bit3)
	wp.wiringPiI2CWriteReg8(fd, reg, writeByte)

	wp.delayMicroseconds(10)

	writeByte = writeByte^value#clear enable pin	
	wp.wiringPiI2CWriteReg8(fd, reg, writeByte)

	wp.delayMicroseconds(10)
	return
    def __send_telegram(self, telegram):
        wait = 375
        data = 0
        for i in range(0, 12):
            data <<= 2
            data |= telegram % 3
            telegram /= 3

        for i in range(0, self.repeats):
            repeatData = data
            for j in range(0, 12):
                test = repeatData & 3
                if test == 0:
                    wiringpi2.digitalWrite(self.pin, 1)
                    wiringpi2.delayMicroseconds(wait)
                    wiringpi2.digitalWrite(self.pin, 0)
                    wiringpi2.delayMicroseconds(wait * 3)
                    wiringpi2.digitalWrite(self.pin, 1)
                    wiringpi2.delayMicroseconds(wait)
                    wiringpi2.digitalWrite(self.pin, 0)
                    wiringpi2.delayMicroseconds(wait * 3)
                elif test == 1:
                    wiringpi2.digitalWrite(self.pin, 1)
                    wiringpi2.delayMicroseconds(wait * 3)
                    wiringpi2.digitalWrite(self.pin, 0)
                    wiringpi2.delayMicroseconds(wait)
                    wiringpi2.digitalWrite(self.pin, 1)
                    wiringpi2.delayMicroseconds(wait * 3)
                    wiringpi2.digitalWrite(self.pin, 0)
                    wiringpi2.delayMicroseconds(wait)
                elif test == 2:
                    wiringpi2.digitalWrite(self.pin, 1)
                    wiringpi2.delayMicroseconds(wait)
                    wiringpi2.digitalWrite(self.pin, 0)
                    wiringpi2.delayMicroseconds(wait * 3)
                    wiringpi2.digitalWrite(self.pin, 1)
                    wiringpi2.delayMicroseconds(wait * 3)
                    wiringpi2.digitalWrite(self.pin, 0)
                    wiringpi2.delayMicroseconds(wait)

                repeatData >>= 2

            wiringpi2.digitalWrite(self.pin, True)
            wiringpi2.delayMicroseconds(wait)
            wiringpi2.digitalWrite(self.pin, False)
            wiringpi2.delayMicroseconds(wait * 31)
    def __send_telegram(self, telegram):
        wait = 375
        data = 0
        for i in range(0, 12):
            data <<= 2
            data |= telegram % 3
            telegram /= 3

        for i in range(0, self.repeats):
            repeatData = data
            for j in range(0, 12):
                test = repeatData & 3
                if test == 0:
                    wiringpi2.digitalWrite(self.pin, 1)
                    wiringpi2.delayMicroseconds(wait)
                    wiringpi2.digitalWrite(self.pin, 0)
                    wiringpi2.delayMicroseconds(wait * 3)
                    wiringpi2.digitalWrite(self.pin, 1)
                    wiringpi2.delayMicroseconds(wait)
                    wiringpi2.digitalWrite(self.pin, 0)
                    wiringpi2.delayMicroseconds(wait * 3)
                elif test == 1:
                    wiringpi2.digitalWrite(self.pin, 1)
                    wiringpi2.delayMicroseconds(wait * 3)
                    wiringpi2.digitalWrite(self.pin, 0)
                    wiringpi2.delayMicroseconds(wait)
                    wiringpi2.digitalWrite(self.pin, 1)
                    wiringpi2.delayMicroseconds(wait * 3)
                    wiringpi2.digitalWrite(self.pin, 0)
                    wiringpi2.delayMicroseconds(wait)
                elif test == 2:
                    wiringpi2.digitalWrite(self.pin, 1)
                    wiringpi2.delayMicroseconds(wait)
                    wiringpi2.digitalWrite(self.pin, 0)
                    wiringpi2.delayMicroseconds(wait * 3)
                    wiringpi2.digitalWrite(self.pin, 1)
                    wiringpi2.delayMicroseconds(wait * 3)
                    wiringpi2.digitalWrite(self.pin, 0)
                    wiringpi2.delayMicroseconds(wait)

                repeatData >>= 2

            wiringpi2.digitalWrite(self.pin, True)
            wiringpi2.delayMicroseconds(wait)
            wiringpi2.digitalWrite(self.pin, False)
            wiringpi2.delayMicroseconds(wait * 31)
Example #31
0
def signal(pin, time):
	wpi.digitalWrite(pin, 1)
	wpi.delayMicroseconds(time)
	wpi.digitalWrite(pin, 0)
Example #32
0
def write(writeByte, type, fd):

	#===============================extract upper nibble
	value = writeByte
	#clear the lower nibble
	value = value>>4
	value = value<<4
	#place in register
	upperNibble = value
	#==================================extract lower nibble
	value = writeByte
	#move the lower nibble to the upper nibble
	value = value<<4
	#place in register
	lowerNibble = value


	if(type):
		value = 4 #set bit 2
		upperNibble = upperNibble|value# set CD to 1 for data (bit2)
		lowerNibble = lowerNibble|value
	#else CD is 0 for a command



	#=====================================================write upperNibble
	wp.wiringPiI2CWriteReg8(fd, reg, upperNibble)

	wp.delayMicroseconds(10)

	value = 8
	upperNibble = upperNibble|value #pulse enable pin (bit3)
	wp.wiringPiI2CWriteReg8(fd, reg, upperNibble)

	wp.delayMicroseconds(10)

	upperNibble = upperNibble^value#clear enable pin

	wp.wiringPiI2CWriteReg8(fd, reg, upperNibble)

	wp.delayMicroseconds(10)
	#=====================================================write lowerNibble
	wp.wiringPiI2CWriteReg8(fd, reg, lowerNibble)

	wp.delayMicroseconds(10)

	value = 8
	lowerNibble = lowerNibble|value #pulse enable pin (bit3)
	wp.wiringPiI2CWriteReg8(fd, reg, lowerNibble)

	wp.delayMicroseconds(10)

	lowerNibble = lowerNibble^value#clear enable pin	
	wp.wiringPiI2CWriteReg8(fd, reg, lowerNibble)

	wp.delayMicroseconds(10)

	return
Example #33
0
def reset(fd):
	type = False
	
	writeByte = 0x30 # 1100 0000

	LCD8bit(writeByte, type, fd)
	wp.delay(5)  

	LCD8bit(writeByte, type, fd) 
	wp.delayMicroseconds(110)

	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(50)

	writeByte = 0x20 #0100 0000

	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(50)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(50)

	writeByte = 0x80                # sets up device to 2 lines5x7 pixel chars, 1/8 duty cycle
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)
	#============================= can switch to 4 bit
	writeByte = 0x00          # display on, cursor on (blink)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0xF0
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)
	writeByte = 0x40
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x00          # display on, cursor on (blink)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delay(5)

	writeByte = 0x40
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)  

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x00          # display on, cursor on (blink)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delay(5)
		
	return
Example #34
0
def init():
	fd = wp.wiringPiI2CSetup(0x38)
	type = False

	if(fd==3):
		print "I2C device initialized \n"
	wp.delay(110)

	writeByte = 0x30 # 1100 0000

	LCD8bit(writeByte, type, fd)
	wp.delay(5)  

	LCD8bit(writeByte, type, fd) 
	wp.delayMicroseconds(110)

	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(50)

	writeByte = 0x20 #0100 0000

	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(50)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(50)

	writeByte = 0x80                # sets up device to 2 lines5x7 pixel chars, 1/8 duty cycle
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)
	#============================= can switch to 4 bit
	writeByte = 0x00          # display on, cursor on (blink)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0xF0
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)
	writeByte = 0x40
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x00          # display on, cursor on (blink)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delay(5)

	writeByte = 0x40
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)  

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x00          # display on, cursor on (blink)
	LCD8bit(writeByte, type, fd)
	wp.delayMicroseconds(100)

	writeByte = 0x10
	LCD8bit(writeByte, type, fd)
	wp.delay(5)
		
	return fd
Example #35
0
	def stop(self):
		wpi.digitalWrite(1,1)#S1
		wpi.digitalWrite(2,1)#S2
		wpi.delayMicroseconds(1400)#stop pulse width
		wpi.digitalWrite(1,0)
		wpi.digitalWrite(2,0)
Example #36
0
    def rotate(self, direction, laps, rpm, at, dt):
#------------------------------------------------------------------------
#set counter and speed control variables
#------------------------------------------------------------------------
        steps = int(float(laps) * self.steps_per_rev) 
        rpm=float(rpm)
        at=float(at)
        dt=float(dt) 
        direction = int(direction)
        at_steps=int(steps*(at/100))
        dt_steps=int(steps*(dt/100))
        peak_steps=steps - at_steps - dt_steps
        at_WaitTime = int(1000000 / self.steps_per_rev - 8)  #waitTime controls speed
        peak_WaitTime = int(1000000 / (rpm / 60 * self.steps_per_rev) - 8)
        time_Range = (at_WaitTime - peak_WaitTime)
        time_Split = (1 + time_Range) * time_Range / 2 
        at_split_point = int(at_steps / time_Split )
        dt_split_point = int(dt_steps / time_Range )
#------------------------------------------------------------------------
#Set direction of rotation
#------------------------------------------------------------------------
        if direction == -1:
            io1.digitalWrite(self.d_pin,0)
        elif direction == 1:
            io1.digitalWrite(self.d_pin,1)
#------------------------------------------------------------------------

#------------------------------------------------------------------------
#Zero Step Counter
#------------------------------------------------------------------------
        StepCounter = 0
        split_Counter = 0
#------------------------------------------------------------------------

#------------------------------------------------------------------------
#Turn the motor by send pulse
#------------------------------------------------------------------------
        split_Counter = at_split_point 
        adtCounter = 1
        # Start Acceleration loop
        while StepCounter < at_steps:
            #turning the gpio off and on tells the driver to take one step
            io1.digitalWrite(self.p_pin,0)
            if split_Counter == StepCounter:
                if at_WaitTime > peak_WaitTime:
                    at_WaitTime -= 1
                split_Counter = at_split_point * adtCounter + split_Counter 
                adtCounter += 1
            io1.delayMicroseconds(at_WaitTime)        
            io1.digitalWrite(self.p_pin,1)
            StepCounter += 1
        self.motor_address = self.motor_address + direction * StepCounter
        StepCounter = 0
        
        # Start peak loop        
        while StepCounter < peak_steps:
            #turning the gpio off and on tells the driver to take one step
            io1.digitalWrite(self.p_pin,0)
            io1.delayMicroseconds(peak_WaitTime)
            io1.digitalWrite(self.p_pin,1)
            StepCounter += 1
        self.motor_address = self.motor_address + direction * StepCounter
        StepCounter = 0
        
        adtCounter = dt_split_point
        # Start Deceleration loop
        while StepCounter < dt_steps:
            #turning the gpio off and on tells the driver to take one step
            io1.digitalWrite(self.p_pin,0)
            if adtCounter == StepCounter:
                at_WaitTime += 1
                adtCounter += dt_split_point
            io1.delayMicroseconds(at_WaitTime)
            io1.digitalWrite(self.p_pin,1)
            StepCounter += 1
        self.motor_address = self.motor_address + direction * StepCounter   
        print io1.micros()
Example #37
0
 def _transmit(self, high_pulses, low_pulses):
     wiringpi2.digitalWrite(self._pin, wiringpi2.GPIO.HIGH)
     wiringpi2.delayMicroseconds(self._nPulseLength * high_pulses)
     wiringpi2.digitalWrite(self._pin, wiringpi2.GPIO.LOW)
     wiringpi2.delayMicroseconds(self._nPulseLength * low_pulses)
Example #38
0
	def drive(self, drive_pulse):
		wpi.digitalWrite(self.drive_pin, 1)
		wpi.delayMicroseconds(drive_pulse)
		wpi.digitalWrite(self.drive_pin, 0)
Example #39
0
def signal(delay):
	wpi.digitalWrite(pins[0], 1)
	wpi.digitalWrite(pins[1], 1)
	wpi.delayMicroseconds(delay)
	wpi.digitalWrite(pins[0], 0)
	wpi.digitalWrite(pins[1], 0)
Example #40
0
def receive():
	# This will run in endless loop
	noErrors = True
	while(noErrors):
		# detecting low part
		while(GPIO.input(RX_PIN)):
			# keep reading till we found a 0	
			pass
		for i in range(MAXSYNC):
			if(GPIO.input(RX_PIN)):
				# i wasnt at the sync, lets leave
				noErrors = False
				break

			wiringpi2.delayMicroseconds(50)
		
		if(noErrors == False):
			noErrors = True
			continue

		while(GPIO.input(RX_PIN)==0):
			# keep reading till we found a 1
			pass

		# detecting high part
		for i in range(MAXSYNC):
			if(GPIO.input(RX_PIN)!=1):
				# i wasnt at the sync, lets leave
				noErrors = False
				break

			wiringpi2.delayMicroseconds(50)
		
		if(noErrors == False):
			noErrors = True
			continue

		while(GPIO.input(RX_PIN)==1):
			# keep reading till we leave the highpulse
			pass

		# sync found
		wiringpi2.delayMicroseconds(HIGHSYNC)

		# Read data
		message = 0
		for i in range(32):
		
			wiringpi2.delayMicroseconds(QUARTERWAVE)

			tempBit = GPIO.input(RX_PIN)

			while(GPIO.input(RX_PIN)==tempBit):
				# reading until change
				pass

			wiringpi2.delayMicroseconds(QUARTERWAVE)

			if(GPIO.input(RX_PIN)==tempBit):
				noErrors = False

			message = (message << 1) | tempBit

			wiringpi2.delayMicroseconds(QUARTERWAVE)
		
		if(noErrors == False):
			logger.debug("Error occured, continue...")
			noErrors = True
			continue

		logger.debug("Received Message: "+format(message, '08X'))
		logger.debug("Decoding...")

		# read temperatur nibbles
		t1 = getNibble(message,12)
		t2 = getNibble(message,16)
		t3 = getNibble(message,20)

		# calculating checksum and compare
		channelNibble = getNibble(message,24)
		rollingCodeNibble = getNibble(message,28)
		metaNibble = getNibble(message,8)

		byte1 = channelNibble << 4 | rollingCodeNibble
		byte2 = t2 << 4 | t3
		byte3 = metaNibble << 4 | t1

		checksumNibble1 = getNibble(message,4)
		checksumNibble2 = getNibble(message,0)

		checksum = checksumNibble2 << 4 | checksumNibble1

		tempResult = byte1 + byte2 + byte3
		tempResult = (tempResult & int('0x00ff',16)) + (tempResult >> 8)

		# i dont know why the checksum is always one more, as it should be...
		# TODO
		tempResult += 1

		if(tempResult != checksum):
			logger.debug("Checksum is wrong! Continue...")
			continue
			
		# decoding temperatur
		notNegative = getBit(message,10)
		temperatur = (t1*10.0)+t2+(t3/10.0)
	
		if(notNegative):
			temperatur = -1.0*temperatur
		
		# a7a6: 00 = Channel 1, 01 = Channel 2, 10 == Channel 3
		channel = getBit(message, 24)
		channel=(channel << 1) | getBit(message,25)
		channel+=1
	
		# o = ok, 1 = low
		lowBattery = getBit(message,8)
	
		# log to console
		logger.info("Datetime: "+time.strftime("%Y-%m-%d %H:%M:%S"))
		logger.info("Temperatur: "+str(temperatur)+" C")
		logger.info("Channel: "+str(channel))
		if(lowBattery):
			logger.info("Battery: LOW")
		else:
			logger.info("Battery: GOOD")

		# log to file
		fh = open(DATAFILE, 'a')
		fh.write(time.strftime("%Y-%m-%d %H:%M:%S")+","+str(temperatur)+","+str(lowBattery)+"\n")
Example #41
0
#!/usr/bin/python3

import wiringpi2 as wpi
import time

wpi.wiringPiSetup()

pins = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 21, 22, 23, 26, 27, 30, 31]

# GPIO pin setup
for x in pins:
	try:
		wpi.pinMode(x, 1)
		wpi.digitalWrite(x, 0)
		print("Pin #{0} set up".format(x))
	except:
		print("Pin  #{0} error".format(x))

print("done")
while True:
	wpi.digitalWrite(1, 0)
	wpi.delay(1)	# wait 1 millisecond
	wpi.digitalWrite(1, 1)
	wpi.delayMicroseconds(1000)	# wait 1 millisecond