Python

Python is the main language used with AI and data science. The provided DUELink Python library allows a full standard Python program to access the physical world. For example, an AI vision facial recognition can now control a door lock.
Note that Python will be executed on one of the supported hardware options, which is tethered to DUELink modules. Python does not run on the module itself!
Setup
This page assumes the user is already familiar with Python and there is a development machine that is already setup to build and run Python programs.
Make sure your hardware is updated with the latest firmware. The Console can help with that!
Start a new project with a simple line of code to test that the project is running.
Print("Hello DUELink!")
Libraries
We now need to install the DUELink Python library using pip install DUELink. You may also upgrade the libraries using pip install --upgrade DUELink. The DUELink package will also install all required dependencies.
The DUELink python library requires pySerial, which may require an admin access to install.
Blinky!
Our first program will blink the on-board status LED on a tethered module, on for 200ms then it shuts off for 800ms, and does this 20 times.
from DUELink.DUELinkController import DUELinkController
print("Hello DUELink!")
availablePort = DUELinkController.GetConnectionPort()
print("Using port: ", availablePort)
duelink = DUELinkController(availablePort)
# Flash the LED (on for 200ms, off for 800ms, 20 times)
duelink.System.StatLed(200,800,20)
print("Bye DUELink!")
The Python library is open source: DUELink Libraries Repo.
Daisylinking
In the example below, we'll use Python to control an OLED 0.96 Display, a Button, and a Buzzer module Daisylinked together.

Make sure these modules are pre-loaded with Drivers.
import time
from DUELink.DUELinkController import DUELinkController
availablePort = DUELinkController.GetConnectionPort()
duelink = DUELinkController(availablePort)
# Device 1 is Display OLDE 0.96, with driver installed!
# Device 2 is button
# Device 3 is buzzer
duelink.ReadTimeout = 0.1 # 100 milliseconds
duelink.Engine.Select(1)
duelink.Graphics.Clear(1)
duelink.Graphics.Text("DUELink", 0, 10, 10)
duelink.Graphics.Text("Press button on", 0, 1, 21)
duelink.Graphics.Text("device 2 to play", 0, 1, 31)
duelink.Graphics.Text("sound on device 3", 0, 1, 41)
duelink.Graphics.Show()
duelink.Engine.Select(2)
duelink.Button.Enable(1, 0)
while True:
duelink.Engine.Select(2)
if duelink.Button.Down(1):
duelink.Engine.Select(3)
duelink.Frequency.Write(7, 1000, 50, 0.5)
time.sleep(0.1) # Sleep 100 milliseconds
The earlier samples were generic and run on any module. The individual module's product pages. include specific samples.