Guide to the ADP130/ADP102 Isolated DIO Module, covering its features, configuration via shell, and programming.
An optional DIO add-in card is available. The add-in card has an NXP i.MX1050-series microcontroller that can communicate with the host processor over USB. The card provides an interactive shell for configuration on a virtual COM port.
Supported VIN/Input/Output Voltage: 5-48V
Due to the wide variety of potential applications, OnLogic does not supply a mating connector. Below is an example list of connectors compatible with this module.
The add-in card is configured interactively through its shell using a serial terminal emulator program. The shell is accessed differently depending on operating system.
Open Device Manager by pressing Win+X M. Open the “Ports (COM & LPT)” menu.
Note the “COM#” numbers on each port listed.
Download and install PuTTY from the link above.
Open PuTTY. When prompted, enter the COM port number in the “Serial line” text box, then click “Open”.
If the port number was correct, a “uart:~$” prompt should appear. If not, try a different port.
Install picocom, e.g. “sudo apt install picocom” on Ubuntu.
Open the shell’s virtual COM port with picocom by running “picocom /dev/serial/by-id/usb-OnLogic_DIO-*-if00”.
Some Linux distributions may not configure udev to produce by-id links. If those links are missing, try /dev/ttyACM0 and similar devices.
Once the shell is open, type “help” for usage information. A description of available shell commands can also be found .
While the microcontroller shell is intended for human interaction, it can be used to programmatically control the MCU. To avoid a number of pitfalls when doing so, observe the following best practices:
On Linux, use the symlinked device nodes inside /dev/serial/by-id instead of hardcoding /dev/ttyACMx device names. /dev/ttyACMx numbering is
unstable; /dev/serial/by-id/usb-OnLogic_<device>-if00 will reliably point to the terminal interface.
When writing Linux shell scripts, ensure that the echo flag is disabled on the TTY by running stty -F /dev/serial/by-id/<device> -echo
External Connector Pinout - Note the key notch at pins 7 & 9
Digital Input (Active-Low)
Digital Input (Active-High)
Digital Output (Low-Side/Sinking)
interacting with the shell. Most serial libraries (pyserial, serialport-rs, etc.) will automatically disable this flag.
When sending a command, precede it with a ‘\x03’ byte to clear the terminal’s line buffer and ensure that the command is interpreted correctly. Follow the command with a ‘\r’ or ‘\n’ character to execute the command.
Send less than 64 bytes at a time. To send longer commands, explicitly flush the port’s output buffer in between each block of 64 bytes.





