How Huangshan Pai Xiao Zhi Uses Sensor

How to use I2C sensors with Xiaozhi on Huangshan Pi? I registered and tried to use the built-in lsm6dsl sensor in Xiaozhi, referring to the sensor example project under the SDK. After running it on Xiaozhi, I encountered the following error. How should I modify the code to make it work properly?

[21693] I/sensor motor: rt_sensor init success
[21700] I/sensor motor: rt_sensor init success
[21706] I/sensor motor: rt_sensor init success
[21713] E/drv.i2c motor: bus err:1, xfer:0/2, i2c_stat:20, i2c_errcode=21
[21724] E/drv.i2c motor: reset and send 9 clks
[21731] E/sensor.st.lsm6dsl motor: read id failed
[21737] E/sensor.st.lsm6dsl motor: _lsm6dsl init err code: -1
xiaozhi_ui_task start
 sp: 0x60201c90
psr: 0x81000000
r00: 0xf0207084
r01: 0x1237b292
r02: 0x1237b29a
r03: 0xf0207083
r04: 0x20016be4
r05: 0xf0207090
r06: 0xf0207084
r07: 0x1237b292
r08: 0xdeadbeef
r09: 0xdeadbeef
r10: 0xdeadbeef
r11: 0xdeadbeef
r12: 0x00000000
 lr: 0x122b00ff
 pc: 0x122b2044
hard fault on thread: xz_ui

=====================
PSP: 0x60201bfc, MSP: 0x20001fc4
===================
Thread Info        
===================
thread   pri  status      sp      top     stack size max used left tick  error
-------- ---  ------- ---------- ---------- ----------  ------  ---------- ---
motor     20  suspend 0x60202ee8 0x60202ffc 0x00001000    23%   0x00000006 000
battery   20  suspend 0x602006b8 0x602007fc 0x00000800    16%   0x0000000a 000
mbox      11  suspend 0x2005c438 0x2005c538 0x00001000    22%   0x00000008 000
xz_ui     30  ready   0x60201fb8 0x60201ffc 0x00001800    23%   0x00000009 000
xiaozhi   18  suspend 0x6030aec0 0x6030affc 0x00008000    02%   0x00000007 000
lcd_task  12  suspend 0x20014670 0x200147d4 0x00000800    43%   0x00000008 000
tshell    20  suspend 0x20041638 0x200417b4 0x00001000    16%   0x00000009 000
bt_downv  11  suspend 0x2001b288 0x2001b3a4 0x000007d0    37%   0x0000000a 000
audiosvr  11  suspend 0x2001d648 0x2001d7a4 0x00002400    77%   0x0000000a 000
alarmsvc  12  suspend 0x2003daf0 0x2003dc08 0x00000400    27%   0x00000005 000
tcpip     10  suspend 0x2003d638 0x2003d754 0x00001000    07%   0x00000014 000
etx       12  suspend 0x20036eb8 0x20036fc0 0x00000400    26%   0x00000010 000
erx       12  suspend 0x200369e0 0x20036aec 0x00000400    26%   0x00000010 000
tidle     31  ready   0x2002c9d0 0x2002caac 0x00000800    34%   0x0000000e 000
timer      4  suspend 0x200152d0 0x200153d4 0x00000800    12%   0x00000009 000
main      10  suspend 0x2003c498 0x2003c5c0 0x00001000    28%   0x00000008 000
===================
Mailbox Info       
===================
mailbox  entry size suspend thread
-------- ----  ---- --------------
ui_mb    0000  0008 0
bt_app   0000  0008 1:main
battery_ 0000  0001 0
btn_evt  0000  0008 0
mbox0    0000  0008 1:tcpip
etxmb    0000  0008 1:etx
erxmb    0000  0008 1:erx
===================
MessageQueue Info  
===================
msgqueue entry suspend thread
-------- ----  --------------
ui_msg   0000  0
drv_lcd  0000  1:lcd_task�
===================
Mutex Info         
===================
mutex      owner  hold suspend thread
-------- -------- ---- --------------
ble_flas (NULL)   0000 0
audio_sv (NULL)   0000 0
rtc      (NULL)   0000 0
alarmsvc (NULL)   0000 0
ulog loc (NULL)   0000 0
mu0      (NULL)   0000 0
fslock   (NULL)   0000 0
i2c_bus_ (NULL)   0000 0
i2c_bus_ (NULL)   0000 0
i2c_bus_ (NULL)   0000 0
i2c_bus_ (NULL)   0000 0
===================
Semaphore Info     
===================
semaphore v   suspend thread
-------- --- --------------
update_u 001 0
mbox     000 0
sifli    000 0
btn      001 0
lcd_msg  000 0
lcd_draw 000 0
drv_lcd  001 0
shrx     000 0
epic     001 0
ft6146   000 0
opus_mem 001 0
aes_drv  001 0
drv_eDma 001 0
gpadc    001 0
i2c4     000 0
i2c3     000 0
i2c2     000 0
i2c1     000 0
heap     001 0
flash2   001 0
===================
Memory Info     
===================
total memory: 280884 used memory : 136284 maximum allocated memory: 138784
===================
MemoryHeap Info     
===================
memheap   pool size  max used size available size
-------- ---------- ------------- --------------
opus_mem 1048576    79840         968736
FPU active!
mem manage fault:
SCB_CFSR_MFSR:0x82 DACCVIOL SCB->MMAR:F0207084

It appears that the IIC communication has failed. Check whether the IIC signal used by the sensor has been correctly routed to the appropriate IO through pinmux.

The IO pins should not be an issue. The SDA and SCL for I2C are configured this way and work normally in a separate sensor project.
image

Test whether the GS_3V3 power supply is turned on:

The PA30 has been mistakenly pulled low at this point in Xiao Zhi’s project. You need to enable it again here. Then check whether the power supply is normal. If there’s still no power, you may need to further check whether the upstream power source is turned on.