Uncategorized

dateTime = 2022apr06hkt1706

programName = ‘tmc2225test144.py’

========= ========= ========= ========= ========= ========= ========= =========

Contents

1. System Info/Config and References

2. Import Modules

3. System Utility Functions/Constants

4. Pico GPIO Functions

4.1 Pico GPConfig (GPIO, PWM, UART)

4.2 Pico GP Functions

5. Pico I2C Config/Test Funtions

5.1 I2C Device Detect Functions

6 Pico SPI config/test Functions

8.1 SPI loopback

7. Pico UART config/test functions

7.1 UART loopback

8. I2C Functions

9. PCF8574 Config/Test Functions

10. TB6612FNG Pico GPIO Controling Functions

11. TB6612FNG PCF8574 Controlling Functions

========= ========= ========= ========= ========= ========= ========= =========

xx. DS3231 RTC – 503

xx. TMC2225 Basic Test Functions

xx. L298N DC motor driver and M20 DC gear encoder motor

xx. Main Test Functions

========= ========= ========= ========= ========= ========= ========= =========

========= ========= ========= ========= ========= ========= ========= =========

========= ========= ========= ========= ========= ========= ========= =========

========= ========= ========= ========= ========= ========= ========= =========

========= ========= ========= ========= ========= ========= ========= =========

1. System Info/Config

Thonny 3.3.13, Windows 10 (64-bit), Python 3.7.9, Tk 8.6.9, MicropPython

(Raspberry Pi Pico), USB Port (COM3)

1.1. References

1.1.1 Python bytes concatenation – EESE 2015jan24

https://stackoverflow.com/questions/28130722/python-bytes-concatenation

1.1.2 Should I explain other people’s code? – Asked 2022feb21

https://meta.stackoverflow.com/questions/416114/should-i-explain-other-peoples-code?cb=1

========= ========= ========= ========= ========= ========= ========= =========

2. Import Modules

from machine import Pin, PWM, UART, SPI
import utime

import ubinascii, uhashlib

========= ========= ========= ========= ========= ========= ========= =========

3. System Functions/Constants

Repeat Times

once = 1
twice = 2
fourTimes = 4
eightTimes = 8
tenTimes = 10
oneHundredTimes = 100
fiveHundredTimes = 500
oneThousandTimes = 1000
tenThousandTimes = 10000
oneHundredThousandTimes = 100000
oneMillionTimes = 1000000
tenMillionTimes = 10000000

twoThousand = 2000
fiveThousand = 5000

Seconds Constants

quarterMilliSecond = 0.00025
halfMilliSecond = 0.0005
oneMilliSecond = 0.001
twoMilliSeconds = 0.002
oneTenthSecond = 0.1
quarterSecond = 0.25
halfSecond = 0.5
oneSecond = 1
twoSeconds = 2
fourSeconds = 4
oneMinute = 60
threeMinutes = 180

Frequency Constants ***

fiveHundredHz = 500
oneKHz = 1000
twoKHz = 2000
threeKHz = 3000
fourKHz = 4000
fiveKHz = 5000

Calander Time

monthNameDict = \
{‘Month’ : {‘1’: ‘jan’, ‘2’: ‘feb’, ‘3’: ‘mar’, ‘4’: ‘apr’, ‘5’: ‘may’, ‘6’ : ‘jun’, \
‘7’: ‘jul’, ‘8’: ‘aug’, ‘9’: ‘sep’, ’10’: ‘oct’, ’11’: ‘nov’, ’12’: ‘dec’},
}

timeNow = utime.localtime()

timeNowShort = str(timeNow[0]) + monthNameDict[‘Month’][str(timeNow[1])] + \
str(timeNow[2]) + ‘hkt’ + str(timeNow[3]) + ‘:’ + str(timeNow[4])

def printProgramName():
print(‘========= ‘ + ‘========= ‘ + ‘========= ‘ + ‘========= ‘ + ‘========= ‘ + ‘========= ‘ + ‘========= ‘ + ‘========= ‘)
print(‘* ‘, programName, timeNowShort, ‘*’)
print(‘========= ‘ + ‘========= ‘ + ‘========= ‘ + ‘========= ‘ + ‘========= ‘ + ‘========= ‘ + ‘========= ‘ + ‘========= ‘)
print(”)
return

printProgramName() # sample test <<<<<<<<<<

Time Functions ***

def pause(pauseTime):
utime.sleep(pauseTime)
return

def pauseSeconds(numberOfSeconds):
pause(numberOfSeconds)
return

========= ========= ========= ========= ========= ========= ========= =========

4. Pico GPIO Functions

*** Pico GP Pins Config ***

*** Pico GP Output Pin Assignment ***

gpOutPinNum25 = 25 # Pico System LED default, not need to initialize
gpOutPin25 = Pin(gpOutPinNum25, Pin.OUT)

gpOutPinNum20 = 20
gpOutPinNum21 = 21
gpOutPinNum22 = 22
gpOutPinNum26 = 26
gpOutPinNum27 = 27

gpOutPin20 = Pin(gpOutPinNum20, Pin.OUT)
gpOutPin21 = Pin(gpOutPinNum21, Pin.OUT)
gpOutPin22 = Pin(gpOutPinNum22, Pin.OUT)
gpOutPin26 = Pin(gpOutPinNum26, Pin.OUT)
gpOutPin27 = Pin(gpOutPinNum27, Pin.OUT)

gpOutPin28 = Pin(28, Pin.OUT)

gpOutPin28.low()

gpOutPinDict = {
’25’ : gpOutPin25,
’20’ : gpOutPin20,
’21’ : gpOutPin21,
’22’ : gpOutPin22,
’26’ : gpOutPin26,
’27’ : gpOutPin27,
}

gpOutPin5 = Pin( 5, Pin.OUT) # SPI0 CS

*** Pico GP PWM Pin Assignment ***

gpPwmPin28 = PWM(Pin(28))

gpPwmPin28.freq(oneKHz)

gpPwmPin28.duty_u16(int(65535/2)) #dutyCycle 50%

def createPwm(pwmFreq):
print(‘Begin createPwm(),…’)
gpPwmPin28 = PWM(Pin(28))
gpPwmPin28.freq(pwmFreq)
gpPwmPin28.duty_u16(int(65535/2)) #dutyCycle 50%
print(‘End createPwm()’)
return

*** Sample Tests ***

printProgramName()

createPwm(fourKHz)

========= ========= ========= ========= ========= ========= ========= =========

*** Pico GPIO Functions ***

def setGpOutPinHigh(gpOutPin):
gpOutPin.high()
return

def setGpOutPinLow(gpOutPin):
gpOutPin.low()
return

def toggleGpOutPinNum(gpOutPinNum, highTime, lowTime, repeatTimes, totalToggleTimes):
#print(‘Begin toggleGpOutPin(), …’)
#print(‘ GpOutPinNum =’, gpOutPinNum)
gpOutPin = gpOutPinDict[str(gpOutPinNum)]

