Pages

Friday, May 31, 2013

GPi moving 1 to 4 motors at the same time

Now I am thinking of moving 4 motors at the same time.  Therefore I need some sort of state vector to keep an eye of the motor windings activation pattern.





# ftguzuntypi.py v1.4 tlfong01 2013may31

# *****************************************************************************
# Module - ftguzuntypi.py
# Description - Stepping motor, LED driver 
# *****************************************************************************

# *****************************************************************************
# Imports
# *****************************************************************************

import time
import spidev
from subprocess import call

import ftspi
import ftprint

# *****************************************************************************
# Guzunty Pi test functions
# *****************************************************************************

# *****************************************************************************
# Function - Stepping motor
# Description - 
# P1 pin assignment ***
#   P1-01 = Winding 1 (A-)
#   P1-02 = Winding 2 (A+)
#   P1-03 = Winding 3 (B-)
#   P1-04 = Winding 4 (B+) 
# Activation sequences
#   WaveSequence = [1, 3, 2, 4]
#   FullStepSequence =  [[1, 3], [1, 4], [2, 4], [2, 3]]
#   HalfStepSequence =  [[1], [1,4], [4], [2,4], [2], [2,3], [3]] 
# Unipolar Stepping Motor Switching Sequence 
#   Wave sequence = 1 - 3 - 2 - 4 (A-, B-, A+, B+)
#   Full step sequence = 13 - 14 - 24 - 23 (A-B-, A-B+, A+B+, A+B-)
#   Half step sequence  = 13 - 1 - 14 - 4 - 24 - 2 - 23 - 3 
#   One step swing = 1 - 3 - 1 - 3 (A-, B-, A-, B-)
# Motor windings list
#   Winding        A-(1)    A+(2)    B-(3)   B+(4)    COM (+5V)
#   28BYJ48        Pink     Orange   Blue    Yellow   Red  
#   NPM PF35       Black    Yellow   Brown   Orange   Red
#   PX245          Black    Green    Blue    Red      Yelow/White
# BYJ series geared step motor - 28byj48-12-300-01
#   Rated voltage - 12V
#   Number of phases - 2
#   Resistance per phase 300R
#   Gear reduction ratio - 1:64
#   Step angle - 5.625 degree /64 ??? or / 48
#   Pull-in torque at 500pps - >= 300 gm
#   Pull-in rate - >= 500 pps
#   Detent torque - >= 350
#   Noise - <= 35dB
# Sample call - 
# ftguzuntypi.TestSteppingMotor(stepSequence = ftquzuntypi.Wave,  
#                               stepAngle = ftguzuntyopi.Byj48stepAngle,
#                               stepTime = ftguzuntypi.milliseconds50,
#                               direction = ftguzuntypi.CounterClockwise,  
#        degrees = 45)
#  TestSteppingMotor(activationSequence =  [0x1, 0x2, 0x4, 0x8], stepCount = 50, stepTime = 1)
# *****************************************************************************

Wave = [0x1, 0x4, 0x2, 0x8]
WaveClockwise = [0x1, 0x4, 0x2, 0x8]
WaveCounterClockwise = list.reverse(WaveClockwise)
Clockwise = 0
CounterClockwise = 1
MilliSeconds50 = 0.05
Byj48stepAngle = 5.625 
MotorStateListInit = [0x0f, 0x0f, 0x0f, 0x0f]
MotorStateWordInit = 0xffff

