Package: circuitpython-dfrobot-gravity-drf0627-dual-uart
IntroductionCircuitPython library for DFROBOT Gravity: I2C to Dual UART ModuleGravity: I2C to Dual UART Module (SKU:DFR0627)Extra Wiki informationDependenciesThis driver depends on:Adafruit CircuitPythonBus DeviceDFROBOT Gravity: I2C to Dual UART Module HardwarePlease ensure all dependencies are available on the CircuitPython filesystem.
This is easily achieved by downloadingthe Adafruit library and driver bundleor individual libraries can be installed usingcircup.Installing from PyPIOn supported GNU/Linux systems like the Raspberry Pi, you can install the driver locallyfrom
PyPI.
To install for current user:pip3installCircuitPython_DFRobot_Gravity_DRF0627_I2C_Dual_UartTo install system-wide (this may be required in some cases):sudopip3installCircuitPython_DFRobot_Gravity_DRF0627_I2C_Dual_UartTo install in a virtual environment in your current project:mkdirproject-name&&cdproject-namepython3-mvenv.envsource.env/bin/activatepip3installCircuitPython_DFRobot_Gravity_DRF0627_I2C_Dual_UartInstalling to a Connected CircuitPython Device with CircupMake sure that you havecircupinstalled in your Python environment.
Install it with the following command if necessary:pip3installcircupWithcircupinstalled and your CircuitPython device connected use the
following command to install:circupinstallCircuitPython_DFRobot_Gravity_DRF0627_I2C_Dual_UartOr the following command to update an existing version:circupupdateUsage Exampleimport time
import board
import CircuitPython_DFRobot_Gravity_DRF0627_I2C_Dual_Uart as DualUart

i2c = board.I2C()


iic_uart1 = DualUart.DFRobot_IIC_Serial(
    i2c,
    sub_uart_channel=DualUart.DFRobot_IIC_Serial.SUBUART_CHANNEL_1,
    IA1=1,
    IA0=1,
)

iic_uart2 = DualUart.DFRobot_IIC_Serial(
    i2c,
    sub_uart_channel=DualUart.DFRobot_IIC_Serial.SUBUART_CHANNEL_2,
    IA1=1,
    IA0=1,
)

try:
    iic_uart1.begin(baud=9600, format=iic_uart1.IIC_Serial_8N1)
    print("Opened: UART 1 ")
except Exception as e:
    iic_uart1 = None
    print("Error: Could not open UART 1 Exception: " + str(e))

try:
    iic_uart2.begin(baud=9600, format=iic_uart2.IIC_Serial_8N1)
    print("Opened: UART 2")
except Exception as e:
    iic_uart2 = None
    print("Error: Could not open UART 2 Exception: " + str(e))

sendID = 1
sendDelayCount = 1

while True:
    time.sleep(.3)
    sendDelayCount -= 1
    if sendDelayCount <= 0:
        sendDelayCount = 10
        iic_uart1.write("From1:" + str(sendID))
        iic_uart2.write("From2:" + str(sendID))

    if iic_uart1 is not None:
        if iic_uart1.available():
            s = ""
            while iic_uart1.available():
                b = iic_uart1.read(1)
                s += chr(b[0])
            print("<1:" + s + " len:" + str(len(s)) + ">")

    if iic_uart2 is not None:
        if iic_uart2.available():
            s = ""
            while iic_uart2.available():
                b = (iic_uart2.read(1))
                s += chr(b[0])
            print("<2:" + s + " len:" + str(len(s)) + ">")Additional connection informationThe DRF0627 comes with a cable that allows for connection to the CircuitPython hardware using a
SparkFun STEMMA QT / Qwiic Breadboard Breakout Adapter Product ID: 4527https://www.adafruit.com/product/4527Connections:Black wire -> Stemma Ground
Red wire -> Stemma 3.3 V
Green wire -> Stemma SDA
Blue wire -> Stemma SCATo test the connection the “t” and “R” pins can be connected together. If you tie the “T” and “R” pins between the same UART the data will echo back to you on the same port. If you tie the “T” and “R” pins from UART1 to UART 2 data will be send between the two ports.If RS485 is desired you can use a RS485 adapter such as the “SCM TTL to RS-485 Interface Module”DocumentationAPI documentation for this library can be found onRead the Docs.For information on building library documentation, please check outthis guide.ContributingContributions are welcome! Please read ourCode of Conductbefore contributing to help this project stay welcoming.