通过前面3节的研究,总算把基本的环境搭建好了,接下来移植Grove来获取模块的数据
【创龙TL3562-MiniEVM开发板试用体验】问题1 更换到Ubuntu镜像后,USB识别不了外设
【创龙TL3562-MiniEVM开发板试用体验】问题2 ubuntu镜像,不能获取ip地址
【创龙TL3562-MiniEVM开发板试用体验】问题3 扩展ubuntu文件系统
grove
Grove是由Seeed Studio推出的模块化电子接口标准,旨在简化嵌入式原型开发。它通过标准化4针连接器(防反插设计)替代复杂的面包板跳线,实现传感器、执行器与主控板(如Arduino、树莓派)的“积木式”连接,降低硬件入门门槛。
核心设计理念:
- 模块化:通过统一的4针接口连接传感器、执行器等模块,类似“电子积木”。
- 标准化:接口分为GPIO、ADC、PWM、UART、I2C等类型,确保兼容性。
- 易用性:简化硬件连接流程,降低学习门槛,适合快速原型开发
grove模块
Grove 拥有 300+ 种模块,覆盖传感器(温湿度、光照、火焰)、执行器(电机、继电器)、显示设备(OLED、数码管)、通信模块等,形成“积木式”开发体验

按功能分类的典型模块及用途:

主要应用在开源板上,从8位的Arduino,到32位的raspberry系列、BeagleBone系列等等主流开发板,通过扩展板(如GrovePi+)实现无缝连接
grove库
grove采用分层的设计模式,通过grove.py库,实现上层应用与底层实现的分离,以适应不同的硬件环境

- 应用层:开发者编写逻辑代码,调用Grove库提供的封装函数(如analogRead(pin)读取光传感器)
- 软件库层:主要是指抽象层grove.py,也即Adafrit RKIO层,封装硬件细节,提供跨平台兼容性
- SMBUS,针对I2C,使用pySMBUS和i2ctools库
- 接口层:物理连接:4针统一接口定义,当然了,接口的信号连接对应的信号,如GPIO,I2C,ADC,PWM等:
- 硬件模块层:具体的grove模型模块,输出标准化信号供主控读写
安装BB.GPIO
常见的GPIO库,有raspberry pi 的RPi.GPIO和beaglebone Black的BB.GPIO
在此以BB.GPIO以例子,将其移植到TL3562MiniEVM上
下载