def MoveStepMotor(motorStateList, motorNumber, stepSequence, stepAngle, stepTime, direction, angularDistance):

    ftprint.PrintDoubleSpaceLine("*** Start testing stepping motor N ***")    

    print "Motor state list = ", hex(motorStateList[0]), hex(motorStateList[1]), hex(motorStateList[2]), hex(motorStateList[3])
    print "Motor number = ", motorNumber
    print "Step sequence = ", stepSequence
    print "Step angle = ", stepAngle
    print "Step time = ", stepTime
    print "Direction = ", direction
    print "Angular distance = ", angularDistance

    print "Motor state word = ", hex(MotorStateWordInit)  

    spiChannel = spidev.SpiDev() 
    spiChannel.open(0, 0)           

    if (direction == Clockwise):
        stepSequence == list.reverse(stepSequence)

    print "Step sequence = ", stepSequence[0], stepSequence[1], stepSequence[2], stepSequence[3]

    spiChannel.close() 

    ftprint.PrintDoubleSpaceLine("*** Stop testing stepping motor N ***")

    return motorStateList



*** Start Program - FongToy v1.4 tlfong01 2013may31 ***


*** Start testing stepping motor N ***

Motor state list =  0xf 0xf 0xf 0xf
Motor number =  1
Step sequence =  [1, 4, 2, 8]
Step angle =  5.625
Step time =  0.05
Direction =  1
Angular distance =  10
Motor state word =  0xffff
Step sequence =  1 4 2 8

*** Stop testing stepping motor N ***


*** Start testing stepping motor N ***

Motor state list =  0xf 0xf 0xf 0xf
Motor number =  1
Step sequence =  [1, 4, 2, 8]
Step angle =  5.625
Step time =  0.05
Direction =  0
Angular distance =  10
Motor state word =  0xffff
Step sequence =  8 2 4 1

*** Stop testing stepping motor N ***


*** Stop Program ***



def TestSteppingMotor(stepSequence, stepAngle, stepTime, direction, degrees):

    ftprint.PrintDoubleSpaceLine("*** Start testing stepping motor ***")    

    print "Step sequence = ", stepSequence
    print "Step angle = ", stepAngle
    print "Step time = ", stepTime
    print "Direction = ", direction
    print "Degrees = ", degrees

    spiChannel = spidev.SpiDev() 
    spiChannel.open(0, 0) 

    stepCount = int((degrees / stepAngle) * 32) # why not /64 ???

    if (direction == Clockwise):
        for i in range(stepCount * 4):
            for stepPattern in stepSequence:
                spiChannel.xfer2([stepPattern])
                time.sleep(stepTime)
    else:
        for i in range(stepCount * 4):
            for stepPattern in reversed(stepSequence):
                spiChannel.xfer2([stepPattern])
                time.sleep(stepTime)

    spiChannel.close() 

    ftprint.PrintDoubleSpaceLine("*** Stop testing stepping motor ***")


# *****************************************************************************
# Function - 
# Description - 
# Sample call -  
#   ftguzuntypi.TestGuzuntyPi4digit7segmentLedModule(spiChannelNumber = 0, spiChipEnableNumber = 1)
# Sample output -
#   *** Start Program - FongToy v1.0 tlfong01 2013may20  ***
#   Tue May 21 08:43:18 2013
#   Hour   digit 1 =  0
#   Hour   digit 2 =  8
#   Minute digit 1 =  4
#   Minute digit 2 =  3
#   Second digit 1 =  1
#   Second digit 2 =  8
#   hourDoubleDigit 0 =  0
#   hourDoubleDigit 1 =  8
#   minuteDoubleDigit 0 =  4
#   minuteDoubleDigit 1 =  3
#   secondDoubleDigit 0 =  1
#   secondDoubleDigit 1 =  8
#   hour =  0 8
#   minute =  4 3
#   second =  1 8
#   *** Stop Program ***
# ***************************************************************************** 

def SetRpiPin7GpClk0Frequency4688Hz():
    returnCode = call(["gpio mode 7 clock"], shell = True)
    returnCode = call("gpio clock 7 4688", shell=True)

