Python

Python is the main language used with AI and data science. For example, an AI vision facial recognition can now control a door lock.

The provided DUELink Python library allows a full standard Python program to access the physical world.
Note that Python will be executed on a compatible supported hardware option, which is tethered to DUELink modules. Python does not run on the module itself! The Standalone page shows some options that run on modules directly.
Setup
For the module, visit loader.duelink.com to make sure your hardware has the latest DUElink Official firmware and related module drivers.
We assume that you are already familiar with Python and your development machine is already setup to build and run Python programs.
Start a new project with a simple line of code to test that the project is running.
print("Hello DUELink!")
We now need to install the DUELink Python library using pip install DUELink (or python -m 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 only supports serial ports, which can be either UART or USB. The GetConnectionPort() function scans for a USB-connected DUELink module. The returned value can be used to start DUElinkController(). If serial port is used then use the actual port number, which for example can be DUELinkController("COM6") on Windows and DUELinkController("/dev/ttyAMA0") on Linux. Using serial is useful with wireless Bluetooth connections.
Daisylinking
DUELink modules can be Daisylinked together. The duelink.Engine.Select() function is used to select the module to be listening to incoming commands.
In the example below, we'll use Python to control an OLED Display, a Button, and a Buzzer.

Visit loader.duelink.com to "discover" modules and load the latest firmware and 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
Code Samples
Individual product pages include specific code samples that utilize the module's Driver Script.
See Tethered Samples under individual module pages.