WiringLMK (中文)
简介 (Introduction)
WiringLMK是LeMaker专门为其单板计算机开发的GPIO控制库,基于Gordon Henderson的WiringPi项目。该库为Banana Pi、Banana Pro和LeMaker Guitar提供了简单易用的GPIO编程接口。WiringLMK支持C语言和Python绑定,使开发者能够轻松控制GPIO引脚、I2C总线、SPI接口和PWM输出。本页面提供中文概述和详细的英文技术文档。
安装 (Installation)
WiringLMK可以从LeMaker的GitHub仓库获取源代码并编译安装。在LeMaker板上打开终端,依次执行以下命令:git clone https://github.com/LeMaker/WiringLMK.git,然后进入目录 cd WiringLMK,最后运行 sudo ./build 完成编译和安装。安装完成后,使用 gpio -v 命令验证安装是否成功。该命令会显示WiringLMK的版本信息和检测到的板型。
Installation (English)
Clone the WiringLMK repository from GitHub onto your LeMaker board: git clone https://github.com/LeMaker/WiringLMK.git. Enter the directory with cd WiringLMK and build the library with sudo ./build. The build script compiles the library, installs shared objects to /usr/local/lib, headers to /usr/local/include, and the gpio command-line utility to /usr/local/bin. Verify the installation by running gpio -v which displays the version and detected board type. If building on a fresh system, ensure build-essential and git are installed first with sudo apt-get install build-essential git.
API Overview
WiringLMK provides a comprehensive set of functions for GPIO control. The core setup functions determine pin numbering mode: wiringPiSetup() uses WiringLMK sequential numbering, wiringPiSetupGpio() uses the kernel GPIO numbering, and wiringPiSetupPhys() uses physical header pin numbers. After setup, use pinMode(pin, mode) to configure a pin as INPUT, OUTPUT, or PWM_OUTPUT. Digital I/O is handled by digitalRead(pin) which returns HIGH or LOW, and digitalWrite(pin, value) which sets a pin HIGH or LOW. For analogue operations, analogRead(pin) reads from ADC channels where available.
Pin Numbering
WiringLMK supports three pin numbering schemes to accommodate different programming preferences. The WiringPi numbering assigns sequential integers starting from 0 to GPIO pins in a convenient order. The GPIO numbering uses the Linux kernel's GPIO numbers which correspond to the SoC's internal pin identifiers. The physical numbering uses the actual pin position on the board's GPIO header. Use the gpio readall command to display a comprehensive table mapping all three numbering schemes for every pin on your specific board. This table is invaluable during hardware development and debugging.
核心函数 (Core Functions)
以下是WiringLMK最常用的核心函数列表:pinMode(pin, mode) 设置引脚模式(输入、输出或PWM);digitalWrite(pin, value) 设置引脚高低电平;digitalRead(pin) 读取引脚状态;analogRead(pin) 读取模拟值;pwmWrite(pin, value) 设置PWM输出值(范围0-1023);pullUpDnControl(pin, pud) 配置内部上拉或下拉电阻。这些函数与原版WiringPi保持API兼容。
Example Programs
The following C example blinks an LED connected to WiringLMK pin 0. Include the header with #include <wiringPi.h>. In the main function, call wiringPiSetup() to initialise the library, then pinMode(0, OUTPUT) to set pin 0 as output. In a loop, alternate between digitalWrite(0, HIGH) and digitalWrite(0, LOW) with delay(500) between each call for a half-second blink interval. Compile the program with gcc -o blink blink.c -lwiringPi and run with sudo ./blink. Root privileges are required for direct GPIO access.
Python Bindings
WiringLMK includes Python bindings for rapid prototyping. Install the Python module from the WiringLMK repository's python directory with sudo python setup.py install. Import the module with import wiringpi. The Python API mirrors the C library: wiringpi.wiringPiSetup() for initialisation, wiringpi.pinMode(0, 1) to set output mode, and wiringpi.digitalWrite(0, 1) to set a pin high. Python bindings are particularly useful for interactive testing in the Python REPL and for integration with other Python libraries for sensors, displays, and web frameworks.
Command-Line GPIO Utility
The gpio command-line tool installed with WiringLMK enables GPIO control without writing code. Use gpio mode 0 out to set a pin as output and gpio write 0 1 to set it high. Read a pin with gpio read 0. The gpio readall command displays the complete pin mapping table showing all pins, their current modes, values, and all numbering schemes. This tool is ideal for quick hardware testing, shell scripting, and verifying physical connections before writing application code.
相关页面 (Related Pages)
WiringPi英文文档请参阅 WiringPi。引脚定义详情请参阅 Pin Definition。For the complete English WiringPi documentation, visit the WiringPi wiki page.
Author: LeMaker Documentation Team
Last updated: 2026-02-10