In this tutorial, we'll use the TDFA50507 or TDFA50607 USB digital output board to control seven output channels from a Raspberry Pi.
Both boards let you switch digital outputs over USB. For example, running a command with set 1 turns on output 1. The USB interface is electrically isolated from the output circuitry, making these boards well suited to prototyping with industrial signal lines.
We'll start without connecting any external equipment and use the onboard LEDs to verify the output states. At the end, we'll also cover the basic wiring required to connect an external device.
TDFA50507 vs. TDFA50607
The two boards use nearly identical commands. The main difference is the type of output they provide.
| Product | Output type | Maximum output current | TD-USB model identifier |
|---|---|---|---|
| TDFA50507 | Current-sinking output | 80 mA per channel | tdfa50507 |
| TDFA50607 | Current-sourcing output | 100 mA per channel | tdfa50607 |
The TDFA50507 provides current-sinking, or low-side, outputs: it switches the negative side of the load. The TDFA50607 provides current-sourcing, or high-side, outputs: it supplies voltage to the positive side of the load.
Although the wiring differs when you connect external equipment, both boards are controlled from the Raspberry Pi in the same way.
What You'll Need
| Item | Description |
|---|---|
| Raspberry Pi with an operating system installed | A Raspberry Pi running Raspberry Pi OS, with access to a terminal |
| TDFA50507 or TDFA50607 | Seven-channel USB digital output board |
| TDAC-USB2B1M5 USB cable | Connects the Raspberry Pi to the output board |
| Internet connection | Required to install tools and download the source code |
| 12–24 V external power supply | Powers the output circuitry for the LED test and when driving external equipment |
| Hookup wire | Required when connecting the external power supply or other equipment |
For the main walkthrough, we'll leave external equipment disconnected and monitor the output states using the board's LEDs. External-device wiring is covered later in the article.
Install the Prerequisites
First, update the software on your Raspberry Pi and install the required development tools and libraries.
sudo apt update && sudo apt upgrade -y
sudo apt install -y git build-essential libusb-dev python3
Configure USB Permissions
To access the TDFA50507 or TDFA50607 as a regular user, create a udev rule that grants permission to the USB device.
Run the following command to create the rule. 32ee is the Tokyo Devices vendor ID. The product IDs are 1771 for the TDFA50507 and 1784 for the TDFA50607.
sudo tee /etc/udev/rules.d/99-usb-tokyodevices.rules <<EOF
SUBSYSTEM=="usb", ATTR{idVendor}=="32ee", ATTR{idProduct}=="1771", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="32ee", ATTR{idProduct}=="1784", MODE="0666"
EOF
Reload the rules and apply them:
sudo udevadm control --reload-rules
sudo udevadm trigger
Now connect the board to your Raspberry Pi with the USB cable. If it was already connected, unplug it and plug it back in so the new rule takes effect.
Build the TD-USB Command-Line Tool
We'll control the board with TD-USB, the official command-line utility. Clone the source code from GitHub and build it:
git clone https://github.com/tokyodevices/td-usb.git
cd td-usb
make
Confirm that the tool runs:
./td-usb
# If version information appears, the build was successful.
Next, check that TD-USB can detect the board. Run the command for your model.
For the TDFA50507:
./td-usb tdfa50507 list
XXXXXXXXXXXXXX
For the TDFA50607:
./td-usb tdfa50607 list
XXXXXXXXXXXXXX
If the board's serial number appears, the Raspberry Pi has detected it successfully.
Power the Output Side for the LED Test
The output circuitry requires an external 12–24 V power supply even when you are only checking the onboard LEDs. Do not connect any external equipment yet.
For the TDFA50507, connect the power supply as follows:
Power supply + → TDFA50507 Common Plus
Power supply − → TDFA50507 Common Minus
For the TDFA50607, connect the positive side of the supply to Common Plus:
Power supply + → TDFA50607 Common Plus
The TDFA50607 does not have a Common Minus terminal. For this LED-only test, leave the negative side of the power supply disconnected from the board. The wiring for the negative side when using an external device is explained later.
Turn Output 1 On and Off
Let's start by switching output 1 from the command line. Keep external equipment disconnected and watch the corresponding LED on the board.
For the TDFA50507:
./td-usb tdfa50507 set 0
./td-usb tdfa50507 set 1
./td-usb tdfa50507 get
1
./td-usb tdfa50507 set 0
For the TDFA50607:
./td-usb tdfa50607 set 0
./td-usb tdfa50607 set 1
./td-usb tdfa50607 get
1
./td-usb tdfa50607 set 0
The set 1 command turns on output 1. If its onboard LED lights up, the test was successful. The final set 0 command turns all outputs off.
How Output Channels Map to Values
The TDFA50507 and TDFA50607 represent the state of all seven outputs as a single integer. Each bit corresponds to one output channel.
| Output state | Binary representation | Value |
|---|---|---|
| All outputs off | 0000000 | 0 |
| Output 1 only | 0000001 | 1 |
| Output 2 only | 0000010 | 2 |
| Outputs 1 and 2 | 0000011 | 3 |
| Output 3 only | 0000100 | 4 |
| Output 7 only | 1000000 | 64 |
| All outputs on | 1111111 | 127 |
For example, use the value 3 to turn on outputs 1 and 2 at the same time.
For the TDFA50507:
./td-usb tdfa50507 set 3
./td-usb tdfa50507 get
3
./td-usb tdfa50507 set 0
For the TDFA50607:
./td-usb tdfa50607 set 3
./td-usb tdfa50607 get
3
./td-usb tdfa50607 set 0
Run set 0 when you are finished to return all outputs to the off state.
Blink an Output with Python
Next, we'll call td-usb from Python to toggle output 1 once per second.
Inside the td-usb directory, create a file named blink_output.py with the following code. Uncomment only the MODEL assignment for the board you are using.
#!/usr/bin/env python3
import subprocess
import time
# Enable only one of the following lines for your board.
MODEL = 'tdfa50507' # TDFA50507
# MODEL = 'tdfa50607' # TDFA50607
def set_outputs(value):
subprocess.run(['./td-usb', MODEL, 'set', str(value)], check=True)
print('Toggling output 1. Press Ctrl+C to stop.')
try:
while True:
set_outputs(1)
print('Output 1: ON')
time.sleep(1)
set_outputs(0)
print('Output 1: OFF')
time.sleep(1)
except KeyboardInterrupt:
set_outputs(0)
print('\nAll outputs are now off. Exiting.')
Run the Script
$ python3 blink_output.py
Toggling output 1. Press Ctrl+C to stop.
Output 1: ON
Output 1: OFF
Output 1: ON
Output 1: OFF
If the LED for output 1 turns on and off once per second, the script is working. Press Ctrl+C to stop it. The interrupt handler sets the output value to 0, ensuring that all channels are turned off before the script exits.
Connecting External Equipment
This section provides the basic wiring for driving an external device. The output side of the board requires a 12–24 V external power supply; USB power alone cannot supply an output signal to external equipment.
Disconnect power from the Raspberry Pi and the external supply before making or changing any wiring. Also note that the TDFA50507 and TDFA50607 use transistor outputs, not relay contacts. Do not connect a load that exceeds the maximum current rating per channel, and do not drive high-current loads such as motors directly from the board.
TDFA50507 Wiring
The TDFA50507 has current-sinking outputs. In other words, it switches the negative side of the external device.
To connect a device to output 1, wire it as follows:
Power supply + → TDFA50507 Common Plus
Power supply − → TDFA50507 Common Minus
Power supply + → Positive terminal of the external device
Negative terminal of the external device → TDFA50507 output 1
With this wiring, running ./td-usb tdfa50507 set 1 turns on output 1 and allows current to flow through the external device.
TDFA50607 Wiring
The TDFA50607 has current-sourcing outputs. Each output supplies voltage to the positive side of the external device. The signal supply voltage is 12–24 V.
To connect a device to output 1, wire it as follows:
Power supply + → TDFA50607 Common Plus
TDFA50607 output 1 → Positive terminal of the external device
Negative terminal of the external device → Power supply −
With this wiring, running ./td-usb tdfa50607 set 1 makes output 1 supply a signal to the positive side of the external device.
On either board, leave unused terminals—and any terminal marked No Connection—unconnected.
Conclusion
You have now used a Raspberry Pi with the TDFA50507 or TDFA50607 to control seven digital output channels from both the command line and Python.
Once you have verified the output states with the onboard LEDs, you can connect external equipment and start controlling real 12–24 V signals. Remember that the TDFA50507 provides current-sinking outputs, while the TDFA50607 provides current-sourcing outputs, so always double-check the wiring for your board before applying power.



