Hello,
I started to use smbus2 which can be installed with pip3 after an apt install python3-pip installation.
…
So,
# with help from @zmatt on Freenode
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
…
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)
…
On line 302 of the smbus2.py file, change the line to read:
filepath = "/dev/i2c-2".format(bus)
that should do it.
If you are making your source work in a virtual environment, sudo apt install python3-venv will take care of making some nice .txt files for use later in other Linux SBCs, e.g. requirements.txt is one.
Seth
P.S. If this makes sense, good. It took a while to get it to work without the read-only, deprecated versioning of Adafruit_GPIO.I2C as I2C.