Skip to main content

CircuitPython library for the DF DFRobot_Gravity_DRF0627_Dual_Uart

Project description

Introduction

Documentation Status Discord Build Status Code Style: Black

CircuitPython library for DFROBOT Gravity: I2C to Dual UART Module

Gravity: I2C to Dual UART Module (SKU:DFR0627)

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle or individual libraries can be installed using circup.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install CircuitPython_DFRobot_Gravity_DRF0627_I2C_Dual_Uart

To install system-wide (this may be required in some cases):

sudo pip3 install CircuitPython_DFRobot_Gravity_DRF0627_I2C_Dual_Uart

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install CircuitPython_DFRobot_Gravity_DRF0627_I2C_Dual_Uart

Installing to a Connected CircuitPython Device with Circup

Make sure that you have circup installed in your Python environment. Install it with the following command if necessary:

pip3 install circup

With circup installed and your CircuitPython device connected use the following command to install:

circup install CircuitPython_DFRobot_Gravity_DRF0627_I2C_Dual_Uart

Or the following command to update an existing version:

circup update

Usage Example

import 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 information

The DRF0627 comes with a cable that allows for connection to the CircuitPython hardware using a SparkFun STEMMA QT / Qwiic Breadboard Breakout Adapter Product ID: 4527 https://www.adafruit.com/product/4527

SparkFun STEMMA QT / Qwiic Breadboard Breakout Adapter

Connections:

Black wire -> Stemma Ground
Red wire -> Stemma 3.3 V
Green wire -> Stemma SDA
Blue wire -> Stemma SCA

To 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”

SCM TTL to RS-485 Interface Module

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page