Python Code Example for I2C on Unihiker

Do you have any examples on how to use the I2C function on Unihiker.
I am trying to read data from a 9-DOF ICM-20948 board.
There is very little detail on the pinpong library functions or examples
Thanks
Warning. I have experienced that the i2c scan takes MULTIPLE attempts before it finds my device. The first scans return no devices. You need to run it in a loop. After more experimentation, I found that even if i2c scan can not see the device immediately, the device IS functionsl and will respond immediately to commands.

The I2C interface of the unihiker is connected to a co-processor (gd32), so the pinpong library in Python is used, which operates on the same principle as Firmata.
By examining the source code of the pinpong library on pypi, you can see that there are five functions in pinpong for I2C data read and write:
- writeto(i2c_addr, value)- writeto_mem(i2c_addr, reg, value)- readfrom(i2c_addr, read_byte)- readfrom_mem(i2c_addr, reg, read_byte)- readfrom_mem_restart_transmission(i2c_addr, reg, read_byte)
-----------------------------------------------------
Here is the link to the GitHub repository where I attempted to port the Raspberry Pi library to unihiker. It might be useful to you:https://github.com/liliang9693/DFRobot_SGP40/tree/master/Python

Try to test the 9-DOF ICM-20948 sensor separately. If possible with an Arduino UNO.

Hi!
# -*- coding: utf-8 -*-
#i2c
import time
from pinpong.board import Board,I2C
Board("UNIHIKER").begin() #初始化,选择板型和端口号,不输入端口号则进行自动识别
#Board("UNIHIKER","COM36").begin() #windows
#Board("UNIHIKER","/dev/ttyACM0").begin() #linux
#Board("UNIHIKER","/dev/cu.usbmodem14101").begin() #mac
i2c = I2C()
#i2c = I2C(bus_num=0)#bus_num default 0
l=i2c.scan()#[0x33]
print("i2c list:",l)
#i2c.writeto(0x33,[1,2,3,4,5])
#i2c.readfrom(0x33,6)#read 6 bit
#i2c.readfrom_mem(0x33,2,6)#i2c register 2 read 6bit
#i2c.writeto_mem(0x33,2,[1,2,3,4,5])#i2c register 2 write[1,2,3,4,5]
while(1):
time.sleep(1)