Guide to using the OnLogic ADP120/ADP102 Isolated DIO module, covering features, wiring, application interface, and sample Python code
The OnLogic ADP120/ADP102 provides isolated digital inputs and outputs for safe external signal control. The adapter USB interface and wide input voltage range offer enhanced versatility. The onboard ARM processor allows for fast, reliable operation independent of host system.
Systems from 2021 or older may use the ADP102, instead of the ADP120. These are functionally identical except for the hardware ID of the device. If you’re not sure which device you have, you can check for the following hardware IDs to confirm:
1FC9:0094 = ADP120
15A2:0300 = ADP102
Due to the wide variety of potential applications, OnLogic does not supply a mating connector. Below is an example list of connectors compatible with this module.
Isolated Digital Input/Output
Four Inputs, 0-16V (2.5V HIGH), dry contact
Four Outputs, 50mA, open collector
Keyed 2.54mm connector
IO Isolation to 3750 Volts (*Rated, not tested)
The header is 2×8 pins, 2.54mm pitch, with shroud and key
For mating connector, use Wurth Electronics 61201623021 or similar.
Digital inputs are triggered by the flow of a small amount (1-2mA) of current through DI. Current is limited, and correct polarity is ensured by the ADP/120/ADP102’s built-in protection circuit. A request for DI state will report active when the voltage at DI exceeds 2.5 V.
Digital outputs switch a circuit in series after the device they control (represented by LOAD). Each output is rated for 50mA. If more than 50mA are required, DO may be used to trigger a relay driving LOAD instead.
The ADP120/ADP102 provides a standard USB-CDC (USB-serial) interface. To determine the COM port number, check device manager or equivalent for the COM device. A developer may employ any serial-compatible software library in order to communicate with the ADP120/ADP102. Available commands are outlined below. After the execution of any command, a response is returned by the ADP120/ADP102 containing any requested data. For commands that do not return a value, a success/failure code is returned instead.
Each command is comprised of a start character, length (not including the start character), 1-byte pin address, 2-byte command ID, and (optional) data. For example, to set the state of digital output 3 to ‘ON’, the command packet is:
After executing each command, the ADP120/ADP102 issues a response containing data the command generated (if any) and a success code. The first two bytes of a response packet are the incoming command code that generated the response OR’d with 0x8000, followed by the pin number requested and any relevant data. The packet is completed by the same carriage return delimiter as the command packet.
For example, a response to the ‘Get input status’ command looks like this:
The ADP120/ADP102 may also be configured to send a report to the host system whenever an input changes state, or a counter overflows (reaches the maximum value of 2^32 and resets). These reports are formatted as responses to the input “Get State” command (0x8101 [Address] [State] 0x13). They may be enabled or disabled via their respective configuration bits in each pin’s configuration.
Simple-to-program USB-serial interface
Onboard ARM Cortex-M0 processor
Latches and 32-bit counters for inputs
''' Example usage of the ADP120 DIO expansion card '''
import sys
from time import sleep
import functools
from serial import Serial # python -m pip install pyserial
# Detecting serial port
import serial.tools.list_ports as system_ports
def get_device_port() -> str:
''' Scans system to detect device CDC ACM port '''
all_ports = system_ports.comports()
for port, _, hwid in sorted(all_ports):
if "1FC9:0094" in hwid:
# Replace with "15A2:0300" if using ADP102
# Fix for windows COM ports above 10
if 'win' in sys.platform:
return "\\\\.\\" + port
else:
return port
return None
class PinConfig:
''' Pin configuration; used to set or report a pin config
PARAMETERS:
state_change: Report to host when pin state has changed
counter_overflow: Report to host when pin counter has overflown
counter_polarity:
latch_polarity:
starting_state: Initial pin state
enable: Enable/disable pin
'''
def __init__(self, state_change=False, counter_overflow=False, counter_polarity=0, latch_polarity=0,
starting_state=0, enabled=True):
self.state_change = state_change
self.counter_overflow = counter_overflow
self.counter_polarity = counter_polarity
self.latch_polarity = latch_polarity
self.starting_state = starting_state
self.enabled = enabled
def bytes(self):
nbytes = [0x00, 0x00, 0x00, 0x00]
if self.state_change:
nbytes[2] |= 0x02
if self.counter_overflow:
nbytes[2] |= 0x01
if self.enabled:
nbytes[3] |= 0x01
if self.starting_state:
nbytes[3] |= 0x04
if self.latch_polarity:
nbytes[3] |= 0x40
if self.counter_polarity:
nbytes[3] |= 0x80
return bytes(nbytes)
@staticmethod
def from_bytes(nbytes):
nbytes = list(nbytes)
config = {
'state_change': True if nbytes[2] & 0x02 else False,
'counter_overflow': True if nbytes[2] & 0x01 else False,
'enabled': True if nbytes[3] & 0x01 else False,
'starting_state': True if nbytes[3] & 0x04 else False,
'latch_polarity': True if nbytes[3] & 0x40 else False,
'counter_polarity': True if nbytes[3] & 0x80 else False,
}
return PinConfig(**config)
class ADP120(Serial):
''' Subclass serial with ADP120 specific commands '''
START = b'\x24'
END = b'\x00\x80\x01'
COMMANDS = {
'model': b'\x00\x00\x01',
'serial': b'\x00\x00\x03',
'read_state': b'\x01\x01',
'read_latch': b'\x01\x02',
'read_count': b'\x01\x03',
'clear_latch': b'\x01\x04',
'clear_count': b'\x01\x05',
'toggle_output': b'\x01\x09',
'save_config': b'\x00\x06',
}
def __init__(self, *args, **kwargs):
''' Initialize serial device; set port timeout if missing '''
if 'timeout' not in kwargs:
kwargs['timeout'] = 5
if 'write_timeout' not in kwargs:
kwargs['write_timeout'] = 0
super(ADP120, self).__init__(*args, **kwargs)
def command(self, cmd: bytes, adr=None) -> bytes:
''' Send and ADP120.COMMAND to the hardware device '''
if adr is None:
return self.write_command_raw(cmd)
else:
return self.write_command_raw(bytes([adr]) + cmd)
def read_response(self) -> bytes:
''' Read the response to a command '''
r = self.read(1)
if r == self.START:
rlen = self.read(1)
return self.read(ord(rlen) - 1)[3:]
else:
sleep(0.01)
return self.read(self.in_waiting)
def write_command_raw(self, cmd: bytes) -> bytes:
''' Write the raw bytes to the serial device '''
# Raw command
raw = self.START + bytes([len(cmd) + 1]) + cmd
# Write the command
count = self.write(raw)
# Check whole command was written
if count != len(raw):
return None
# Get the response
reply = self.read_response()
return reply
def write_config(self, address, config):
''' Configure a pin '''
return self.write_command_raw(bytes([address]) + b'\x00\x05' + config.bytes())
def read_config(self, address):
config = self.write_command_raw(bytes([address]) + b'\x00\x04')
return PinConfig.from_bytes(config)
def write_output(self, address, state):
return self.write_command_raw(bytes([address]) + b'\x01\x08' + bytes([state]))
# Support ADP120.model() syntax
def __getattr__(self, name):
cmd = self.COMMANDS.get(name)
if cmd is None:
raise AttributeError(name)
else:
result = functools.partial(self.command, cmd)
return result
if __name__ == "__main__":
port_name = get_device_port()
# Detect the ADP120 module
if port_name is None:
print("Failed to detect device!")
sys.exit(-1)
adp = ADP120(port_name)
# Report model and firmware version
print(f"Model: {adp.model()}")
# Read input and output states
for i in range(0, 8):
print(f"{'Input' if i < 4 else 'Output'} {i if i < 4 else i - 4} State: {adp.read_state(i)}")
# Read the config of output 0
cfg = adp.read_config(4)
print(f"Output 0:\n Starting state: {cfg.starting_state}\n Enabled: {cfg.enabled}")
# Toggle the starting state, and enable the port
cfg.starting_state = False if cfg.starting_state else True
cfg.enabled = True
adp.write_config(4, cfg)
cfg = adp.read_config(4)
print(f"Output 0:\n Starting state: {cfg.starting_state}\n Enabled: {cfg.enabled}")
# Write an output and confirm it worked
adp.write_output(4, 1)
print(f"Current State: {adp.read_state(4)}")








