Skip to main content

Daisylink


Upstream-Downstream

In a DUELink setup, where there are more than one module, there will always be a connection between the Upstream and Downstream sockets. The limit of connected devices is 255 devices. And if you need more, use another Interface to add another 255 devices! Also, each single module in a stream is an active repeater of the signal. There will be no degradation of the signal quality. If necessary, add Power Inject to help with power. Daisylink

Device Selection

The Standard Library offers the Sel() command to activate devices on the stream. To blink the status LED on the second device on the daisylink stream, use Sel(2) followed by statled(200,200,50). The LED will blink 50 times on the second module in the stream.

Daisylinked devices on a stream are addressed from 1. The fourth device on the bus is selected using 'Sel(4)'.

Select

It is possible to select more than one device at once. Let's say we want to select devices 1,3 and 4 Sel(1,3,4)

Multiple Select

Broadcast

Address zero is a special address on the stream, which indicates a broadcast selection. During a broadcast, all modules are required to process the command.

In this example, we have 4 modules connected.

Sending Sel(0) followed by statled(200,200,50) will blink the status LED 50 times on each one of the four modules. It is also possible to read from multiple devices. Sel(0):Print("Hi").

Broadcast

tip

Do not confuse the module address with I2C address. They are unrelated! The module address work the same no matter what Interface is being used.

Device Addressing

When modules power up, they have a NULL interface, and they have no set address yet. Once an Interface is selected, such as USB, then the first device will set its own address to 1 and then command all downstream devices to take a new address, 1, 2, 3, 4...etc.

Use GetAddr() to read the current address. If the current address is zero, then the device has not been enumerated.

Module to Module Commands

DUELink is very flexible that things can get quite nifty! A Button can be programmed to run Standalone, where this button sends commands to control an LED!

Button Controlling LEDs

Cmd() is a special Standard Library command to send a command from the current device to all devices on the downstream. Of course, only devices that were selected using Sel() will respond to commands. Any device in the daisylink can Cmd() but the command will only be sent downstream.

For demonstration, let us assume we have a Raspberry Pi Pico connected using I2C bus to Button, Accelerometer, and CP23 color display. Once Raspberry Pi starts communicating over I2C, the first device (button in this case) will detect the I2C. This first device will set its own address to 1 and then flag a new address protocol to all devices in the stream, resulting in Accelerometer with address 2, and CP23 Display with address 3

RaspberryPI Daisylinked

Assuming the display was selected by the host, where Raspberry Pi Pico sent Sel(3) in this example, any downstream commands will now be processed by the display. Sending Circle(1,20,20,15):Show() from the host, again RPI Pico, will result with a circle on the display. Now, any other modules, like the accelerometer can send similar commands, such as Cmd("Circle(1,40,30,35):Show()"). Of course, the Accelerometer can get is own position and use that move the circle on the display. The button can similarly send Cmd("Clear(0):Show()") to clear the screen.

RaspberryPI Daisylinked

Sending Sel() over Cmd() is supported but can be tricky! The reason is that Sel() is only sent downstream. Going back the previous example, let us assume RPI Pico has elected device 1 Sel(1) (the button) but then the Accelerometer sent Cmd("Sel(3)"") to select the Display. The Sel() command sent by the Accelerometer is only seen by devices on downstream. The display in this case will be selected but so does the button.

All this comes in very handy in Host mode!

Host Mode

Typically, a host is used to command a stream of daisylinked devices. There are several Supported Systems and many supported Languages.

Other Micros

DUELink modules can run Standalone and can also be the host of other daisylinked modules connected on the Downstream socket. The difference here is that the device that is the host, is not part of the stream, it is the host! Use Host() command to activate this mode.

Once activated, the device configures and enumerates the devices downstream, starting with address 1. From this point, the host can address other devices.

Host Mode

Host() # Switch to host mode
Cmd("Sel(2)") # Select second device
Cmd("statled(200,200,50)") # Blink the LED 50 times on the selected device
tip

Since the "host" is not part of the stream, its own address is set to 255, GetAddr() returns 255.

A device in Host() mode is still listening upstream to commands but does not forward the commands downstream. This allows for programming, configuring the host, from DUELink Console for example.