Uncategorized

pca9685

fdsf

sdfsd

# pca9685_test59_2019aug0701 tlfong01 2019aug07hkt1613
# Rpi4B Raspbian 10 buster (Release 2019jul10), Python 3.7.3

# References

# / to continue, …

# *** Import ***

from time import sleep
from datetime import datetime
import inspect
import smbus

# ********************************************************************************
# ********************************************************************************

# *** Config ***

i2cCh0 = smbus.SMBus(1)

# ********************************************************************************
# ********************************************************************************

# *** Print Functions ***

def printStars():
print(‘\n********************************************************************************\n’)
return

def printBeginExecFunction():
printStars()
print(‘ Begin Execute Function’, inspect.stack()[1][3], ‘tlfong01’, str(datetime.now())[0:16])
return

def printEndExecFunction():
print(‘ End Execute Function’, inspect.stack()[1][3], ‘tlfong01’, str(datetime.now())[0:16])
printStars()
return

# *** Date Time Functions ***

def printDateTimeNow():
timeNowLong = datetime.now()
timeNowShort = str(timeNowLong)[0:16]
print(‘\n timeNowLong =’, timeNowLong)
print(‘ timeNowShort =’, timeNowShort)
return

def printElapsedTime():
startTime = datetime.now()
sleep(1.5)
finishTime = datetime.now()

timeElapsed = finishTime – startTime
secondsElapsed = timeElapsed.seconds
microSecondsElapsed = (secondsElapsed * 1000000) + timeElapsed.microseconds
milliSecondsElapsed = microSecondsElapsed / 1000

print(‘\n Start Time =’, startTime)
print(‘ Finish Time =’, finishTime)
secondsElapsed = timeElapsed.seconds
microSecondsElapsed = (secondsElapsed * 1000000) + timeElapsed.microseconds
milliSecondsElapsed = microSecondsElapsed / 1000

print(‘\n Start Time =’, startTime)
print(‘ Finish Time =’, finishTime)
print(‘\n timeElapsed =’, timeElapsed)
print(‘ microSecondsElapsed =’, microSecondsElapsed)
print(‘ milliSecondsElapsed =’, ‘%d’ %milliSecondsElapsed)
print(‘ secondsElapsed =’, secondsElapsed, ‘\n’)
return

def testDateTime():
printBeginExecFunction()
printDateTimeNow()
printElapsedTime()
printEndExecFunction()
return

# ********************************************************************************
# ********************************************************************************

# *** I2c Functions ***

# *** Read Write Print Device/Register Functions ***

def writeDevTwoBytes(i2cCh, devAddrByte, dataByte1, dataByte2):
i2cCh.write_byte_data(devAddrByte, dataByte1, dataByte2)
return

def readDevRegOneByte(i2cCh, devAddrByte, regAddrByte):
readByte = i2cCh.read_byte_data(devAddrByte, regAddrByte)
return readByte

def writeDevRegOneByte(i2cCh, devAddrByte, regAddrByte, writeByte):
writeDevTwoBytes(i2cCh, devAddrByte, regAddrByte, writeByte)
return

def printDevRegOneByte(i2cCh, devAddrByte, regAddrByte, printTitle):
readByte = readDevRegOneByte(i2cCh, devAddrByte, regAddrByte)
print(printTitle, hex(readByte))

# *** Test Functions ***

def testPingPca9685():
pingPca9685()
return

# ********************************************************************************
# ********************************************************************************

# *** PCA9685 ***

# *** Config ***

dvAddr0 = 0x40
dvAddr1 = 0x41
dvAddr2 = 0x42

allCallAddr = 0xe0
softResetAddr = 0x06

dvAddrList = [dvAddr0, dvAddr2, dvAddr2]

# *** dv config ***

dvTotal = 3
dvNumList = [i for i in range(dvTotal)]

pwmChTotal = 16
pwmChNumList = [i for i in range(pwmChTotal)]

# enablePwmOutputChNum = 15

fourLedRegNamesListList = [ [‘LedOnHigh0’, ‘LedOnLow0’, ‘LedOffHigh0’, ‘LedOffLow0’],
[‘LedOnHigh1’, ‘LedOnLow1’, ‘LedOffHigh1’, ‘LedOffLow1’],
[‘LedOnHigh2’, ‘LedOnLow2’, ‘LedOffHigh2’, ‘LedOffLow2’],
[‘LedOnHigh3’, ‘LedOnLow3’, ‘LedOffHigh3’, ‘LedOffLow3’],
[‘LedOnHigh4’, ‘LedOnLow4’, ‘LedOffHigh4’, ‘LedOffLow4’],
[‘LedOnHigh5’, ‘LedOnLow5’, ‘LedOffHigh5’, ‘LedOffLow5’],
[‘LedOnHigh6’, ‘LedOnLow6’, ‘LedOffHigh6’, ‘LedOffLow6’],
[‘LedOnHigh7’, ‘LedOnLow7’, ‘LedOffHigh7’, ‘LedOffLow7’],
[‘LedOnHigh8’, ‘LedOnLow8’, ‘LedOffHigh8’, ‘LedOffLow8’],
[‘LedOnHigh9’, ‘LedOnLow9’, ‘LedOffHigh9’, ‘LedOffLow9’],
[‘LedOnHigh10’, ‘LedOnLow10’, ‘LedOffHigh10’, ‘LedOffLow10’],
[‘LedOnHigh11’, ‘LedOnLow11’, ‘LedOffHigh11’, ‘LedOffLow11’],
[‘LedOnHigh12’, ‘LedOnLow12’, ‘LedOffHigh12’, ‘LedOffLow12’],
[‘LedOnHigh13’, ‘LedOnLow13’, ‘LedOffHigh13’, ‘LedOffLow13’],
[‘LedOnHigh14’, ‘LedOnLow14’, ‘LedOffHigh14’, ‘LedOffLow14’],
[‘LedOnHigh15’, ‘LedOnLow15’, ‘LedOffHigh15’, ‘LedOffLow15’],
]

# *** Test Functions ***

def pingPca9685():
# Function: Read and print PCA9685 register MODE1, addr = 0x00, default contents = 0x11
# Results : Print MOD1 register addr and contents
# Error : I2C wiring problem = OSError: [Errno 121] Remote I/O error

printBeginExecFunction()

i2cCh = i2cCh0
devAddrByte = 0x40
regAddrByte = 0x00

readByte = readDevRegOneByte(i2cCh, devAddrByte, regAddrByte)

print(‘\n PCA9685 I2C Address =’, hex(devAddrByte))
print(‘ PCA9685 MODE1 Register Contents =’, hex(readByte), ‘\n’)

printEndExecFunction()
return

def testPca9685Basic():
printBeginExecFunction()
printEndExecFunction()
return

# ********************************************************************************
# ********************************************************************************

# *** Main/Init/Test Functions ***

#*** Main Function ***

def main():
init()
test()
return

# *** Init Function ***

def init():
pass
return

# *** Test Function ***

def test():
# testDateTime()
testPingPca9685()
testPca9685Basic()
return

# ********************************************************************************
# ********************************************************************************

# *** Main ***

if __name__ == ‘__main__’:
main()

# *** End of Program ***

”’
********************************************************************************

*** Begin Sample output ***

/ to continue,…

*** End Sample output ****

********************************************************************************

”’


sdfsd

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s