介绍
如上所示,整个文件可以分为3种,
- 一种是通用文件,如constants,定义常量,
- 一种是需要移植适配的,如common.c,c_xxx.c文件
- 一种是py_xxx文件,它会调用c_xxx.c文件,是标准文件,它的存在是为了将c语言转成python接口
而关键的移植适配文件有
- common,定义引脚及转换接口
- event_gpio,定义gpio的输入输出配置,主要是基于/sys/class/gpio
- c_adc,定义adc的输入配置,主要是基于/sys/bus/iio/devices/iio:device0/in_voltage2_raw
- c_pwm,定义pwm的输入输出配置,主要是基于/sys/class/pwm
安装测试
root@RK3562-Tronlong:~/rkio# python setup.py install
running install
/usr/local/lib/python3.8/dist-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
/usr/local/lib/python3.8/dist-packages/setuptools/command/easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
running bdist_egg
running egg_info
writing Adafruit_RKIO.egg-info/PKG-INFO
writing dependency_links to Adafruit_RKIO.egg-info/dependency_links.txt
writing top-level names to Adafruit_RKIO.egg-info/top_level.txt
file Adafruit_I2C.py (for module Adafruit_I2C) not found
reading manifest file 'Adafruit_RKIO.egg-info/SOURCES.txt'
writing manifest file 'Adafruit_RKIO.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-aarch64/egg
running install_lib
running build_py
file Adafruit_I2C.py (for module Adafruit_I2C) not found
file Adafruit_I2C.py (for module Adafruit_I2C) not found
running build_ext
building 'Adafruit_RKIO.GPIO' extension
creating build
creating build/temp.linux-aarch64-cpython-38
creating build/temp.linux-aarch64-cpython-38/source
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/c_pinmux.c -o build/temp.linux-aarch64-cpython-38/source/c_pinmux.o -Wall
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/common.c -o build/temp.linux-aarch64-cpython-38/source/common.o -Wall
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/constants.c -o build/temp.linux-aarch64-cpython-38/source/constants.o -Wall
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/event_gpio.c -o build/temp.linux-aarch64-cpython-38/source/event_gpio.o -Wall
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/py_gpio.c -o build/temp.linux-aarch64-cpython-38/source/py_gpio.o -Wall
creating build/lib.linux-aarch64-cpython-38
creating build/lib.linux-aarch64-cpython-38/Adafruit_RKIO
aarch64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 build/temp.linux-aarch64-cpython-38/source/c_pinmux.o build/temp.linux-aarch64-cpython-38/source/common.o build/temp.linux-aarch64-cpython-38/source/constants.o build/temp.linux-aarch64-cpython-38/source/event_gpio.o build/temp.linux-aarch64-cpython-38/source/py_gpio.o -L/usr/lib -o build/lib.linux-aarch64-cpython-38/Adafruit_RKIO/GPIO.cpython-38-aarch64-linux-gnu.so
building 'Adafruit_RKIO.PWM' extension
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/c_pinmux.c -o build/temp.linux-aarch64-cpython-38/source/c_pinmux.o -Wall
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/c_pwm.c -o build/temp.linux-aarch64-cpython-38/source/c_pwm.o -Wall
source/c_pwm.c: In function 鈥[01mpwm_setup鈥
source/c_pwm.c:535:51: warning: 鈥[01m/period鈥directive output may be truncated writing 7 bytes into a region of size between 1 and 100 [-Wformat-truncation=]
535 | snprintf(period_path, sizeof(period_path), "%s/period", pwm_path);
| ^~~~~~~
In file included from /usr/include/stdio.h:867,
from source/c_pwm.c:25:
/usr/include/aarch64-linux-gnu/bits/stdio2.h:67:10: note: 鈥[01m__builtin___snprintf_chk鈥output between 8 and 107 bytes into a destination of size 100
67 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
source/c_pwm.c:536:55: warning: 鈥[01m/polarity鈥directive output may be truncated writing 9 bytes into a region of size between 1 and 100 [-Wformat-truncation=]
536 | snprintf(polarity_path, sizeof(polarity_path), "%s/polarity", pwm_path);
| ^~~~~~~~~
In file included from /usr/include/stdio.h:867,
from source/c_pwm.c:25:
/usr/include/aarch64-linux-gnu/bits/stdio2.h:67:10: note: 鈥[01m__builtin___snprintf_chk鈥output between 10 and 109 bytes into a destination of size 100
67 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/common.c -o build/temp.linux-aarch64-cpython-38/source/common.o -Wall
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/constants.c -o build/temp.linux-aarch64-cpython-38/source/constants.o -Wall
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/py_pwm.c -o build/temp.linux-aarch64-cpython-38/source/py_pwm.o -Wall
aarch64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 build/temp.linux-aarch64-cpython-38/source/c_pinmux.o build/temp.linux-aarch64-cpython-38/source/c_pwm.o build/temp.linux-aarch64-cpython-38/source/common.o build/temp.linux-aarch64-cpython-38/source/constants.o build/temp.linux-aarch64-cpython-38/source/py_pwm.o -L/usr/lib -o build/lib.linux-aarch64-cpython-38/Adafruit_RKIO/PWM.cpython-38-aarch64-linux-gnu.so
building 'Adafruit_RKIO.ADC' extension
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/c_adc.c -o build/temp.linux-aarch64-cpython-38/source/c_adc.o -Wall
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/common.c -o build/temp.linux-aarch64-cpython-38/source/common.o -Wall
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/constants.c -o build/temp.linux-aarch64-cpython-38/source/constants.o -Wall
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Isource/include/ -I/usr/include/python3.8 -c source/py_adc.c -o build/temp.linux-aarch64-cpython-38/source/py_adc.o -Wall
aarch64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 build/temp.linux-aarch64-cpython-38/source/c_adc.o build/temp.linux-aarch64-cpython-38/source/common.o build/temp.linux-aarch64-cpython-38/source/constants.o build/temp.linux-aarch64-cpython-38/source/py_adc.o -L/usr/lib -o build/lib.linux-aarch64-cpython-38/Adafruit_RKIO/ADC.cpython-38-aarch64-linux-gnu.so
creating build/bdist.linux-aarch64
creating build/bdist.linux-aarch64/egg
creating build/bdist.linux-aarch64/egg/Adafruit_RKIO
copying build/lib.linux-aarch64-cpython-38/Adafruit_RKIO/ADC.cpython-38-aarch64-linux-gnu.so -> build/bdist.linux-aarch64/egg/Adafruit_RKIO
copying build/lib.linux-aarch64-cpython-38/Adafruit_RKIO/GPIO.cpython-38-aarch64-linux-gnu.so -> build/bdist.linux-aarch64/egg/Adafruit_RKIO
copying build/lib.linux-aarch64-cpython-38/Adafruit_RKIO/PWM.cpython-38-aarch64-linux-gnu.so -> build/bdist.linux-aarch64/egg/Adafruit_RKIO
creating stub loader for Adafruit_RKIO/GPIO.cpython-38-aarch64-linux-gnu.so
creating stub loader for Adafruit_RKIO/PWM.cpython-38-aarch64-linux-gnu.so
creating stub loader for Adafruit_RKIO/ADC.cpython-38-aarch64-linux-gnu.so
byte-compiling build/bdist.linux-aarch64/egg/Adafruit_RKIO/GPIO.py to GPIO.cpython-38.pyc
byte-compiling build/bdist.linux-aarch64/egg/Adafruit_RKIO/PWM.py to PWM.cpython-38.pyc
byte-compiling build/bdist.linux-aarch64/egg/Adafruit_RKIO/ADC.py to ADC.cpython-38.pyc
creating build/bdist.linux-aarch64/egg/EGG-INFO
copying Adafruit_RKIO.egg-info/PKG-INFO -> build/bdist.linux-aarch64/egg/EGG-INFO
copying Adafruit_RKIO.egg-info/SOURCES.txt -> build/bdist.linux-aarch64/egg/EGG-INFO
copying Adafruit_RKIO.egg-info/dependency_links.txt -> build/bdist.linux-aarch64/egg/EGG-INFO
copying Adafruit_RKIO.egg-info/top_level.txt -> build/bdist.linux-aarch64/egg/EGG-INFO
writing build/bdist.linux-aarch64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
Adafruit_RKIO.__pycache__.ADC.cpython-38: module references __file__
Adafruit_RKIO.__pycache__.GPIO.cpython-38: module references __file__
Adafruit_RKIO.__pycache__.PWM.cpython-38: module references __file__
creating dist
creating 'dist/Adafruit_RKIO-1.1.0-py3.8-linux-aarch64.egg' and adding 'build/bdist.linux-aarch64/egg' to it
removing 'build/bdist.linux-aarch64/egg' (and everything under it)
Processing Adafruit_RKIO-1.1.0-py3.8-linux-aarch64.egg
removing '/usr/lib/python3.8/site-packages/Adafruit_RKIO-1.1.0-py3.8-linux-aarch64.egg' (and everything under it)
creating /usr/lib/python3.8/site-packages/Adafruit_RKIO-1.1.0-py3.8-linux-aarch64.egg
Extracting Adafruit_RKIO-1.1.0-py3.8-linux-aarch64.egg to /usr/lib/python3.8/site-packages
Adafruit-RKIO 1.1.0 is already the active version in easy-install.pth
Installed /usr/lib/python3.8/site-packages/Adafruit_RKIO-1.1.0-py3.8-linux-aarch64.egg
Processing dependencies for Adafruit-RKIO==1.1.0
Finished processing dependencies for Adafruit-RKIO==1.1.0
root@RK3562-Tronlong:~/rkio#
root@RK3562-Tronlong:~/rkio#
但运行报错
root@RK3562-Tronlong:~/rkio# python ../grovy/LED.py
Traceback (most recent call last):
File "../grovy/LED.py", line 7, in <module>
import Adafruit_RKIO.GPIO as GPIO
ModuleNotFoundError: No module named 'Adafruit_RKIO'
换一种方法安装
root@RK3562-Tronlong:~/rkio# pip install .
Processing /root/rkio
Building wheels for collected packages: Adafruit-RKIO
Building wheel for Adafruit-RKIO (setup.py) ... done
Created wheel for Adafruit-RKIO: filename=Adafruit_RKIO-1.1.0-cp38-cp38-linux_aarch64.whl size=159556 sha256=b86c7ad20525027b4fe92ffdfe31aa757512e92e024ee4038b8bc1ee0cf29206
Stored in directory: /tmp/pip-ephem-wheel-cache-8f5thcwd/wheels/df/ba/e7/4a31d3e204b40ce56db199fdec715d9b504119104db0afba50
Successfully built Adafruit-RKIO
Installing collected packages: Adafruit-RKIO
Successfully installed Adafruit-RKIO-1.1.0
再次运行,说明整个流程已经跑通,接下来就是功能调试了
root@RK3562-Tronlong:~/rkio# python ../grovy/LED.py
___ _
/ __/ | |
\\ \\ ___ ___ ___ __| |
\\ \\ / _ \\ / _ \\ / _ \\ / _ |
__\\ \\| __ | __ | __ | (_| |
\\___ / \\___ \\___ \\___ \\__,_|
___ _ _ _
/ __/ | | | | (_)
\\ \\ _| |_ _ _ __| | _ ___
\\ \\ |_ _| | | |/ _ | | | / _ \\
__\\ \\ | |_| |_| | (_| | | || (_) |
\\___ / |___/\\__,_|\\__,_| |_| \\___/
LED is On.
LED is Off.
LED is On.
LED is Off.
LED is On.
LED is Off.
LED is On.
Traceback (most recent call last):
File "../grovy/LED.py", line 20, in <module>
time.sleep(1)
KeyboardInterrupt