for toggleCount in range(totalToggleTimes):
    for repeatCount in range(repeatTimes):
        setGpOutPinHigh(gpOutPin)
        pause(highTime)
        setGpOutPinLow(gpOutPin)    
        pause(lowTime)
#print('End   toggleGpOutPin(), ...')            
return

def toggleGpOutPinNumList(gpOutPinNumList, highTime, lowTime, repeatTimes, totalToggleTimes):
for gpOutPinNum in gpOutPinNumList:
toggleGpOutPinNum(gpOutPinNum, highTime, lowTime, repeatTimes, totalToggleTimes)
return

def toggleGpOutPin1kHz(gpOutPinNum):
print(‘Begin toggleGpOutPin1kHz’)
toggleGpOutPin(gpOutPinNum, highTime = halfMilliSecond, lowTime = halfMilliSecond, repeatTimes = once, totalToggleTimes = tenMillionTimes)
print(‘End toggleGpOutPin1kHz’)
return

def toggleGpOutPin2kHz(gpOutPinNum):
print(‘Begin toggleGpOutPin1kHz’)
toggleGpOutPin(gpOutPinNum, highTime = quarterMilliSecond, lowTime = quarterMilliSecond, repeatTimes = once, totalToggleTimes = tenMillionTimes)
print(‘End toggleGpOutPin1kHz’)
return

*** Sample Tests 2022mar20hkt1602 ***

printProgramName() # Line 209

toggleGpOutPinNum(gpOutPinNum = 25, highTime = 1, lowTime = 1, repeatTimes = 2, totalToggleTimes = 4) # *** Tested OK, 2022mar20hkt1601 ***

*** Sample Tests ***

toggleGpOutPinNumList(gpOutPinNumList = [20, 21, 22, 26, 27], highTime = quarterSecond, lowTime = quarterSecond, \

repeatTimes = once, totalToggleTimes = twice)

printProgramName()

toggleGpOutPinNum(gpOutPinNum = 20, highTime =quarterSecond, lowTime = quarterSecond, repeatTimes = twice, totalToggleTimes = fourTimes)

toggleGpOutPinNumList(gpOutPinNumList = [20, 21, 22, 26, 27], highTime = quarterSecond, lowTime = quarterSecond, repeatTimes = twice, totalToggleTimes = fourTimes)

toggleGpOutPin1kHz(gpOutPinNum = 22)

toggleGpOutPin2kHz(gpOutPinNum = 22)

========= ========= ========= ========= ========= ========= ========= =========

*** Pico UART Config/Functions ***

uart0TxdPinNum = 0
uart0RxdPinNum = 1
uart1TxdPinNum = 8
uart1RxdPinNum = 9

uart0 = UART(0, baudrate = 9600, tx=Pin(uart0TxdPinNum), rx=Pin(uart0RxdPinNum))
uart1 = UART(1, baudrate = 9600, tx=Pin(uart1TxdPinNum), rx=Pin(uart1RxdPinNum))

uartPortDict = \
{
‘0’: uart0,
‘1’: uart1,
}

*** Uart Functions ***

========= ========= ========= ========= ========= ========= ========= =========

*** UART Functions ***

def uartWrite(uartPortNum, writeBytes):
uartPort = uartPortDict[str(uartPortNum)]
uartPort.write(writeBytes)
return

def uartRead(uartPortNum, bytesLen):
uartPort = uartPortDict[str(uartPortNum)]
while uartPort.any():
readBytes = uartPort.read(bytesLen)
return readBytes

*** test uart loopback functions ***

def testUartLoopBack(uartPortNum, writeBytes):
print(‘ Begin testUartLoopBack(), …’)
print(‘ uartPortNum =’, uartPortNum)

uartWrite(uartPortNum, writeBytes)
print('        writeBytes       =', writeBytes)    

utime.sleep(0.5)

bytesLength = len(writeBytes)
readBytes = uartRead(uartPortNum, bytesLength)     
print('        readBytes        =', readBytes)

print('    End   testUartLoopBack().')
return

*** UART Test Functions ***

printProgramName()

testUartLoopBack(uartPortNum = 0, writeBytes = ‘uart0 Hello World’) # 223

testUartLoopBack(uartPortNum = 1, writeBytes = ‘uart1 Hello World’) # 224

*** Sample output ***

”’

%Run -c $EDITOR_CONTENT
*** Program Name = tmc2225test60.py Programmer = tlfong01 Date = 2022feb17 ***

Begin testUartLoopBack(), ...
  uartPortNum        = 0
    writeBytes       = uart0 Hello World
    readBytes        = b'uart0 Hello World'
End   testUartLoopBack().
Begin testUartLoopBack(), ...
  uartPortNum        = 1
    writeBytes       = uart1 Hello World
    readBytes        = b'uart1 Hello World'
End   testUartLoopBack().

”’

readRequestDatagramV01 = b’syncByte

*** Test Functions ***

testUartListLoopBack([0], ‘Msg1’)

testUartListLoopBack([1], ‘Msg2’)

testUartListLoopBack([0, 1], ‘Msg’)

========= ========= ========= ========= ========= ========= ========= =========

8. SPI Functions

*** Config SPI Ports ***

spiPort0 = SPI(0, baudrate = 100000, polarity = 0, phase = 0, bits = 8,
sck = Pin(2), mosi = Pin(3), miso = Pin(4))

spiPort1 = SPI(1, baudrate = 100000, polarity = 0, phase = 0, bits = 8,
sck = Pin(10), mosi = Pin(11), miso = Pin(12))

*** SPI Functions ***

spiPort0.read(10) # read 10 bytes on MISO

spiPort0.read(10, 0xff) # read 10 bytes while outputting 0xff on MOS##I

spiBuf1 = bytearray(50) # create a buffer

spiPort0.readinto(spiBuf1) # read into the given buffer (reads 50 bytes in this case)

spiPort0.readinto(spiBuf1, 0xff) # read into the given buffer and output 0xff on MOSI

spiPort0.write(b’12345′) # write 5 bytes on MOSI

spiBuf2 = bytearray(4) # create a buffer

spiPort0.write_readinto(b’1234′, spiBuf2) # write to MOSI and read from MISO into the buffer

spiPort0.write_readinto(spiBuf2, spiBuf2) # write buf to MOSI and read MISO back into buf

*** Test Functions ***

def testSpiLoopBack(spiPort, testBytes):
printProgramName()
print(‘Begin testSpiLoopback(), …’)
writeBytes = ‘hello’
for count in range(1):
spiPort0.write(writeBytes)
utime.sleep(0.01)
readBytes = spiPort0.read(5)
utime.sleep(0.01)

