Introduction
The pinpong library is an open-source python library that is based on the firmata protocol and utilizes micropython syntax. Its primary objective is to provide developers with a tool that allows them to directly control various open-source hardware control boards through Python code.
Usage
Pin numbers
Duo
pinpong | PIN NAME | Pin# | Pin# | PIN NAME | pinpong |
---|---|---|---|---|---|
0 | GP0 | 1 | 40 | VBUS | |
1 | GP1 | 2 | 39 | VSYS | |
GND | 3 | 38 | GND | ||
2 | GP2 | 4 | 37 | 3V3_EN | |
3 | GP3 | 5 | 36 | 3V3(OUT) | |
4 | GP4 | 6 | 35 | ||
5 | GP5 | 7 | 34 | ||
GND | 8 | 33 | GND | ||
6 | GP6 | 9 | 32 | GP27 | 27 |
7 | GP7 | 10 | 31 | GP26 | 26 |
8 | GP8 | 11 | 30 | RUN | |
9 | GP9 | 12 | 29 | GP22 | 22 |
GND | 13 | 28 | GND | ||
10 | GP10 | 14 | 27 | GP21 | 21 |
11 | GP11 | 15 | 26 | GP20 | 20 |
12 | GP12 | 16 | 25 | GP19 | 19 |
13 | GP13 | 17 | 24 | GP18 | 18 |
GND | 18 | 23 | GND | ||
14 | GP14 | 19 | 22 | GP17 | 17 |
15 | GP15 | 20 | 21 | GP16 | 16 |
25 | GP25 | LED |
Pinmux
Many of Duo's pins have multipurpose functionality. When using pinpong library to control the functions of each pin, it is important to confirm the current state of the pin to ensure it matches the desired functionality. If it doesn't, you can use the duo-pinmux
command to switch it to the desired function
Please refer to the instructions: pinmux
GPIO
Onboard LED blinking
This is an example to blink the Duo's onboard LED. You can create a new file blink.py
directly in Duo, or create it on your computer and upload it to Duo via SSH.
The Duo LED pin number is 25. If you use other pins to connect an external LED, please refer to the table above for the number.
Contents of the file blink.py
:
# -*- coding: utf-8 -*-
# 实验效果:控制 MilkV-Duo 板载 LED 灯一秒闪烁一次。
# Function: Control the MilkV-Duo onboard LED light to flash once per second.
# 接线:使用电脑连接一块 MilkV-Duo 主控板。
# Wiring: Use a computer to connect a MilkV-Duo board.
# 在启动程序前请使用 duo-pinmux 确认引脚复用在正确的功能上。
# Please use duo-pinmux to confirm that the pins are multiplexed to the correct functions before starting the program.
import time
from pinpong.board import Board,Pin
Board("MILKV-DUO").begin() # 初始化,选择板型 ,不输入板型则进行自动识别;Initialize, select the board type, if you do not enter the board type, it will be automatically identified.
led = Pin(Pin.D14, Pin.OUT) # 引脚初始化为电平输出;The pin is initialized as output.
while True:
led.value(1) # 输出高电平;Output High.
print("1")
time.sleep(1) # 等待1秒 保持状态;Stay 1s.
led.value(0) # 输出低电平;Output Low.
print("0")
time.sleep(1) # 等待1秒 保持状态;Stay 1s.
Execute the command python blink.py
in the Duo terminal:
[root@milkv-duo]~# python blink.py
milkv-duo
__________________________________________
| ____ _ ____ |
| / __ \(_)___ / __ \____ ____ ____ _ |
| / /_/ / / __ \/ /_/ / __ \/ __ \/ __ `/ |
| / ____/ / / / / ____/ /_/ / / / / /_/ / |
|/_/ /_/_/ /_/_/ \____/_/ /_/\__, / |
| v0.5.2 Designed by DFRobot /____/ |
|__________________________________________|
1
0
1
0
You will see the LED flashing at 1 second intervals.
The default firmware of the current Duo will automatically blink the LED after power-on. This is achieved by the boot script. When testing the blink example, you need to disable the LED blinking script. Execute in the Duo terminal:
mv /mnt/system/blink.sh /mnt/system/blink.sh_backup && sync
reboot