def TestGuzuntyClock(spiChannel, secondCount):

    SetRpiPin7GpClk0Frequency4688Hz()

    # *** 7 segment patterns ***
    #PatternDigit0     = ~0x3f
    #PatternDigit1     = ~0x06
    #PatternDigit2     = ~0x5b
    #PatternDigit3     = ~0x4f
    #PatternSpace      = 0xff
    #PatternAllOn      = 0x00

    PatternBigG       = 0x3d
    PatternSmallG     = 0x6f
    PatternSmallO     = 0x5c
    PatternSmallD     = 0x5e

    PatternDigit0     = 0x3f
    PatternDigit1     = 0x06
    PatternDigit2     = 0x5b
    PatternDigit3     = 0x4f
    PatternSpace      = ~0xff
    PatternAllOn      = ~0x00

    PatternBigG       = 0x3d
    PatternSmallG     = 0x6f
    PatternSmallO     = 0x5c
    PatternSmallD     = 0x5e

    PatternListAllOff = [PatternSpace, PatternSpace, PatternSpace, PatternSpace]
    PatternListAllOn  = [PatternAllOn, PatternAllOn, PatternAllOn, PatternAllOn]
    PatternList0123   = [PatternDigit0, PatternDigit1, PatternDigit2, PatternDigit3]
    PatternListGood   = [PatternBigG, PatternSmallO, PatternSmallO, PatternSmallD]     
  
    # *** time digits ***
    timeString =  time.asctime(time.localtime(time.time()))
    print timeString

    print "Hour   digit 1 = ", timeString[11:12]
    print "Hour   digit 2 = ", timeString[12:13]
    print "Minute digit 1 = ", timeString[14:15]
    print "Minute digit 2 = ", timeString[15:16]
    print "Second digit 1 = ", timeString[17:18]
    print "Second digit 2 = ", timeString[18:19]

    hourDoubleDigit = [timeString[11:12], timeString[12:13]]
    print "hourDoubleDigit 0 = ", hourDoubleDigit[0]
    print "hourDoubleDigit 1 = ", hourDoubleDigit[1]

    minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
    print "minuteDoubleDigit 0 = ", minuteDoubleDigit[0]
    print "minuteDoubleDigit 1 = ", minuteDoubleDigit[1]

    secondDoubleDigit = [timeString[17:18], timeString[18:19]]
    print "secondDoubleDigit 0 = ", secondDoubleDigit[0]
    print "secondDoubleDigit 1 = ", secondDoubleDigit[1]

    timeHexDigit = [hourDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
    print "hour = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

    timeHexDigit = [minuteDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
    print "minute = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

    timeHexDigit = [secondDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
    print "second = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

    # *** 4 digit 7-segment LED displays ***    

    ftspi.SpiWrite(spiChannel, PatternListAllOff)
    time.sleep(0.5)

    ftspi.SpiWrite(spiChannel, PatternListAllOn)    
    time.sleep(0.5)

    ftspi.SpiWrite(spiChannel, PatternList0123)    
    time.sleep(1)

    ftspi.SpiWrite(spiChannel, PatternListGood)    
    time.sleep(1)

    # SevenSegmentPatternNumbers = [~0x3f, ~0x06, ~0x5b, ~0x4f, ~0x66, ~0x6d, ~0x7d, ~0x07, ~0x7f, ~0x6f]
    SevenSegmentPatternNumbers = [0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f]
    
    decimalPoint = 0

    for i in range(secondCount):

        print "Guzunty Clock second count = ", i
        timeString =  time.asctime(time.localtime(time.time()))

        hourDoubleDigit = [timeString[11:12], timeString[12:13]]
        minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
secondDoubleDigit = [timeString[17:18], timeString[18:19]]

        minuteDigit0 = SevenSegmentPatternNumbers[int(minuteDoubleDigit[0])]
        minuteDigit1 = SevenSegmentPatternNumbers[int(minuteDoubleDigit[1])]
        secondDigit0 = SevenSegmentPatternNumbers[int(secondDoubleDigit[0])]
        secondDigit1 = SevenSegmentPatternNumbers[int(secondDoubleDigit[1])]

        if (decimalPoint == 0):
   #minuteDigit1 &= ~0x80
   minuteDigit1 |= 0x80
   decimalPoint = 1
        else:
            decimalPoint = 0

        minuteSecondQuadDigitList = [minuteDigit0, minuteDigit1, secondDigit0, secondDigit1]        
ftspi.SpiWrite(spiChannel, minuteSecondQuadDigitList)            
time.sleep(1)

def TestGuzuntyPiLedDriver00(spiChannel, channelNumber, chipEnableNumber):

    SetRpiPin7GpClk0Frequency4688Hz()
    
    spiGuzuntyPi = spidev.SpiDev() 
    spiGuzuntyPi.open(0, 1)

    # *** 7 segment patterns ***
    #PatternDigit0     = ~0x3f
    #PatternDigit1     = ~0x06
    #PatternDigit2     = ~0x5b
    #PatternDigit3     = ~0x4f
    #PatternSpace      = 0xff
    #PatternAllOn      = 0x00

    PatternBigG       = 0x3d
    PatternSmallG     = 0x6f
    PatternSmallO     = 0x5c
    PatternSmallD     = 0x5e

    PatternDigit0     = 0x3f
    PatternDigit1     = 0x06
    PatternDigit2     = 0x5b
    PatternDigit3     = 0x4f
    PatternSpace      = ~0xff
    PatternAllOn      = ~0x00

    PatternBigG       = 0x3d
    PatternSmallG     = 0x6f
    PatternSmallO     = 0x5c
    PatternSmallD     = 0x5e

    PatternListAllOff = [PatternSpace, PatternSpace, PatternSpace, PatternSpace]
    PatternListAllOn  = [PatternAllOn, PatternAllOn, PatternAllOn, PatternAllOn]
    PatternList0123   = [PatternDigit0, PatternDigit1, PatternDigit2, PatternDigit3]
    PatternListGood   = [PatternBigG, PatternSmallO, PatternSmallO, PatternSmallD]     
  
    # *** time digits ***
    timeString =  time.asctime(time.localtime(time.time()))
    print timeString

    print "Hour   digit 1 = ", timeString[11:12]
    print "Hour   digit 2 = ", timeString[12:13]
    print "Minute digit 1 = ", timeString[14:15]
    print "Minute digit 2 = ", timeString[15:16]
    print "Second digit 1 = ", timeString[17:18]
    print "Second digit 2 = ", timeString[18:19]

    hourDoubleDigit = [timeString[11:12], timeString[12:13]]
    print "hourDoubleDigit 0 = ", hourDoubleDigit[0]
    print "hourDoubleDigit 1 = ", hourDoubleDigit[1]

    minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
    print "minuteDoubleDigit 0 = ", minuteDoubleDigit[0]
    print "minuteDoubleDigit 1 = ", minuteDoubleDigit[1]

    secondDoubleDigit = [timeString[17:18], timeString[18:19]]
    print "secondDoubleDigit 0 = ", secondDoubleDigit[0]
    print "secondDoubleDigit 1 = ", secondDoubleDigit[1]

    timeHexDigit = [hourDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
    print "hour = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

    timeHexDigit = [minuteDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
    print "minute = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

    timeHexDigit = [secondDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
    print "second = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

    # *** 4 digit 7-segment LED displays ***    

    spiGuzuntyPi.xfer2(PatternListAllOff)    
    time.sleep(1)

    spiGuzuntyPi.xfer2(PatternListAllOn)    
    time.sleep(1)

    spiGuzuntyPi.xfer2(PatternList0123)    
    time.sleep(2)

    spiGuzuntyPi.xfer2(PatternListGood)    
    time.sleep(2)

    # SevenSegmentPatternNumbers = [~0x3f, ~0x06, ~0x5b, ~0x4f, ~0x66, ~0x6d, ~0x7d, ~0x07, ~0x7f, ~0x6f]
    SevenSegmentPatternNumbers = [0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f]
    
    decimalPoint = 0

    for i in range(2):
        timeString =  time.asctime(time.localtime(time.time()))

        hourDoubleDigit = [timeString[11:12], timeString[12:13]]
        minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
secondDoubleDigit = [timeString[17:18], timeString[18:19]]

        minuteDigit0 = SevenSegmentPatternNumbers[int(minuteDoubleDigit[0])]
        minuteDigit1 = SevenSegmentPatternNumbers[int(minuteDoubleDigit[1])]
        secondDigit0 = SevenSegmentPatternNumbers[int(secondDoubleDigit[0])]
        secondDigit1 = SevenSegmentPatternNumbers[int(secondDoubleDigit[1])]

        if (decimalPoint == 0):
   #minuteDigit1 &= ~0x80
   minuteDigit1 |= 0x80
   decimalPoint = 1
        else:
            decimalPoint = 0

        minuteSecondQuadDigitList = [minuteDigit0, minuteDigit1, secondDigit0, secondDigit1]
        
spiGuzuntyPi.xfer2(minuteSecondQuadDigitList)    
        
time.sleep(1)


def TestGuzuntyPi4digit7segmentLedModule(spiChannelNumber, spiChipEnableNumber):

    spiChannel = spidev.SpiDev() 
    spiChannel.open(spiChannelNumber, spiChipEnableNumber)

    SetRpiPin7GpClk0Frequency4688Hz()

    # *** 7 segment patterns ***
    #PatternDigit0     = ~0x3f
    #PatternDigit1     = ~0x06
    #PatternDigit2     = ~0x5b
    #PatternDigit3     = ~0x4f
    #PatternSpace      = 0xff
    #PatternAllOn      = 0x00

    PatternBigG       = 0x3d
    PatternSmallG     = 0x6f
    PatternSmallO     = 0x5c
    PatternSmallD     = 0x5e

    PatternDigit0     = 0x3f
    PatternDigit1     = 0x06
    PatternDigit2     = 0x5b
    PatternDigit3     = 0x4f
    PatternSpace      = ~0xff
    PatternAllOn      = ~0x00

    PatternBigG       = 0x3d
    PatternSmallG     = 0x6f
    PatternSmallO     = 0x5c
    PatternSmallD     = 0x5e

    PatternListAllOff = [PatternSpace, PatternSpace, PatternSpace, PatternSpace]
    PatternListAllOn  = [PatternAllOn, PatternAllOn, PatternAllOn, PatternAllOn]
    PatternList0123   = [PatternDigit0, PatternDigit1, PatternDigit2, PatternDigit3]
    PatternListGood   = [PatternBigG, PatternSmallO, PatternSmallO, PatternSmallD]     
  
    # *** time digits ***
    timeString =  time.asctime(time.localtime(time.time()))
    print timeString

    print "Hour   digit 1 = ", timeString[11:12]
    print "Hour   digit 2 = ", timeString[12:13]
    print "Minute digit 1 = ", timeString[14:15]
    print "Minute digit 2 = ", timeString[15:16]
    print "Second digit 1 = ", timeString[17:18]
    print "Second digit 2 = ", timeString[18:19]

    hourDoubleDigit = [timeString[11:12], timeString[12:13]]
    print "hourDoubleDigit 0 = ", hourDoubleDigit[0]
    print "hourDoubleDigit 1 = ", hourDoubleDigit[1]

    minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
    print "minuteDoubleDigit 0 = ", minuteDoubleDigit[0]
    print "minuteDoubleDigit 1 = ", minuteDoubleDigit[1]

    secondDoubleDigit = [timeString[17:18], timeString[18:19]]
    print "secondDoubleDigit 0 = ", secondDoubleDigit[0]
    print "secondDoubleDigit 1 = ", secondDoubleDigit[1]

    timeHexDigit = [hourDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
    print "hour = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

    timeHexDigit = [minuteDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
    print "minute = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

    timeHexDigit = [secondDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
    print "second = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

    # *** 4 digit 7-segment LED displays ***    

#    spiGuzuntyPi.xfer2(PatternListAllOff)    
#    time.sleep(1)
#    spiGuzuntyPi.xfer2(PatternListAllOn)    
#    time.sleep(1)
#    spiGuzuntyPi.xfer2(PatternList0123)    
#    time.sleep(2)
#    spiGuzuntyPi.xfer2(PatternListGood)    
#    time.sleep(2)

    ftspi.SpiWrite(spiChannel, PatternListAllOff)
    time.sleep(1)

    ftspi.SpiWrite(spiChannel, PatternListAllOn)    
    time.sleep(1)

    ftspi.SpiWrite(spiChannel, PatternList0123)    
    time.sleep(2)

    ftspi.SpiWrite(spiChannel, PatternListGood)    
    time.sleep(2)

    # SevenSegmentPatternNumbers = [~0x3f, ~0x06, ~0x5b, ~0x4f, ~0x66, ~0x6d, ~0x7d, ~0x07, ~0x7f, ~0x6f]
    SevenSegmentPatternNumbers = [0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f]
    
    decimalPoint = 0

    for i in range(2):
        timeString =  time.asctime(time.localtime(time.time()))

        hourDoubleDigit = [timeString[11:12], timeString[12:13]]
        minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
secondDoubleDigit = [timeString[17:18], timeString[18:19]]

        minuteDigit0 = SevenSegmentPatternNumbers[int(minuteDoubleDigit[0])]
        minuteDigit1 = SevenSegmentPatternNumbers[int(minuteDoubleDigit[1])]
        secondDigit0 = SevenSegmentPatternNumbers[int(secondDoubleDigit[0])]
        secondDigit1 = SevenSegmentPatternNumbers[int(secondDoubleDigit[1])]

        if (decimalPoint == 0):
   #minuteDigit1 &= ~0x80
   minuteDigit1 |= 0x80
   decimalPoint = 1
        else:
            decimalPoint = 0

        minuteSecondQuadDigitList = [minuteDigit0, minuteDigit1, secondDigit0, secondDigit1]        
ftspi.SpiWrite(spiChannel, minuteSecondQuadDigitList)            
time.sleep(1)


def TestGuzuntyPiLedDriver00(spiChannel, channelNumber, chipEnableNumber):

    SetRpiPin7GpClk0Frequency4688Hz()
    
    spiGuzuntyPi = spidev.SpiDev() 
    spiGuzuntyPi.open(0, 1)

    # *** 7 segment patterns ***
    #PatternDigit0     = ~0x3f
    #PatternDigit1     = ~0x06
    #PatternDigit2     = ~0x5b
    #PatternDigit3     = ~0x4f
    #PatternSpace      = 0xff
    #PatternAllOn      = 0x00

    PatternBigG       = 0x3d
    PatternSmallG     = 0x6f
    PatternSmallO     = 0x5c
    PatternSmallD     = 0x5e

    PatternDigit0     = 0x3f
    PatternDigit1     = 0x06
    PatternDigit2     = 0x5b
    PatternDigit3     = 0x4f
    PatternSpace      = ~0xff
    PatternAllOn      = ~0x00

    PatternBigG       = 0x3d
    PatternSmallG     = 0x6f
    PatternSmallO     = 0x5c
    PatternSmallD     = 0x5e

    PatternListAllOff = [PatternSpace, PatternSpace, PatternSpace, PatternSpace]
    PatternListAllOn  = [PatternAllOn, PatternAllOn, PatternAllOn, PatternAllOn]
    PatternList0123   = [PatternDigit0, PatternDigit1, PatternDigit2, PatternDigit3]
    PatternListGood   = [PatternBigG, PatternSmallO, PatternSmallO, PatternSmallD]     
  
    # *** time digits ***
    timeString =  time.asctime(time.localtime(time.time()))
    print timeString

    print "Hour   digit 1 = ", timeString[11:12]
    print "Hour   digit 2 = ", timeString[12:13]
    print "Minute digit 1 = ", timeString[14:15]
    print "Minute digit 2 = ", timeString[15:16]
    print "Second digit 1 = ", timeString[17:18]
    print "Second digit 2 = ", timeString[18:19]

    hourDoubleDigit = [timeString[11:12], timeString[12:13]]
    print "hourDoubleDigit 0 = ", hourDoubleDigit[0]
    print "hourDoubleDigit 1 = ", hourDoubleDigit[1]

    minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
    print "minuteDoubleDigit 0 = ", minuteDoubleDigit[0]
    print "minuteDoubleDigit 1 = ", minuteDoubleDigit[1]

    secondDoubleDigit = [timeString[17:18], timeString[18:19]]
    print "secondDoubleDigit 0 = ", secondDoubleDigit[0]
    print "secondDoubleDigit 1 = ", secondDoubleDigit[1]

    timeHexDigit = [hourDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
    print "hour = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

    timeHexDigit = [minuteDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
    print "minute = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

    timeHexDigit = [secondDoubleDigit, minuteDoubleDigit, secondDoubleDigit]
    print "second = ", (timeHexDigit[0])[0], (timeHexDigit[0])[1]

    # *** 4 digit 7-segment LED displays ***    

    spiGuzuntyPi.xfer2(PatternListAllOff)    
    time.sleep(1)

    spiGuzuntyPi.xfer2(PatternListAllOn)    
    time.sleep(1)

    spiGuzuntyPi.xfer2(PatternList0123)    
    time.sleep(2)

    spiGuzuntyPi.xfer2(PatternListGood)    
    time.sleep(2)

    # SevenSegmentPatternNumbers = [~0x3f, ~0x06, ~0x5b, ~0x4f, ~0x66, ~0x6d, ~0x7d, ~0x07, ~0x7f, ~0x6f]
    SevenSegmentPatternNumbers = [0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f]
    
    decimalPoint = 0

    for i in range(2):
        timeString =  time.asctime(time.localtime(time.time()))

        hourDoubleDigit = [timeString[11:12], timeString[12:13]]
        minuteDoubleDigit = [timeString[14:15], timeString[15:16]]
secondDoubleDigit = [timeString[17:18], timeString[18:19]]

        minuteDigit0 = SevenSegmentPatternNumbers[int(minuteDoubleDigit[0])]
        minuteDigit1 = SevenSegmentPatternNumbers[int(minuteDoubleDigit[1])]
        secondDigit0 = SevenSegmentPatternNumbers[int(secondDoubleDigit[0])]
        secondDigit1 = SevenSegmentPatternNumbers[int(secondDoubleDigit[1])]

        if (decimalPoint == 0):
   #minuteDigit1 &= ~0x80
   minuteDigit1 |= 0x80
   decimalPoint = 1
        else:
            decimalPoint = 0

        minuteSecondQuadDigitList = [minuteDigit0, minuteDigit1, secondDigit0, secondDigit1]
        
spiGuzuntyPi.xfer2(minuteSecondQuadDigitList)    
        
time.sleep(1)

# .END

# fongtoy v1.4 tlfong01 2013may31

ProgramTitle = "FongToy v1.4 tlfong01 2013may31"

import sys 
import time 
import smbus 
import pdb 
import spidev 
import wiringpi
import wiringpi2
import RPIO as GPIO  
from RPIO import PWM 
from enum import Enum 
from subprocess import call

import ftgpio
import ftprint
import ftspi
import ftiox
import fteeprom
import ftguzuntypi
import ftdemux
import fttest
import ftadc

# *** Troubleshooting functions ***

# *** GPIO tests v1.3 tlfong01 2013may23 ***
# ftgpio.TestLed()
# ftgpio.TestBuzzer()
# ftgpio.TestButtonEchoBuzzer()
# ftgpio.TestButtonEchoLed()

# *** SPI Tests v1.3 tlfong01 2013may23 ***

# ftdemux.TestSelectSpiSlaveDevice(spiChannelNumber = 0, spiChipEnableNumber = 0, spiIoxSubAddress = 0, spiSlaveDeviceNumber = 5)
# fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 2, testStartAddress = 0x0123, testWriteDataByte = 0x5a)
# fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 1, testStartAddress = 0x0123, testWriteDataByte = 0x3b)
# fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 0, testStartAddress = 0x0123, testWriteDataByte = 0x3b)

# ftiox.TestMcp23s17BlinkLed(spiChannelNumber = 0, spiChipEnableNumber = 0, spiChipSubAddress = 0)
# ftdemux.TestSelectSpiSlaveDevice(spiChannelNumber = 0, spiChipEnableNumber = 0, spiIoxSubAddress = 0, spiSlaveDeviceNumber = 5)
# fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 0, testStartAddress = 0x0123, testWriteDataByte = 0x3b)
# fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 1, testStartAddress = 0x0411, testWriteDataByte = 0x4c)
# fttest.TestDemuxGuzuntyClock(mcp23s17SubAddress = 0, guzuntyClockDemuxAddress = 2, secondCount = 10)

# *** Main program ***

# *** Start program message ***
ftprint.StartProgram(ProgramTitle)

# *** Main tests ***

# *** SPI loop back ***
# ftspi.TestSpiLoopBackV01(spiChannelNumber = 0, spiChipEnableNumber = 1, testDataByte = 0x55, testTime = 0.001, testCount = 60000)

# *** ADC ***
# ftadc.TestMcp3208v03() 
# ftadc.TestMcp3201v04()

# *** EEPROM ***
# fteeprom.TestEeporm25Lc256v01(spiChannelNumber = 0, spiChipEnableNumber = 1, startAddress = 0x4100, testDataByte = 0x55)

# *** Mcp23s17 ***
# ftiox.TestMcp23s17BlinkLed(spiChannelNumber = 0, spiChipEnableNumber = 0, spiChipSubAddress = 0)

# *** Demux ***
# ftdemux.TestDemuxV01(spiChannelNumber = 0, spiChipEnableNumber = 0, spiIoxSubAddress = 0, spiSlaveDeviceNumber = 5)

# *** Guzunty Pi Step Motor ***

#ftguzuntypi.TestSteppingMotorN(motorNumber = 1,
#                               stepSequence = ftguzuntypi.Wave,  
#                               stepAngle = ftguzuntypi.Byj48stepAngle,
#                               stepTime = ftguzuntypi.MilliSeconds50,
#                               direction = ftguzuntypi.Clockwise,  
#                               degrees = 10)

#ftguzuntypi.TestSteppingMotorN(motorNumber = 0,
#                               stepSequence = ftguzuntypi.Wave,  
#                               stepAngle = ftguzuntypi.Byj48stepAngle,
#                               stepTime = ftguzuntypi.MilliSeconds50,
#                               direction = ftguzuntypi.CounterClockwise,  
#                               degrees = 10)

ftguzuntypi.MoveStepMotor(motorStateList = ftguzuntypi.MotorStateListInit,
                               motorNumber = 1,
                               stepSequence = ftguzuntypi.Wave,  
                               stepAngle = ftguzuntypi.Byj48stepAngle,
                               stepTime = ftguzuntypi.MilliSeconds50,
                               direction = ftguzuntypi.CounterClockwise,  
                               angularDistance = 10)

ftguzuntypi.MoveStepMotor(motorStateList = ftguzuntypi.MotorStateListInit,
                               motorNumber = 1,
                               stepSequence = ftguzuntypi.Wave,  
                               stepAngle = ftguzuntypi.Byj48stepAngle,
                               stepTime = ftguzuntypi.MilliSeconds50,
                               direction = ftguzuntypi.Clockwise,  
                               angularDistance = 10)

# *** Stop program message ***

ftprint.StopProgram()

#.END

.END

No comments:

Post a Comment