print('  writeBytes =', writeBytes)
print('  readBytes  =', readBytes)
print('End   testSpiLoopback().')    
return

*** Sample Test ***

testSpiLoopBack(spiPort0, b’12345′) # NOT tested!!!

========= ========= ========= ========= ========= ========= ========= =========

I2C Config/Test Functions

i2cPort0SclPinNum = 17
i2cPort0SdaPinNum = 16
i2cPort0FreqName = ‘100kHz’ # 400kHz cannot detect pcf9875!!!
i2cPort1SclPinNum = 19
i2cPort1SdaPinNum = 18
i2cPort1FreqName = ‘100kHz’

i2cFreqDict = \
{
‘100kHz’ : 100000,
‘400kHz’ : 400000,
}

i2cDeviceNameDict = \
{
‘0x20’ : {‘DeviceName’ : ‘(PCF8574 #0 0x20)’},
‘0x21’ : {‘DeviceName’ : ‘(PCF8574 #1 0x21)’},
‘0x27’ : {‘DeviceName’ : ‘(PCF8575 #0 0x27)’},
‘0x26’ : {‘DeviceName’ : ‘(PCF8575 #1 0x26)’},

    '0x22' : {'DeviceName' : '(PCF8574 #2 0x22)'},
    '0x23' : {'DeviceName' : '(PCF8574 #3 0x23)'},
    '0x24' : {'DeviceName' : '(PCF8574 #0 0x24)'},
    '0x25' : {'DeviceName' : '(PCF8574 #1 0x25)'},

    '0x68' : {'DeviceName' : '(DS3231 RTC #0 0x68)'},
    '0x57' : {'DeviceName' : '(DS3231 ROM #0 0x57)'} 
}

i2cPort0 = machine.I2C(0, scl = machine.Pin(i2cPort0SclPinNum), sda = machine.Pin(i2cPort0SdaPinNum), freq = i2cFreqDict[i2cPort0FreqName])
i2cPort1 = machine.I2C(1, scl = machine.Pin(i2cPort1SclPinNum), sda = machine.Pin(i2cPort1SdaPinNum), freq = i2cFreqDict[i2cPort1FreqName])

i2cPortDict = \
{
‘0’ : {
‘I2cPort’ : i2cPort0,
‘I2cPortName’ : ‘I2cPort0’,
‘I2cPortSclPinNum’ : i2cPort0SclPinNum,
‘I2cPortSdaPinNum’ : i2cPort0SdaPinNum,
‘I2cPortFreq’ : i2cPort0FreqName,
},

'1' : {
         'I2cPort'          : i2cPort1,
         'I2cPortName'      : 'I2cPort1',
         'I2cPortSclPinNum' : i2cPort1SclPinNum,
         'I2cPortSdaPinNum' : i2cPort1SdaPinNum,
         'I2cPortFreq'      : i2cPort1FreqName,             
      }
}

def scanI2cDevices(i2cPortNum):
i2cPort = i2cPortDict[str(i2cPortNum)][‘I2cPort’]
i2cPortName = i2cPortDict[str(i2cPortNum)][‘I2cPortName’]
i2cPortSclPinNum = i2cPortDict[str(i2cPortNum)][‘I2cPortSclPinNum’]
i2cPortSdaPinNum = i2cPortDict[str(i2cPortNum)][‘I2cPortSdaPinNum’]
i2cPortFreq = i2cPortDict[str(i2cPortNum)][‘I2cPortFreq’]
i2cDeviceAddrList = i2cPort.scan()
print(‘ i2cPortNum =’, i2cPortNum)
print(‘ i2cPortName =’, i2cPortName)
print(‘ ic2PortSclPinNum =’, i2cPortSclPinNum)
print(‘ ic2PortSdaPinNum =’, i2cPortSdaPinNum)
print(‘ ic2PortFreq =’, i2cPortFreq)
print(‘ Devices detected = ‘, end = ”)
#print(i2cDeviceAddrList) # for debugging, for unknown devices
for deviceAddr in i2cDeviceAddrList:
print(hex(deviceAddr), i2cDeviceNameDict[hex(deviceAddr)][‘DeviceName’], end = ‘, ‘)
print(”)
return

def scanI2cDevicesI2cPortNumList(i2cPortNumList):
printProgramName()
print(‘Begin testScanI2cDevices(), …’)
for i2cPortNum in i2cPortNumList:
scanI2cDevices(i2cPortNum)
print(‘End testScanI2cDevices().’)
return

*** Sample Tests ***

scanI2cDevicesI2cPortNumList([0, 1]) # Line432

========= ========= ========= ========= ========= ========= ========= =========

*** PCF8574/pcf8575 8-bit/16-bit GPIO Pin Expander

pcf8574DevDict = \
{
‘0’ : { ‘DeviceName’ : ‘pcf857400’,
‘I2cPortNum’ : 0,
‘DevAddr’ : 0x20,
},
‘1’ : { ‘DeviceName’ : ‘pcf857401’,
‘I2cPortNum’ : 0,
‘DevAddr’ : 0x21,
},
‘2’ : { ‘DevicveName’ : ‘pcf857500’,
‘I2cPortNum’ : 1,
‘DevAddr’ : 0x22,
},
‘3’ : { ‘Pcf8574DevName’ : ‘pcf857501’,
‘I2cPortNum’ : 1,
‘DevAddr’ : 0x23,
},

    '4' : { 'Pcf8574DevName' : 'pcf857404',
            'I2cPortNum'     : 1,
            'DevAddr'        : 0x25,
          },        
    '5' : { 'Pcf8574DevName' : 'pcf857405',
            'I2cPortNum'     : 0,
            'DevAddr'        : 0x26,
          },
    '6' : { 'Pcf8574DevName' : 'pcf857406',
            'I2cPortNum'     : 0,
            'DevAddr'        : 0x27,
          },               
    '7' : { 'Pcf8574DevName' : 'pcf857407',
            'I2cPortNum'     : 1,
            'DevAddr'        : 0x24,
          },
    '8' : { 'Pcf8574DevName' : 'pcf857408',
            'I2cPortNum'     : 1,
            'DevAddr'        : 0x27,
          },            
   }

def pcf8574WriteByte(devNum, writeByte):
i2cPortNum = pcf8574DevDict[str(devNum)][‘I2cPortNum’]
i2cPort = i2cPortDict[str(i2cPortNum)][‘I2cPort’]
devAddr = pcf8574DevDict[str(devNum)][‘DevAddr’]
i2cPort.writeto(devAddr, writeByte)
return

def pcf8574SetLowAllOutputBits(devNum):
pcf8574WriteByte(devNum, b’\x00′)
return

def pcf8575SetLowAllOutputBits(devNum):
pcf8574WriteByte(devNum, b’\x00′)
pcf8574WriteByte(devNum, b’\x00′)
return

def pcf8574SetHighAllOutputBits(devNum):
pcf8574WriteByte(devNum, b’\xff’)
return

def pcf8575SetHighAllOutputBits(devNum):
pcf8574WriteByte(devNum, b’\xff’)
pcf8574WriteByte(devNum, b’\xff’)
return

def testPcf8574V01(): # blink all pcf8574’s
print(‘Begin testPcf857401(), …’)
for devNum in range(4):
print(‘devNum =’, devNum)
for count in range(fourTimes):
pcf8574SetHighAllOutputBits(devNum)
pauseSeconds(quarterSecond)
pcf8574SetLowAllOutputBits(devNum)
pauseSeconds(quarterSecond)
print(‘End testPcf8574V01().’)
return

*** Sample Test ***

scanI2cDevicesI2cPortNumList([0, 1]) # Line 517 (tested ok 2022mapr06)

testPcf8574V01() # Line 518 (tested OK, 2022apr06)

13. PCFf8574 Controlling TB6612fng Functions

tb6612FngDrvDict = \
{
‘0’: {‘Pcf8574DevNum’ : 0},
‘1’: {‘Pcf8574DevNum’ : 1},
‘2’: {‘Pcf8574DevNum’ : 2},
‘3’: {‘Pcf8574DevNum’ : 3},
}

motorDict = \
{
‘0’: {‘MotorName’: ‘FrontLeft’, ‘Tb6612FngDevNum’ : 0},
‘1’: {‘MotorName’: ‘FrontRight’, ‘Tb6612FngDevNum’ : 1},
‘2’: {‘MotorName’: ‘BackLeft’, ‘Tb6612FngDevNum’ : 2},
‘3’: {‘MotorName’: ‘BackRight’, ‘Tb6612FngDevNum’ : 3},
}

def testDcMotorV01():
printProgramName()
print(‘Begin testMotorV01(), …’)
for motorNum in range(4):
print(‘ motorNum =’, motorNum)
print(‘ motorName =’, motorDict[str(motorNum)][‘MotorName’])
tb6612FngDevNum = motorDict[str(motorNum)][‘Tb6612FngDevNum’]
print(‘ tb6612fngDevNum =’, tb6612FngDevNum)
pcf8574DevNum = tb6612FngDrvDict[str(tb6612FngDevNum)][‘Pcf8574DevNum’]
print(‘ pcf8574DevNum =’, pcf8574DevNum)
print(‘End testMotorV01().’)
return

def testDcMotorV02():
printProgramName()
print(‘Begin testMotorV02(), …’)

enblBitHigh = 0x01 << 7
enblBitLow  = 0x00 << 7    
in1BitHigh  = 0x01 << 6
in1BitLow   = 0x00 << 6
in2BitHigh  = 0x01 << 5
in2BitLow   = 0x00 << 5
pwmBitHigh  = 0x01 << 4
pwmBitLow   = 0x00 << 4

enblClockWiseFullSpeed = enblBitHigh | in1BitLow | in2BitHigh | pwmBitHigh
print('enblClockWiseFullSpeed =', hex(enblClockWiseFullSpeed))

#0xb0 = 10110000

'''
for motorNum in [0]:
    print('  motorNum          =', motorNum)
    print('    motorName       =', motorDict[str(motorNum)]['MotorName'])
    tb6612FngDevNum = motorDict[str(motorNum)]['Tb6612FngDevNum']
    print('    tb6612fngDevNum =', tb6612FngDevNum)
    pcf8574DevNum = tb6612FngDrvDict[str(tb6612FngDevNum)]['Pcf8574DevNum']
    print('    pcf8574DevNum   =', pcf8574DevNum) 
'''

print('End   testMotorV02().')        
return

”’
def pcf8574WriteByte(devNum, writeByte):
i2cPortNum = pcf8574DevDict[str(devNum)][‘I2cPortNum’]
i2cPort = i2cPortDict[str(i2cPortNum)][‘I2cPort’]
devAddr = pcf8574DevDict[str(devNum)][‘DevAddr’]
i2cPort.writeto(devAddr, writeByte)
return
”’

”’
def testTb6612FngDrvV01():
printProgramName()
print(‘Begin testTb6612FngDrv01(), …’)
for drvNum in range(4):
print(‘ pcf8574DrvNum =’, drvNum)
print(‘ tb6612FngDevNum =’, tb6612FngDrvDict[str(drvNum)][‘Pcf8574DevNum’])
print(‘End testTb6612FngDrv01(), …’)
return
”’

*** Sample Test ***

scanI2cDevicesI2cPortNumList([0, 1]) # Line 517

testPcf8574V01() # Line 518

testTb6612FngDrvV01() # Line548

testDcMotorV01()

testDcMotorV02()

========= ========= ========= ========= ========= ========= ========= =========

12. Pico GP Pins controlling TB6612FNG Config/Functions – Line 520

tb6612fngEnblPinNum = 20
tb6612fngInA1PinNum = 21
tb6612fngInA2PinNum = 22
tb6612fngPwm1PinNum = 26

*** TB6612FNG Functions ***

def testToggleTb6612fngControlPins():
print(‘ Begin testToggleTb6612fngControlPins(), …’)
toggleGpOutPinNumList([tb6612fngEnblPinNum, tb6612fngInA1PinNum, tb6612fngInA2PinNum, tb6612fngPwm1PinNum], \
highTime = quarterSecond, lowTime = quarterSecond, \
repeatTimes = twice, totalToggleTimes = twice)
print(‘ End testToggleTb6612fngControlPins(), …’)
return

*** Sample Tests ***

printProgramName()

testToggleTb6612fngControlPins() # 1007

def tb6612fngDsblDriver(tb6612fngEnblPinNum):
enblPin = gpOutPinDict[str(enblPinNum)]
setGpOutPinLow(enblPin)
return

def tb6612fngEnblDriver(tb6612fngEnblPinNum):
enblPin = gpOutPinDict[str(enblPinNum)]
setGpOutPinHigh(enblPin)
return

def tb6612fngStopMotor(in1PinNum, in2PinNum):
in1Pin = gpOutPinDict[str(in1PinNum)]
in2Pin = gpOutPinDict[str(in2PinNum)]
setGpOutPinLow(in1Pin)
setGpOutPinLow(in2Pin)
return

def tb6612fngSetDirCcw(in1PinNum, in2PinNum):
in1Pin = gpOutPinDict[str(in1PinNum)]
in2Pin = gpOutPinDict[str(in2PinNum)]
setGpOutPinLow(in1Pin)
setGpOutPinHigh(in2Pin)
return

def tb6612fngSetDirCw(in1PinNum, in2PinNum):
in1Pin = gpOutPinDict[str(in1PinNum)]
in2Pin = gpOutPinDict[str(in2PinNum)]
setGpOutPinHigh(in1Pin)
setGpOutPinLow(in2Pin)
return

def tb612fngMoveFullSpeed(pwm1PinNum):
pwm1Pin = gpOutPinDict[str(pwm1PinNum)]
setGpOutPinHigh(pwm1Pin)
return

def tb6612fngTestDriverControlUsingGpPinsV01():
printProgramName()
print(‘Begin tb6612fngTestDriverControlUsingGpPinsV01(), …’)

tb6612fngDsblDriver(tb6612fngEnblPinNum)

# *** CCW 2 seconds ***
tb6612fngSetDirCcw(tb6612fngInA1PinNum, tb6612fngInA2PinNum)
tb6612fngEnblDriver(tb6612fngEnblPinNum)
tb612fngMoveFullSpeed(tb6612fngPwm1PinNum)
pauseSeconds(2)

# *** Stopd 2 seconds ***
tb6612fngStopMotor(tb6612fngInA1PinNum, tb6612fngInA2PinNum)
pauseSeconds(2)    

# *** CW 2 seconds ***
tb6612fngSetDirCw(tb6612fngInA1PinNum, tb6612fngInA2PinNum)
tb6612fngEnblDriver(tb6612fngEnblPinNum)
tb612fngMoveFullSpeed(tb6612fngPwm1PinNum)
pauseSeconds(2)
tb6612fngStopMotor(tb6612fngInA1PinNum, tb6612fngInA2PinNum)
print('End   tb6612fngTestDriverControlUsingGpPinsV01(), ...')
return

*** Sample Tests ***

tb6612fngTestDriverControlUsingGpPinsV01() # CCW 2seconds, stop 2 seconds, CW 2 seconds, Line 1077

def tb6612fngMoveOneMilliSecondStep(enblPinNum, dutyCycle):
highMicroSeconds = int(1000 * (dutyCycle / 100))
lowMicroSeconds = int(1000 – highMicroSeconds)
tb6612fngEnblDriver(enblPinNum)
utime.sleep_us(highMicroSeconds)
tb6612fngDsblDriver(enblPinNum)
utime.sleep_us(lowMicroSeconds)
return

def tb6612fngRepeatMoveOneMilliSecondStep(repeatTimes = 2000):
printProgramName()
print(‘Begin tb6612fngMoveOneMilliSecondStep2000Times(), …’)
tb6612fngDsblDriver(tb6612fngEnblPinNum)
tb6612fngSetDirCcw(tb6612fngInA1PinNum, tb6612fngInA2PinNum)
enblPinNum = tb6612fngEnblPinNum
dutyCycle = 50
for stepCount in range(repeatTimes):
tb6612fngMoveOneMilliSecondStep(enblPinNum, dutyCycle)
tb6612fngDsblDriver(tb6612fngEnblPinNum)
print(‘End tb6612fngMoveOneMilliSecondStep2000Times(), …’)
return

*** Sample Test ***

tb6612fngTestDriverControlUsingGpPinsV01() # CCW 2seconds, stop 2 seconds, CW 2 seconds, Line 1077

tb6612fngRepeatMoveOneMilliSecondStep(repeatTimes = 1000)

”’ *** Old Tests ***
def pcf8574ToggleAllOutputBits(devNum, highTime, lowTime, pauseTime, countTotal):
for count in range(countTotal):
pcf8574SetLowAllOutputBits(devNum)
utime.sleep(pauseTime)
pcf8574SetHighAllOutputBits(devNum)
utime.sleep(pauseTime)
return

pcf8574ControlByteDict = \
{
‘0x00′ : b’\x00’,
‘0xff’ : b’\xff’,
‘0b00000100′ : b’\x04’,
‘0b00000000′ : b’\x00’,
}

def pcf8574ToggleByte(devNum, byte1Name, byte2Name, toggleFreq, totalCount):
toggleTime = 1 / toggleFreq
print(‘ toggleTime =’, toggleTime)
writeByte1 = pcf8574ControlByteDict[byte1Name]
writeByte2 = pcf8574ControlByteDict[byte2Name]

for count in range(totalCount):
    pcf8574WriteByte(devNum, writeByte1)        
    utime.sleep(toggleTime)
    pcf8574WriteByte(devNum, writeByte2)  
    utime.sleep(toggleTime)        
return

def pcf8574ToggleByteAllBitsOnAllBitsOffOneThousandHzFourThousandTimes():
print(‘Begin pcf8574ToggleByteAllBitsOnAllBitsOffOneThousandHzFourThousandTimes(), …’)
pcf8574ToggleByte(devNum = 0, byte1Name = ‘0xff’, byte2Name = ‘0x00’, toggleFreq = 1000, totalCount = 4000)
print(‘End pcf8574ToggleByteAllBitsOnAllBitsOffOneThousandHzFourThousandTimes().’)
return

def pcf8574ToggleByteAllBitsOnAllBitsOffFourHzTwoTimes():
print(‘Begin pcf8574ToggleByteAllBitsOnAllBitsOffFourHzEightTimes(), …’)
for devNum in [0, 1, 2, 3, 4]:
pcf8574ToggleByte(devNum, byte1Name = ‘0xff’, byte2Name = ‘0x00’, toggleFreq = 4, totalCount = 2)
print(‘End pcf8574ToggleByteAllBitsOnAllBitsOffOneHzEightTimes().’)
return

def pcf8574ToggleByteAllBitsOnAllBitsOffFourHzTwoTimesV2():
print(‘Begin pcf8574ToggleByteAllBitsOnAllBitsOffFourHzEightTimes(), …’)
for devNum in [5, 6]:
pcf8574ToggleByte(devNum, byte1Name = ‘0xff’, byte2Name = ‘0x00’, toggleFreq = 4, totalCount = 2)
print(‘End pcf8574ToggleByteAllBitsOnAllBitsOffOneHzEightTimes().’)
return

*** Sample Tests ***

printProgramName()

pcf8574ToggleByteAllBitsOnAllBitsOffFourHzTwoTimesV2()

print(‘Begin pcf8574TaggleByte(), …’)

pcf8574ToggleByte(devNum = 5, byte1Name = ‘0x00’, byte2Name = ‘0xff’, toggleFreq = 3, totalCount = 100)

print(‘End pcf8574TaggleByte()’)

”’

*** DS3231 RTC ***

*** Scan RTC DS3231 ***

scanI2cDevicesI2cPortNumList([0, 1]) # 518

”’
Sample Output

%Run -c $EDITOR_CONTENT
*** Program Name = tmc2225test79.py tlfong01 2022feb20hkt1710

Begin testScanI2cDevices(), …
i2cPortNum = 0
i2cPortName = I2cPort0
ic2PortSclPinNum = 17
ic2PortSdaPinNum = 16
ic2PortFreq = 400kHz
Devices detected = 0x20 (PCF8574 #0 0x20), 0x23 (PCF8574 #3 0x23), 0x57 (DS3231 EEPROM #0 0x57), 0x68 (DS3231 RTC #0 0x68),
i2cPortNum = 1
i2cPortName = I2cPort1
ic2PortSclPinNum = 19
ic2PortSdaPinNum = 18
ic2PortFreq = 100kHz
Devices detected = 0x20 (PCF8574 #0 0x20), 0x23 (PCF8574 #3 0x23),
End testScanI2cDevices().

>
”’

ds3231DevDict = \
{
‘0’ : { ‘DeviceName’ : ‘ds323100’,
‘I2cPortNum’ : 0,
‘DevAddr’ : 0x68,
},
‘1’ : { ‘DeviceName’ : ‘ds3231eeprom00’,
‘I2cPortNum’ : 0,
‘DevAddr’ : 0x57,
},
‘2’ : { ‘DeviceName’ : ‘ds323110’,
‘I2cPortNum’ : 1,
‘DevAddr’ : 0x68,
},
‘3’ : { ‘DeviceName’ : ‘ds3231eeprom11’,
‘I2cPortNum’ : 1,
‘DevAddr’ : 0x57,
},
}

ds3231ControlByteDict = \
{
‘EnableSquareWve0′ : b’\x00, x01’,
‘EnableSquareWve1′ : b’\x00, x01’,
}

def ds3231WriteBytes(devNum, writeBytesName):
i2cPortNum = ds3231DevDict[str(devNum)][‘I2cPortNum’]
i2cPort = i2cPortDict[str(i2cPortNum)][‘I2cPort’]
devAddr = ds3231DevDict[str(devNum)][‘DevAddr’]
writeBytes = ds3231ControlBytesDict[writeBytesName]
i2cPort.writeto(devAddr, writeBytes)
return

def ds3231WriteThreeBytes(devNum, byte1, byte2, byte3):
i2cPortNum = ds3231DevDict[str(devNum)][‘I2cPortNum’]
i2cPort = i2cPortDict[str(i2cPortNum)][‘I2cPort’]
devAddr = ds3231DevDict[str(devNum)][‘DevAddr’]
writeBytes = ds3231ControlBytesDict[writeBytesName]
i2cPort.writeto(devAddr, writeBytes)
return

def ds3231WriteThreeByteNames(devNum, byteName1, byteName22, byteName3):
i2cPortNum = ds3231DevDict[str(devNum)][‘I2cPortNum’]
i2cPort = i2cPortDict[str(i2cPortNum)][‘I2cPort’]
devAddr = ds3231DevDict[str(devNum)][‘DevAddr’]
byte1 = b’\x00′
byte2 = b’\x00′
byte3 = b’\x00′
writeBytes = ds3231ControlBytesDict[writeBytesName]
i2cPort.writeto(devAddr, writeBytes)
return

def ds3231WriteRegOneByte():
return

def ds3231ReadRegOneByte():
return

def testDs3231V01():
#printProgramName()
print(‘Begin testDs3231V01(), …’)
scanI2cDevicesI2cPortNumList([0, 1])
#testTmc2225V01()
print(‘End testDs3231V01().’)

*** Sample Test Call ***

scanI2cDevicesI2cPortNumList([0, 1]) # 408

testDs3231V01()

pcf8574ToggleByteAllBitsOnAllBitsOffOneHzFourTimes(devNum = 0)

pcf8574ToggleByteAllBitsOnAllBitsOffOneHzFourTimes(devNum = 1)

pcf8574ToggleByteAllBitsOnAllBitsOffOneHzFourTimes(devNum = 2)

pcf8574ToggleByteAllBitsOnAllBitsOffOneHzFourTimes(devNum = 3)

pcf8574ToggleByteAllBitsOnAllBitsOffOneHzFourTimes(devNum = 4)

testTmc2225V01()

========= ========= ========= ========= ========= ========= ========= =========

*** TMC2130/2160/2208/2209/2225 Testing Functions ***

========= ========= ========= ========= ========= ========= ========= =========

5. TMC2225 Config/Functions

enblPinNum = 20
dirPinNum = 21
stepPinNum = 22
ms1PinNum = 26
ms2PinNum = 27

*** tmc2225 Functions ***

def testToggleTmc2225ControlPins():
print(‘ Begin testToggleTmc2225ControlPins(), …’)
toggleGpOutPinNumList([enblPinNum, dirPinNum, stepPinNum, ms1PinNum, ms2PinNum], \
highTime = quarterSecond, lowTime = quarterSecond, \
repeatTimes = twice, totalToggleTimes = twice)
print(‘ End testToggleTmc2225ControlPins(), …’)
return

*** Sample Tests ***

printProgramName()

testToggleTmc2225ControlPins()

*** Enable/Disable Driver ***

def tmcEnblDriver(enblPinNum):
enblPin = gpOutPinDict[str(enblPinNum)]
setGpOutPinLow(enblPin)
return

tmcEnblDriver(enblPinNum)

def tmcDisblDriver(enblPinNum):
enblPin = gpOutPinDict[str(enblPinNum)]
setGpOutPinHigh(enblPin)
return

tmcDisblDriver(enblPinNum)

*** Set CW/CCW Direction ***

def tmcSetDirCcw(dirPinNum):
dirPin = gpOutPinDict[str(dirPinNum)]
setGpOutPinHigh(dirPin)
return

tmcSetDirCcw(dirPinNum)

def tmcSetDirCw(dirPinNum):
dirPin = gpOutPinDict[str(dirPinNum)]
setGpOutPinLow(dirPin)
return

tmcSetDirCw(dirPinNum)

*** Set 1/4, 1/8, 1/16, 1/32 microstepping resolution ***

def tmcSetOneFourthStep(ms1PinNum, ms2PinNum): # MS2, MS1: 00: 1/4, 01: 1/8, 10: 1/16, 11: 1/32
ms2Pin = gpOutPinDict[str(ms2PinNum)]
ms1Pin = gpOutPinDict[str(ms1PinNum)]
setGpOutPinLow(ms2Pin)
setGpOutPinLow(ms1Pin)
return

tmcSetOneFourthStep(ms1PinNum, ms2PinNum)

def tmcSetOneEighthStep(ms1PinNum, ms2PinNum):
ms2Pin = gpOutPinDict[str(ms2PinNum)]
ms1Pin = gpOutPinDict[str(ms1PinNum)]
setGpOutPinLow(ms2Pin)
setGpOutPinHigh(ms1Pin)
return

tmcSetOneEighthStep(ms1PinNum, ms2PinNum)

def tmcSetOneSixteenthStep(ms1PinNum, ms2PinNum):
ms2Pin = gpOutPinDict[str(ms2PinNum)]
ms1Pin = gpOutPinDict[str(ms1PinNum)]
setGpOutPinHigh(ms2Pin)
setGpOutPinLow(ms1Pin)
return

tmcSetOneSixteenthStep(ms1PinNum, ms2PinNum)

def tmcSetOneThirtySecondStep(ms1Pin, ms2Pin):
ms1Pin = gpOutPinDict[str(ms1PinNum)]
ms2Pin = gpOutPinDict[str(ms2PinNum)]
setGpOutPinHigh(ms1Pin)
setGpOutPinHigh(ms2Pin)
return

tmcSetOneThirtySecondStep(ms1PinNum, ms2PinNum) # sample test call

def tmcSendOneStepPulse(stepPinNum, halfPulsePeriodUs):
stepPin = gpOutPinDict[str(stepPinNum)]
setGpOutPinHigh(stepPin)
utime.sleep_us(halfPulsePeriodUs)
setGpOutPinLow(stepPin)
utime.sleep_us(halfPulsePeriodUs)
return

def tmcSendMultipleStepPulses(stepPinNum, halfPulsePeriodUs, pulsesTotal):
print(‘ Begin tmcSendMultipelStepPulses(), …’)
for count in range(pulsesTotal):
tmcSendOneStepPulse(stepPinNum, halfPulsePeriodUs)
print(‘ End tmcSendMultipleStepPulses().’)
return

def tmcSendOneMilliSecondStepPulses(stepPinNum, pulsesTotal):
tmcSendMultipleStepPulses(stepPinNum, 500, pulsesTotal)
return

tmcSendMultipleStepPulses(stepPinNum = 22, halfPulseTime = halfMilliSecond, pulsesTotal = fiveThousand)

tmcSendMultipleStepPulses(stepPinNum = 22, halfPulsePeriodUs = 500, pulsesTotal = 5000)

def testTmc2225V01():
printProgramName() # Print program name, author name, data
#testToggleTmc2225ControlPins()
tmcSetOneFourthStep(ms1PinNum, ms2PinNum) # Set microstepping resolution 1/4
tmcSetDirCcw(dirPinNum = 21) # Set direction counter clockwise
tmcSendOneMilliSecondStepPulses(stepPinNum = 22, pulsesTotal = 2000) # Send 2000 1ms step pulses
pause(oneSecond) # Pause one second
tmcSetDirCw(dirPinNum = 21) # Set direction clockwise
tmcSendOneMilliSecondStepPulses(stepPinNum = 22, pulsesTotal = 3000) # Send 3000 1ms step pulses
pause(oneSecond) # Pause one second
tmcSetOneEighthStep(ms1PinNum, ms2PinNum) # Set microstepping resolution 1/32
tmcSendOneMilliSecondStepPulses(stepPinNum = 22, pulsesTotal = 3000) # Send 3000 1ms step pulses
return

*** Sample Tests ***

testToggleTmc2225ControlPins()

testTmc2225V01() # test <<<<<<<<<<

========= ========= ========= ========= ========= ========= ========= =========

7.TMC2209 UART mode Config and Diagonistic Functions ***

Basic Config Byte

sync = 0xa0
slaveAddr = 0x00
gConfigRegAddr00 = 0x00
dummyCrc = 0x00

gConfigWord

gConfigWordLength = 10 # bits
gConfigWordDefaultVal = (0x01 << 0) | (0x01 << 8)
gconfigRegAddr00Write = 0x80 | gConfigRegAddr00
gconfigRegAddr00Read = 0x00 | gConfigRegAddr00

========= ========= ========= ========= ========= ========= ========= =========

12. L298N Config/Functions – Line 763

l298nEnblPinNum = 20
l298nIn1PinNum = 21
l298nIn2PinNum = 22

*** L298N Functions ***

def testTogglel298nControlPins():
print(‘ Begin testToggleL298nControlPins(), …’)
toggleGpOutPinNumList([l298nEnblPinNum, l298nIn1PinNum, l298nIn2PinNum], \
highTime = quarterSecond, lowTime = quarterSecond, \
repeatTimes = twice, totalToggleTimes = twice)
print(‘ End testToggleL298nControlPins(), …’)
return

*** Sample Tests ***

printProgramName()

testTogglel298nControlPins() # 768

def l298nDsblDriver(enblPinNum):
enblPin = gpOutPinDict[str(enblPinNum)]
setGpOutPinLow(enblPin)
return

def l298nEnblDriver(enblPinNum):
enblPin = gpOutPinDict[str(enblPinNum)]
setGpOutPinHigh(enblPin)
return

def l298nFastStopMotor(enblPinNum, in1PinNum, in2PinNum):
enblPin = gpOutPinDict[str(enblPinNum)]
in1Pin = gpOutPinDict[str(in1PinNum)]
in2Pin = gpOutPinDict[str(in2PinNum)]
setGpOutPinHigh(enblPin)
setGpOutPinHigh(in1Pin)
setGpOutPinHigh(in2Pin)
return

def n20StopMotor(enblPinNum):
l298nDsblDriver(enblPinNum)
return

def l298nSetDirCcw(in1PinNum, in2PinNum):
in1Pin = gpOutPinDict[str(in1PinNum)]
in2Pin = gpOutPinDict[str(in2PinNum)]
setGpOutPinLow(in1Pin)
setGpOutPinHigh(in2Pin)
return

def n20SetDirBackward(in1PinNum, in2PinNum):
l298nSetDirCcw(in1PinNum, in2PinNum)
return

def l298nSetDirCw(in1PinNum, in2PinNum):
in1Pin = gpOutPinDict[str(in1PinNum)]
in2Pin = gpOutPinDict[str(in2PinNum)]
setGpOutPinHigh(in1Pin)
setGpOutPinLow(in2Pin)
return

def n20SetDirForward(in1PinNum, in2PinNum):
l298nSetDirCw(in1PinNum, in2PinNum)
return

def l298nMoveFullSpeed(enblPinNum):
#enblPin = gpOutPinDict[str(enblPinNum)]
#setGpOutPinHigh(enblPin)
l298nEnblDriver(enblPinNum)
return

def n20MoveFullSpeed(enblPinNum):
l298nMoveFullSpeed(enblPinNum)
return

def l298nMoveOneMilliSecondStep(enblPinNum, dutyCycle):
highMicroSeconds = int(1000 * dutyCycle)
lowMicroSeconds = int(1000 – highMicroSeconds)

l298nEnblDriver(enblPinNum)
utime.sleep_us(highMicroSeconds)
l298nDsblDriver(enblPinNum)
utime.sleep_us(lowMicroSeconds) 
return

def l298nMoveMultipleSteps(numberOfSteps): # *** Move L298n + N20 motor multiple steps ***
printProgramName()
print(‘Begin l298nMoveMultipleSteps(), …’)
print(‘ Number of steps =’, numberOfSteps)
l298nDsblDriver(l298nEnblPinNum)
l298nSetDirCw(l298nIn1PinNum, l298nIn2PinNum)
for stepCount in range(numberOfSteps):
l298nMoveOneMilliSecondStep(enblPinNum = l298nEnblPinNum, dutyCycle = 0.5)
l298nFastStopMotor(l298nEnblPinNum, l298nIn1PinNum, l298nIn2PinNum)
print(‘End l298nMoveMultipleSteps().’)
return

def testL298nV01(): # *** Move L298n + N20 motor at full speed for 4 seconds ***
printProgramName()
print(‘Begin testL298nV01(), …’)
l298nDsblDriver(l298nEnblPinNum)
l298nSetDirCw(l298nIn1PinNum, l298nIn2PinNum)
l298nMoveFullSpeed(l298nEnblPinNum)
pause(fourSeconds)
l298nDsblDriver(l298nEnblPinNum)
print(‘End testL298nV01().’)
return

def testL298nV02(): # move 180 degrees twice = 360 degrees
for count in range(10):
l298nMoveMultipleSteps(numberOfSteps = 303)
pauseSeconds(1)
return

def testL298nV03(): # move 180 degrees forward and backward
printProgramName()
print(‘Begin testL298nV03(), …’)

numberOfSteps = 303
for count in range(10):
    l298nDsblDriver(l298nEnblPinNum)    
    l298nSetDirCw(l298nIn1PinNum, l298nIn2PinNum)
    for stepCount in range(numberOfSteps):
        l298nMoveOneMilliSecondStep(enblPinNum = l298nEnblPinNum, dutyCycle = 0.5)
    l298nFastStopMotor(l298nEnblPinNum, l298nIn1PinNum, l298nIn2PinNum)          
    pauseSeconds(1)

    l298nDsblDriver(l298nEnblPinNum)    
    l298nSetDirCcw(l298nIn1PinNum, l298nIn2PinNum)
    for stepCount in range(numberOfSteps):
        l298nMoveOneMilliSecondStep(enblPinNum = l298nEnblPinNum, dutyCycle = 0.5)
    l298nFastStopMotor(l298nEnblPinNum, l298nIn1PinNum, l298nIn2PinNum)          
    pauseSeconds(1)

print('End   testL298nV03(), ...')
return

def testL298nV04(): # move 180 degrees forward and backward
printProgramName()
print(‘Begin testL298nV04(), …’)

numberOfSteps = 2

for count in range(2):
    l298nDsblDriver(l298nEnblPinNum)        
    l298nSetDirCw(l298nIn1PinNum, l298nIn2PinNum)
    for stepCount in range(numberOfSteps):
        l298nMoveOneMilliSecondStep(enblPinNum = l298nEnblPinNum, dutyCycle = 0.5)
    l298nFastStopMotor(l298nEnblPinNum, l298nIn1PinNum, l298nIn2PinNum)          
    pauseSeconds(2)

    l298nDsblDriver(l298nEnblPinNum)    
    l298nSetDirCcw(l298nIn1PinNum, l298nIn2PinNum)
    for stepCount in range(numberOfSteps):
        l298nMoveOneMilliSecondStep(enblPinNum = l298nEnblPinNum, dutyCycle = 0.5)
    l298nFastStopMotor(l298nEnblPinNum, l298nIn1PinNum, l298nIn2PinNum)          
    pauseSeconds(2)

    l298nDsblDriver(l298nEnblPinNum)         

print('End   testL298nV04(), ...')
return

*** Sample Test ***

testL298nV01() # *** Move L298n + N20 motor at full speed for 4 seconds – Line 807 ***

testL298nV02() # *** Repeat moving 1800 degrees many times ***

testL298nV03() # *** Move 180 degrees forward and backward ***

def testN20V01(): # *** Move N20 motor at full speed for 2 seconds forward, 2 seconds backward ***
printProgramName()
print(‘Begin testN20V01(), …’)
n20StopMotor(l298nEnblPinNum) # Setup/Config motor
n20SetDirForward(l298nIn1PinNum, l298nIn2PinNum)

n20MoveFullSpeed(l298nEnblPinNum) # move motor full speed, 4 seconds
pause(fourSeconds)
n20StopMotor(l298nEnblPinNum)

n20SetDirBackward(l298nIn1PinNum, l298nIn2PinNum) # move motor backward, full speed, 4 seconds
n20MoveFullSpeed(l298nEnblPinNum)
pause(fourSeconds)

n20StopMotor(l298nEnblPinNum)    

print('End   testN20V01().')
return

*** Sample Tests ***

testN20V01()

13 Main Test Funtions

========= ========= ========= ========= ========= ========= ========= =========

========= ========= ========= ========= ========= ========= ========= =========

========= ========= ========= ========= ========= ========= ========= =========

========= ========= ========= ========= ========= ========= ========= =========

========= ========= ========= ========= ========= ========= ========= =========

*** Main Test Functions ***

1. *** Print Program Name, Author, and Data ***

printProgramName() # >>>>>>>>>> Line209 >>>>>>>>>>

2. *** Blink System LED – Sample Tests 2022mar20hkt1602 ***

print(‘Begin Blink Pico System LED at pin GP25, …’)

toggleGpOutPinNum(gpOutPinNum = 25, highTime = 0.25, lowTime = 0.5, repeatTimes = 2, totalToggleTimes = 4) # *** Tested OK, 2022mar20hkt1601 ***

print(‘End Blink Pico System LED at pin GP25.’)

3. *** Blink GP pins list [20, 21, 22, 26, 27] ***

print(‘Begin toggle GP pin list [20, 21, 22, 26, 27], …’)

toggleGpOutPinNumList(gpOutPinNumList = [20, 21, 22, 26, 27], highTime = quarterSecond, lowTime = quarterSecond, \

repeatTimes = once, totalToggleTimes = twice)

print(‘End toggle GP pin list [20, 21, 22, 26, 27].’)

4. *** Toggle TB6612FNG Control Pins ***

testToggleTb6612fngControlPins() # 1007

5. *** TB6612FNG, CCW 2 seconds, stop two seconds, CW 2 seconds ***

tb6612fngTestDriverControlUsingGpPinsV01() # CCW 2seconds, stop 2 seconds, CW 2 seconds, Line 1077

6. *** TB6612FNG Repeat move 1 millisecond step 2000 times ***

tb6612fngRepeatMoveOneMilliSecondStep(repeatTimes = 1000)

7. *** Scan I2C Devices (PCF8574/8575 on the bus ***

scanI2cDevicesI2cPortNumList([0, 1])

8. *** Test PCF8574 8-bit/16-bit IO Exender ***

scanI2cDevicesI2cPortNumList([0, 1]) # Line 517

testPcf8574V01() # Line 518

9. *** DS3231/UART/HC12/SPI Tests ***

10. *** TMC2225 Tests ***

testToggleTmc2225ControlPins()

testTmc2225V01()

*** End ****

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 )

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.