Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def WriteByte(Reg,Value):
- data = [0 for i in range(2)]
- data[0] = Reg
- data[1] = Value
- MotorBridge.write_i2c_block_data(0x4b, 1, data)
- def WriteHalfWord(Reg,Value):
- data = [0 for i in range(3)]
- data[0] = Reg
- data[1] = Value & 0xff
- data[2] = (Value>>8) & 0xff
- MotorBridge.write_i2c_block_data(0x4b, 1, data)
- def WriteOneWord(Reg,Value):
- data = [0 for i in range(5)]
- data[0] = Reg
- data[1] = Value & 0xff
- data[2] = (Value>>8) & 0xff
- data[3] = (Value>>16) & 0xff
- data[4] = (Value>>24) & 0xff
- MotorBridge.write_i2c_block_data(0x4b, 1, data)
- def SetDefault():
- WriteOneWord(CONFIG_VALID,0x00000000)
- class MotorBridgeCape:
- def __init__(self):
- reset_pin.write_text('high')
- time.sleep(1)
- # init stepper motor A
- def StepperMotorAInit(self):
- WriteByte(TB_1A_MODE,TB_SPM) #Stepper
- time.sleep(DelayTime)
- WriteHalfWord(TB_1A_DUTY,1000) # voltage
- time.sleep(DelayTime)
- # MoveSteps > 0 CW
- # MoveSteps < 0 CCW
- # StepDelayTime : delay time for every step. uint us
- def StepperMotorAMove(self,MoveSteps,StepDelayTime):
- if MoveSteps > 0:
- WriteByte(TB_1A_DIR,TB_CW) #CW
- else:
- WriteByte(TB_1A_DIR,TB_CCW) #CW
- MoveSteps = -MoveSteps
- time.sleep(DelayTime)
- WriteOneWord(TB_1A_SPM_SPEED,StepDelayTime) # unit us
- time.sleep(DelayTime)
- WriteOneWord(TB_1A_SPM_STEP,MoveSteps)
- time.sleep(DelayTime)
- # init stepper motor B
- def StepperMotorBInit(self):
- WriteByte(TB_2A_MODE,TB_SPM) #Stepper
- time.sleep(DelayTime)
- WriteHalfWord(TB_2A_DUTY,1000) # voltage
- time.sleep(DelayTime)
- # MoveSteps > 0 CW
- # MoveSteps < 0 CCW
- # StepDelayTime : delay time for every step. uint us
- def StepperMotorBMove(self,MoveSteps,StepDelayTime):
- if MoveSteps > 0:
- WriteByte(TB_2A_DIR,TB_CW) #CW
- else:
- WriteByte(TB_2A_DIR,TB_CCW) #CW
- MoveSteps = -MoveSteps
- time.sleep(DelayTime)
- WriteOneWord(TB_2A_SPM_SPEED,StepDelayTime) # unit us
- time.sleep(DelayTime)
- WriteOneWord(TB_2A_SPM_STEP,MoveSteps)
- time.sleep(DelayTime)
- # Init DC Motor
- def DCMotorInit(self,MotorName,Frequency):
- # Init the DC Frequency
- WriteOneWord(CONFIG_TB_PWM_FREQ,Frequency)
- time.sleep(DelayTime)
- from smbus2 import SMBus
- import time
- import pathlib
- # reset pin is P9.23, i.e. gpio1.17
- reset_pin = pathlib.Path('/sys/class/gpio/gpio49/direction')
- reset_pin.write_text('low')
- MotorBridge = SMBus('/dev/i2c-2')
- ReadMode = 0
- WriteMode = 1
- DeAddr = 0X4B
- ConfigValid = 0x3a6fb67c
- DelayTime = 0.005
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement