MicroPython
You can use DUELink with any microcontroller that uses MicroPython by connecting a Breakout module to either the I2C or UART output of the board.
MicroPython is very popular on Raspberry Pi microcontroller-level (RP2040/RP2350) boards, such as Raspberry Pi Pico. DuePico is the perfect Raspberry Pi options for connecting directly to DUELink.
We'll use Thonny to program the RaspberryPi Pico directly to control DUELink modules attached to the DuePico'sDownlink connector.
First Make sure your board is set-up for MicroPython. Follow the steps found found at MicroPython.org to load the firmware for your specific hardware.
Connect to the board by going to Tools/Options
and select the proper Interpreter
. In this case we'll be selecting MicroPython(Raspberry Pi Pico)
We can test that everything is working correctly by blinking the Raspberry Pi Pico's onboard LED.
import machine
import time
led = machine.Pin(25, machine.Pin.OUT)
while True:
led.on()
time.sleep(1)
led.off()
time.sleep(1)
Download the duelink-stdlib-mp file found at pypi.org
to you computer. Under Tools/Manage packages
select the downloaded file.
We can now access the complete DUELink standard library from inside Thonny. We need to use UART
to communicate to the modules when using Raspberry Pi Pico. Let's blink the STAT
led on a connected DUELink module.
import time
import machine
import duelink
from duelink import transport
uart = transport.UartTransportController(0)
due = duelink.DUELinkController(uart)
while True:
due.Led.Set(1,0,0)
time.sleep(0.5)
due.Led.Set(0,1,0)
time.sleep(0.5)
Users can also access module drivers using the
You can also use boards that already have a JST connector, like Adafruit QT Py RP2040 or Sparkfun Pro Micro RP2350.
Some boards use I2C vs UART, they also might not use the I2C standard pull-up resistors on the bus. DUELink has a PullUp module to solve this issue.
import time
import machine
import duelink
from duelink import transport
from machine import Pin, Timer
sclPIN = machine.Pin(23)
sdaPIN = machine.Pin(22)
i2c = transport.I2CTransportController(sda=sdaPIN, scl=sclPIN)
due = duelink.DUELinkController(i2c)
while True:
due.Led.Set(1,0,0)
time.sleep(0.5)
due.Led.Set(0,1,0)
time.sleep(0.5)