Skip to main content

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

pinpongPIN NAMEPin#Pin#PIN NAMEpinpong
0GP0
1
40
VBUS
1GP1
2
39
VSYS
GND
3
38
GND
2GP2
4
37
3V3_EN
3GP3
5
36
3V3(OUT)
4GP4
6
35
5GP5
7
34
GND
8
33
GND
6GP6
9
32
GP2727
7GP7
10
31
GP2626
8GP8
21
30
RUN
9GP9
12
29
GP2222
GND
13
28
GND
10GP10
14
27
GP2121
11GP11
15
26
GP2020
12GP12
16
25
GP1919
13GP13
17
24
GP1818
GND
18
23
GND
14GP14
19
22
GP1717
15GP15
20
21
GP1616
 
25GP25
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 of making the Duo onboard LED blink. You can create a new blink.py file directly in Duo, or create it on your computer and then upload it to Duo via ssh.

tip

The Pin number of the LED is 25. If you use other pins to connect external LEDs, please refer to the table above for the Pin number.

Contents of the blink.py file:

# -*- coding: utf-8 -*-

import time
from pinpong.board import Board,Pin

Board("MILKV-DUO").begin()

led = Pin(Pin.D25, Pin.OUT)

while True:
led.value(1)
print("1")
time.sleep(1)

led.value(0)
print("0")
time.sleep(1)

Execute the python blink.py command in Duo's terminal:

[root@milkv-duo]~# python blink.py
milkv-duo

__________________________________________
| ____ _ ____ |
| / __ \(_)___ / __ \____ ____ ____ _ |
| / /_/ / / __ \/ /_/ / __ \/ __ \/ __ `/ |
| / ____/ / / / / ____/ /_/ / / / / /_/ / |
|/_/ /_/_/ /_/_/ \____/_/ /_/\__, / |
| v0.5.2 Designed by DFRobot /____/ |
|__________________________________________|

1
0
1
0

You will see the LED blinking at 1 second intervals.

Note: To test the blink.py example, which involves LED blinking, you need to disable the script responsible for the automatic LED blinking on the default firmware of Duo. In the Duo terminal, execute the following command:

mv /mnt/system/blink.sh /mnt/system/blink.sh_backup && sync

This command renames the LED blinking script. After restarting Duo, the LED will no longer blink.

Once you have finished testing the blink.py, if you want to restore the LED blinking script, you can rename it back using the following command and then restart Duo:

mv /mnt/system/blink.sh_backup /mnt/system/blink.sh && sync

Other examples

Please refer to: github

  • carbonfix