Welcome to JetCobot repository
10.Driver library and communication
10. Driver Library and Communication Configuration
This example demonstrates the process of installing and configuring the serial port and I2C driver libraries. The factory image already has these configured, so you can skip this step.
1. Python I2C driver
Open the terminal and enter the following command to install
xxxxxxxxxxsudo pip3 install smbus
Python imports the smbus object
xxxxxxxxxximport smbusbus = smbus.SMBus(1)
I2C read and write examples
xxxxxxxxxx# Write data and write data blocksbus.write_byte_data(addr, reg, data)bus.write_i2c_block_data(addr, reg, data_array)# Read datarecv = bus.read_word_data(addr, reg)
2. Python serial port driver
Open the terminal and enter the following command to install
xxxxxxxxxxsudo pip3 install pyserial
Python imports the serial object
xxxxxxxxxximport serialser = serial.Serial('/dev/ttyUSB0', 115200)
Serial Port Read and Write Example
xxxxxxxxxx# Write a block of dataser.write(data_array)# Read datarecv = ser.read()