Guide to the MOD110 Isolated DIO Module, detailing its DIO, CAN, PWM, and QEP features, and control via the Hardware Control Application.
The (optional) MOD110 digital input/output (DIO) expansion adds up to eight digital inputs and outputs to the system, and an additional CAN port. It also optionally provides support for pulse width modulation (PWM) on three of the eight digital output pins, and support for using a quadrature encoder peripheral (QEP) in place of the first and/or second group of three digital inputs.
The isolated digital inputs/outputs are enabled by default, and require an external power source (9 ~ 48 VDC) in order to operate.
The outputs function as open-drains, and should not be used to source more than 150mA of current. The input of the DIO are pulled high when floating.
The additional CAN device supported by the MOD110 DIO Module supports CAN 2.0 A/B at bitrates from 100000 to 1000000. The CAN device is not internally terminated, so a properly terminated CAN cable should be used when connecting to the device.
Digital outputs 0, 1, and 2 can be optionally configured to operate in PWM mode. This configuration is performed in the system UEFI BIOS (Setup Menu > Advanced > OnLogic Feature Configuration).
The frequency of the PWM is limited by the switching speed of the isolating optocouplers to 10KHz.
Groups of digital inputs (0, 1, 2 and 3, 4, 5) can be optionally configured to operate as a QEP (Quadrature Encoder Peripheral). This configuration is performed in the system UEFI BIOS (Setup Menu > Advanced > OnLogic Feature Configuration).
Interfaces on the MOD110 DIO Module are managed of the system’s Host Embedded Controller Interface (HECI). Installing the system Windows driver for this interface is a required prerequisite to using the MOD110, and it can be found as part of the HX310/K400’s .
On Linux systems, see for driver installation instructions.
Once the driver is installed, the MOD110 can be controlled programmatically over the HECI connection, or by using the provided hardware control command line application.
Make sure your system’s drivers are installed and up-to-date
Sample code (in C) is also available for . Windows sample code is not currently available.
The hardware control application can be used to read and write the states of the digital outputs and inputs.
Additionally, digital-inputs track the number of signal edges detected since device power-on; this count can be reported and cleared by the command line interface:
Contextual help information is also available in the application:
The hardware control application support reading and writing CAN frames, as well as enabling/disabling the device.
NOTE The MOD110’s CAN device is referenced as device one (-d 1) the onboard CAN is device zero (-d 0).
Contextual help information is also available in the application:
The PWM supports starting/stopping output, as well as setting the period and pulse of the PWM signal.
In-application help is also available:
The Quadrature Encoder Peripheral supports a number of configurations and commands, including setting the edge trigger type, index gating, and switching between edge capture and decoder mode:
Interfacing with the HECI driver requires elevated permissions on both Windows and Linux. The commands in this guide should be run from an elevated command prompt.
The hardware control application supports verbose debug output:
$ hwc.exe -v debug dio read digital-input 0
Capturing this output is helpful if you’re reaching out to OnLogic for support with an issue using your hardware.
v1.2.1
10/11/2023
Program must run as administrator in CMD
Fixes issue with Version-Check warning. * Note that the CAN baudrate is fixed at 1M. Please see our C-Based PSE-Examples for setting the baudrate programmatically.
# Set digital output 0
$ hwc.exe dio set digital-output 0
# Clear digital output 0
$ hwc.exe dio clear digital-output 0# Read the state of a digital input
$ hwc.exe dio read digital-input 0# Clear the toggle-count of a digital input
$ hwc.exe dio clear-count digital-input 0$ hwc.exe dio --help
Read and write digital IO states
Set outputs, read both inputs and outputs.
USAGE:
hwc.exe dio <action> <kind> <pin>
FLAGS:
-h, --help
Prints help information
-V, --version
Prints version information
ARGS:
<action>
Kind of action to take on the IO pin [possible values: ...]
<kind>
The type of IO device to target [possible values: ...]
<pin>
Hardware pin number used by this operation# Set the device baudrate to 500000
$ hwc.exe can -d 1 set-baudrate 500
# Enable the can device
$ hwc.exe can -d 1 enable
# Send a message
$ hwc.exe can -d 1 write 1FF 3 -- 11 22 33
# Receive a message
$ hwc.exe can -d 1 read$ hwc.exe can --help
Control system CAN devices
Send and receive messages, set the system baudrate, and report status
USAGE:
hwc.exe can [OPTIONS] <action> [msg-id] [length] [-- <data>...]
FLAGS:
-h, --help
Prints help information
-V, --version
Prints version information
OPTIONS:
-b, --baudrate <baudrate>
Set the CAN baudrate from 100 - 1000 kbaud [default: 500]
-d, --device <device>
The CAN device to target, if the interface has more than one [default: 0]
-f, --frame-type <frame-type>
Select if this frame is Standard or Remote [default: standard] [possible values: standard, remote]
-i, --id-type <id-type>
CAN ID format specifier. IDs greater that 0x7FF should be sent as extended, or they will be truncated
[default: standard] [possible values: standard, extended]
ARGS:
<action>
CAN action to perform [possible values: read, write, enable, disable, set-baudrate, status-report, status-
clear]
<msg-id>
The ID of a CAN message, must be <0x7FF for standard frames and <0x1FFFFFFF for extended frames [default: 0]
<length>
The length of this CAN message, 0 - 8 If length is greater than the number of provided bytes, they will be
filled with 00 [default: 8]
<data>...
Can data vector, up to eight bytes in length [default: 00]# Set the pwm signal behavior
$ hwc.exe set-cycles --period 1000000 --pulse 500000
# Start the pwm output
$ hwc.exe pwm start
# Stop the pwm output
$ hwc.exe pwm stop$ hwc.exe pwm --help
Control system PWM devices
USAGE:
hwc.exe pwm [OPTIONS] <action> <device>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-t, --period <period> Period, in microseconds [default: 0]
-p, --pulse <pulse> Pulse, in microseconds [default: 0]
ARGS:
<action> Kind of action to take on the pwm device [possible values: start, stop, set-cycles]
<device> The PWM device to target on this controller$ hwc.exe qep --help
Control system QEP (Encoder) peripherals
USAGE:
hwc.exe qep [FLAGS] [OPTIONS] <action>
FLAGS:
-h, --help
Prints help information
--swap-inputs
Swap the Phase A and Phase B inputs
-V, --version
Prints version information
OPTIONS:
-c, --counter-reset <counter-reset>
Select which event will cause a reset of the encoder position counter [default: max-count] [possible
values: max-count, index-event]
-a, --data <data>
Data returned from/ sent to a QEP command. Zero if the command does not return a data value
GetDirection: The direction based on the last change event
0: Clockwise, 1: Counter-Clockwise, 2: Unknown
GetPositionCount: The current position count
StartCapture: The number of edges to capture
GetPhaseError: Whether or not a phase error has been detected [default: 0]
-d, --device <device>
The QEP device to interface with, if the controller has more than one [default: 0]
-g, --edge-type <edge-type>
Edge to trigger capture events on in edge capture mode [default: rising] [possible values: rising, falling,
both]
-e, --event <event>
QEP Event to enable or disable Only used when calling 'enable event' or 'disable event' [default: unknown]
[possible values: watchdog-timeout, counter-reset-up, counter-reset-down, direction-change, phase-error,
edge-capture-done, edge-capture-cancelled, unknown]
-f, --filter-width <filter-width>
The noise filter width in nanoseconds. Set to 0 to disable noise filtering [default: 0]
-i, --index-gating <index-gating>
Select the system index gating, which effects the counter reset in index-event mode [default: a-low-b-low]
[possible values: a-low-b-low, a-low-b-high, a-high-b-low, a-high-b-high]
-m, --mode <mode>
Select encoder or edge-capture QEP operation [default: decoder] [possible values: decoder, edge-capture]
-p, --pulses-per-rev <pulses-per-rev>
The number of pulses per revolution in quadrature decoder mode [default: 0]
-w, --watchdog-timeout <watchdog-timeout>
The watchdog timeout in microseconds. The QEP watchdog will trigger an event on stalls when operating in
decoder mode
Set as zero to disable the watchdog [default: 0]
ARGS:
<action>
Kind of action to take on the qep device [possible values: configure, start-decode, stop-decode, get-
direction, get-position-count, start-capture, stop-capture, enable-event, disable-event, get-phase-
error]
Guide to Digital I/O (DIO) basics and a tutorial for setting up and testing DIO on Karbon K300 / K700 series systems using Python.
This article provides specific examples for the K300 and K700 systems. Other models may not be compatible with the exact software packages used. Check out the available documentation directly on your system’s Support page. Checkout the newer generation series: Karbon K410 & K430 or Karbon 800 Series.
DIO, or Digital Input/Output, is a simple form of interface used in a wide range of systems to effectively relay digital signals from sensors, transducers and mechanical equipment to other electrical circuits and devices.
Sometimes referred to as General Purpose Input/Output (GPIO), DIO utilizes a logic signal to transfer information. Unlike an analog signal which might be comprised of varying voltages, the digital signals used by DIO have two possible values and are generally represented as either OFF or ON. Think of analog signals as those you might use a knob or dial to set, while digital signals would most often be controlled by a switch. This makes it ideal for sensing switch contacts, reacting to motion sensors, limit switches, operator buttons or machinery status indicators. It can also be used to control indicator lights, small relays or PLCs within equipment.
Read more about DIO basics on our blog.
Install Python3 and the Pykarbon library.
This tutorial will outline a quick and simple test for the Karbon K300 and K700 series’ Digital I/O. We’ll wire the DIO port and run a simple python script to control an LED during a button press event on an input pin
The Karbon Digital I/O port is not powered and will need to have power supplied to the port. The DIO port is able to handle 5-36VDC on the K300 and 5-48VDC on the K700.
For this tutorial we’ll borrow the USB port’s 5V and GND pins and splice a spare USB cable for use in the DIO port.
Once the power is supplied to the DIO port we’ll need to wire up our input. Since the Input of the DIO are pulled high when floating, we’ll wire an input to ground so that pressing the button will pull the input low.
We’ll wire up an LED to output 3 and to the supplied 5V. NOTE: most LEDs will need to have a resistor in line from the power rail to limit the current supplied to the LED. check the details of the current limits of the LED you are using.
To validate the input is working, the can be run to monitor the behavior of the inputs and outputs.
Running the karbon tool with the `op dio-state’ will print out what the input and output states are. The output bit order is I0 I1 I2 I3 O0 O1 O2 O3 Since we have the button wired to Input 3 we should expect 11110000 and then 11100000 when the command is ran while the button is pressed.
Now that that input can be read from the MCU, the output portion can be configured.
We can run a python script that will react to Input 3 being pulled low with the button press and set output 3 to high and turn the LED on.
Save the following script as dio.py and run it with the command python3 dio.py
Running the script will show configuration info and then print out information when the button is pressed and depressed.
The button press will set input 3 to high, triggering the python script to set output 3 high and turn on the LED.
import pykarbon.terminal as pkt
def callback_fn(arg):
if arg[3] == '0': #check if 3rd item from popdata() is 0
print("DI 3 --> LOW ", arg)
return True #return True to dev.set_do. sets output high
else: #if 3rd item from popdat() is anything other than 0
print("DI 3 --> HIGH", arg)
return False #return Flase to set_do. sets output low
i = 0
with pkt.Session() as dev:
dev.update_info(print_info=True) # Update and print configuration info
dev.set_do(0, False) # Set digital output zero low
while True: #create loop that runs forever
line = dev.popdata() #popdata will print out data in the queue
if line:
dev.set_do(0, callback_fn(line)) #returns data from queue as argument for use by callback_fn



