Skip to content

About

S88 Adapter

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

21 Commits

Folders and files

Repository files navigation

DCCExpress-S88Adapter

Arduino-based S88 / s88-N feedback adapter for DCC-EX CommandStation-EX.

The primary purpose of this project is to add S88 occupancy feedback to a DCC-EX command station through its I2C HAL. DCC-EX reads the adapter over I2C, maps the S88 inputs to VPINs, and emits normal DCC-EX sensor events such as <Q ID> and <q ID>.

Those standard DCC-EX events can then be consumed by DCCExpressHub, JMRI or other DCC-EX clients without any S88-specific transport on the client side.

The adapter firmware itself runs on an Arduino Uno-class ATmega328P board. It owns the S88 bus, keeps its hardware configuration in EEPROM, and exposes a read-only I2C snapshot interface plus a USB serial configuration/diagnostic console.

Current firmware

Current firmware version:

v0.6.0

Main features:

  • S88 / s88-N feedback input
  • up to 32 S88 bytes / 256 feedback inputs
  • configurable active S88 byte count
  • configurable I2C slave address
  • configuration stored in Arduino EEPROM
  • USB serial configuration console
  • automatic compact ASCII HEX + CRC16 snapshot streaming over USB serial
  • original underscore-bit text view selectable with VIEW BIN
  • periodic S88 diagnostic logging
  • read-only I2C protocol for DCC-EX CommandStation-EX
  • DCC-EX HAL driver included in this repository
  • adapter INFO packet with firmware/protocol/capability information
  • direct S88 snapshot reads over I2C
  • tested with a YaMoRC YD6016ES-CS
  • stable operation verified with two chained 16-input s88-N modules / 32 inputs

Architecture

The normal DCC-EX integration is:

S88 / s88-N feedback modules
          |
          v
+--------------------------+
| Arduino Uno              |
| DCCExpress S88Adapter    |
|                          |
| S88 master               |
| USB serial configuration |
| EEPROM configuration     |
| I2C slave                |
+--------------------------+
          |
          | I2C
          v
+--------------------------+
| DCC-EX CommandStation-EX |
| DCCExpressS88 HAL driver |
+--------------------------+
          |
          | normal DCC-EX
          | <Q>/<q> events
          v
+--------------------------+
| DCCExpressHub / JMRI /   |
| other DCC-EX clients     |
+--------------------------+

The DCC-EX HAL driver has read-only access to the adapter. Adapter I2C address and S88 byte length are configured locally through the Arduino USB serial console. The optional direct USB feedback integration streams CRC-verified HEX snapshots to the Hub.

DCC-EX integration

The repository contains a ready-to-use DCC-EX integration under:

dcc-ex/
├── IO_DCCExpressS88.h
├── myHal.example.cpp
├── sensors-1001-1032.txt
└── README.md

For the complete DCC-EX installation guide, see:

dcc-ex/README.md

Typical 32-input setup:

  1. Configure the adapter for four S88 bytes:
SET BYTES 4
SAVE
  1. Copy dcc-ex/IO_DCCExpressS88.h into the CommandStation-EX configuration/source location.
  2. Merge the example from dcc-ex/myHal.example.cpp into your existing DCC-EX myHal.cpp.
  3. Map the S88 inputs to VPIN/sensor IDs, for example 1001-1032.
  4. Verify DCC-EX emits normal events such as:
<Q 1001>
<q 1001>

Example HAL configuration:

#include "IO_DCCExpressS88.h"
#include "Sensors.h"

void halSetup() {
    constexpr int FIRST_VPIN = 1001;
    constexpr int SENSOR_COUNT = 32;

    DCCExpressS88::create(FIRST_VPIN, SENSOR_COUNT, 0x30);

    for (int i = 0; i < SENSOR_COUNT; i++) {
        const int id = FIRST_VPIN + i;
        Sensor::create(id, id, 0);
    }
}

This produces the normal DCC-EX sensor path:

S88 input -> DCC-EX VPIN -> DCC-EX Sensor -> <Q>/<q> -> client

Supported hardware

Recommended / tested controller:

  • Arduino Uno
  • compatible ATmega328P Uno boards

The firmware currently assumes the standard Uno pin assignment shown below.

Arduino pin assignment

Function Arduino Uno
S88 CLOCK D2
S88 PS / LOAD D3
S88 RESET D4
S88 DATA D5
I2C SDA A4
I2C SCL A5
GND GND

On many Uno-compatible boards the silkscreen only shows 2, 3, 4, 5. These correspond to D2, D3, D4, D5.

s88-N RJ45 pinout

s88-N uses an 8P8C / RJ45 connector and normal Ethernet-style twisted-pair cable.

RJ45 pin s88-N signal Arduino Uno
1 +5 V / +12 V bus supply 5 V only when suitable for the module
2 DATA D5
3 GND GND
4 CLOCK D2
5 GND GND
6 PS / LOAD D3
7 RESET D4
8 RAILDATA not used

Important: bus voltage

The general s88-N specification allows different bus supply voltages depending on the connected hardware.

Do not assume every s88-N module accepts 12 V.

For the tested YaMoRC YD6016ES-CS:

Use maximum 5 V on the s88 bus. Do not feed 12 V into the module.

Disconnect power before changing wiring.

RJ45 cable requirements

Use a full 8-conductor straight-through Ethernet patch cable, preferably CAT5, CAT5e or CAT6.

A cable tester should show:

1 -> 1
2 -> 2
3 -> 3
4 -> 4
5 -> 5
6 -> 6
7 -> 7
8 -> 8

Do not use 4-conductor Ethernet cables wired only for 10/100 Mbit Ethernet. Such a cable cannot carry all required s88-N signals.

Typical symptoms include:

  • feedback module powers up but no feedback data appears,
  • S88 snapshot remains all zero,
  • CLOCK or RESET never reaches the detector.

When debugging S88 hardware, verify the cable before changing firmware.

RJ45 wire colors

The pin number matters; wire color alone is not enough because Ethernet cables may use either T568A or T568B.

With the gold contacts facing you and the locking clip on the opposite/down side:

1  2  3  4  5  6  7  8

Typical T568B:

Pin Color
1 white/orange
2 orange
3 white/green
4 blue
5 white/blue
6 green
7 white/brown
8 brown

Typical T568A:

Pin Color
1 white/green
2 green
3 white/orange
4 blue
5 white/blue
6 orange
7 white/brown
8 brown

Use a continuity meter or cable tester when connecting a screw-terminal RJ45 adapter.

Tested feedback module

The current implementation has been tested with the YaMoRC YD6016ES-CS.

For this module:

  • connect the Arduino / S88 master side to s88N OUT,
  • additional downstream S88 modules connect through s88N IN,
  • use maximum 5 V on the s88-N bus,
  • the green status LED may light or blink while S88 communication is active,
  • the red occupancy indicator may light when detector inputs sense current.

Practical wiring:

RJ45 pin 1 -> Uno 5V
RJ45 pin 2 -> Uno D5   DATA
RJ45 pin 3 -> Uno GND
RJ45 pin 4 -> Uno D2   CLOCK
RJ45 pin 5 -> Uno GND
RJ45 pin 6 -> Uno D3   PS / LOAD
RJ45 pin 7 -> Uno D4   RESET
RJ45 pin 8 -> not connected

Refer to the YaMoRC manual before combining s88-N and ES-Link connections.

Default configuration

Firmware defaults:

I2C address:       0x30
S88 bytes:         2
S88 inputs:        16
Maximum bytes:     32
Maximum inputs:    256
Serial baud rate:  115200

One S88 byte represents eight feedback inputs.

2 bytes  = 16 inputs
4 bytes  = 32 inputs
8 bytes  = 64 inputs
16 bytes = 128 inputs
32 bytes = 256 inputs

The maximum of 32 bytes is based on the AVR Wire transmit buffer size.

S88 timing

Current default timing:

CLOCK HIGH: 50 us
CLOCK LOW:  50 us

This gives an S88 clock of approximately:

10 kHz

Control pulse timing:

50 us

The clock was intentionally reduced from the earlier 25 kHz setting after testing with multiple chained s88-N modules.

With two chained 16-input modules / 32 feedback inputs, the faster timing produced intermittent adjacent-bit errors such as:

_00000001
_00000011
_00000010

Reducing the clock to approximately 10 kHz eliminated the instability and produced stable feedback states.

For model railway occupancy detection, 10 kHz is still comfortably fast and provides better timing margin on multi-module S88 chains.

The adapter refreshes the S88 snapshot approximately every 20 ms.

The serial link emits an initial full snapshot, changes (rate-limited to at most one frame every 60 ms), and a full heartbeat snapshot every second. Both serial views are human-readable and line-based. The I2C snapshot protocol for DCC-EX is unchanged.

Serial configuration console

The USB serial console is used to configure and diagnose the adapter.

IMPORTANT serial monitor settings

Use:

Baud rate:   115200
Line ending: Newline (LF)

Both NL & CR also works.

Do not use

No line ending
Carriage return only

The command parser executes a command only when it receives a newline (LF, \n).

So if you type:

HELP

and nothing happens, check the serial monitor line-ending setting first.

PlatformIO serial monitor:

pio device monitor

Available serial commands

Type HELP or ? to display the command list.

HELP
STATUS
INFO
READ
SET ADDRESS <address>
SET I2C <address>
SET BYTES <count>
SET GROUPS <count>
VIEW HEX
VIEW BIN
VIEW
SAVE
DEFAULTS
LOG ON
LOG OFF
REBOOT
RESET

Commands are case-insensitive, so HELP, help, Help and ? are all valid.

HELP

Display available commands:

HELP

STATUS

Show active, staged and saved configuration:

STATUS

Alias:

SHOW

The output includes firmware version, protocol version, uptime, active/staged/saved I2C address, active/staged/saved S88 length, EEPROM status, unsaved changes and periodic logging state.

INFO

Show firmware, protocol and hardware information:

INFO

READ

Print the current S88 snapshot immediately:

READ

Default ASCII HEX example (2 S88 bytes, input 1 active):

S88:02:0100*91CD

The rightmost bit of the first byte represents feedback input 1. VIEW BIN restores the original _00000001 text presentation.

All inputs inactive:

S88:02:0000*A2FC

Input 1 active:

S88:02:0100*91CD

With 32 inputs configured (SET BYTES 4), input 17 active should appear as:

S88:04:00000100*AB3B

HEX and BIN terminal views

USB serial operates at 115200 baud, LF line endings. The default on every power-up/reset is ASCII HEX. Both modes are text, not raw binary bytes.

VIEW HEX
OK: serial view HEX (boot default)
S88:04:0200FF01*66BC

VIEW BIN
OK: serial view BIN (ASCII bits)
S88: _00000010 _00000000 _11111111 _00000001

VIEW
Serial view: BIN

The VIEW setting is not stored in EEPROM. A reboot always returns to HEX, irrespective of any earlier terminal session. All earlier commands (HELP, STATUS, INFO, READ, SET ADDRESS, SET BYTES, SET GROUPS, SAVE, DEFAULTS, LOG ON/OFF, REBOOT) are retained.

HEX snapshot wire format:

S88:NN:DDDD...*CCCC\n
  • NN: 2 hexadecimal characters for the number of data bytes (1..32)
  • DDDD...: exactly NN * 2 uppercase hexadecimal data characters
  • CCCC: 4 hexadecimal characters, CRC-16/CCITT-FALSE over raw [NN, byte1, ..., byteN] (poly 0x1021, init 0xFFFF, no reflection, xor 0)
  • \n: LF packet delimiter; a partial or invalid CRC must be discarded
  • S88 sensor 1 = bit 0 of byte 1; groups follow in ascending byte order

No separate READ polling is needed for v0.6. The UNO transmits its initial full snapshot on startup, on sensor changes (max ~16 frames/second due to 60 ms minimum spacing), and once per second as a heartbeat. The periodic full snapshot allows a consumer to recover from a lost frame.

READ still sends a full snapshot immediately, using whichever view is selected, even when automatic logging is off. This serial behavior does not change the read-only I2C interface used by DCC-EX.

SET ADDRESS

Stage a new I2C slave address:

SET ADDRESS 0x30

Valid normal 7-bit I2C address range:

0x08 .. 0x77

Alias:

SET I2C 0x30

Changing the I2C address requires:

SET ADDRESS 0x31
SAVE
REBOOT

The currently active I2C address remains in use until reboot.

SET BYTES

Set the active S88 snapshot length:

SET BYTES 4

This means:

4 bytes = 32 S88 inputs

Valid range:

1 .. 32 bytes

Alias:

SET GROUPS 4

Byte-count changes are applied immediately to the running adapter. Use SAVE to keep the new byte count after reboot.

SAVE

Store the staged I2C address and S88 byte count in EEPROM:

SAVE

If the I2C address changed, reboot after saving.

DEFAULTS

Stage the firmware defaults:

DEFAULTS

Current defaults:

I2C address: 0x30
S88 bytes:   2

DEFAULTS does not save automatically.

To make the defaults persistent:

DEFAULTS
SAVE
REBOOT

LOG ON / LOG OFF

Enable periodic S88 snapshot output:

LOG ON

Disable it:

LOG OFF

Automatic streaming is enabled by default after boot; LOG OFF silences unsolicited snapshots (but READ still works), and LOG ON resumes streaming.

REBOOT / RESET

Reboot the Arduino:

REBOOT

Alias:

RESET

This is required after changing and saving the I2C address.

Configuration model

The adapter maintains three related configuration states.

Active configuration

Values currently used by the running firmware.

Staged configuration

Values edited through the serial console.

Example:

SET ADDRESS 0x31
SET BYTES 4

Saved configuration

Values stored in EEPROM using:

SAVE

On boot, valid EEPROM configuration overrides firmware defaults. If EEPROM configuration is invalid or absent, firmware defaults are used.

I2C interface

The Arduino acts as an I2C slave.

Default address:

0x30

Arduino Uno pins:

SDA = A4
SCL = A5

Ownership model

The DCC-EX HAL driver has read-only access.

DCC-EX can:

  • request adapter INFO,
  • read the current S88 snapshot,
  • expose the adapter inputs as VPINs and Sensor objects.

DCC-EX cannot:

  • change the adapter I2C address,
  • change the adapter S88 byte count,
  • write adapter configuration.

Configuration is intentionally controlled only through the Arduino USB serial console.

Normal snapshot read

A normal I2C read returns the current raw S88 snapshot. The DCC-EX HAL driver requests exactly the number of bytes advertised by the adapter.

Each byte contains eight S88 feedback states.

INFO request

The DCC-EX HAL driver can request a fixed adapter information packet.

I2C write selector:

byte 0 = 0xA5
byte 1 = 0x02
byte 2 = XOR checksum of byte 0 and byte 1

Checksum:

0xA5 XOR 0x02 = 0xA7

So the request packet is:

A5 02 A7

The next I2C read returns the 10-byte INFO packet.

INFO response

[0]  0xA5  protocol magic
[1]  0x82  INFO response
[2]  protocol version
[3]  firmware major
[4]  firmware minor
[5]  firmware patch
[6]  active S88 byte count
[7]  maximum supported byte count
[8]  capability flags
[9]  XOR checksum of bytes 0..8

Current protocol version:

1

Current capability flags indicate serial configuration and EEPROM configuration support.

The INFO selection applies only to the next I2C read. After that, reads automatically return to normal S88 snapshot mode.

Build with PlatformIO

Environment:

[env:uno]
platform = atmelavr
board = uno
framework = arduino
monitor_speed = 115200

Build:

pio run

Upload:

pio run -t upload

Serial monitor:

pio device monitor

Remember: 115200 baud and Newline / LF line ending for commands.

Typical first setup

  1. Flash the adapter.
  2. Connect the Arduino through USB.
  3. Open the serial monitor at 115200.
  4. Configure line ending as Newline (LF) or Both NL & CR.
  5. Type:
HELP
  1. Check current configuration:
STATUS
  1. For the default 16-input setup, no configuration change is required.
  2. For 32 feedback inputs:
SET BYTES 4
SAVE
  1. To change the I2C address:
SET ADDRESS 0x31
SAVE
REBOOT
  1. Verify with STATUS and test feedback with READ.

Troubleshooting

HELP does nothing

Check:

Baud:        115200
Line ending: Newline / LF

No line ending will not execute commands.

Carriage return only will not execute commands.

Serial output is unreadable

Check that the serial monitor is set to 115200 baud.

S88 always reads zero

Check:

  • detector power,
  • GND connection,
  • RJ45 pin mapping,
  • full 8-conductor Ethernet cable,
  • CLOCK on D2,
  • LOAD on D3,
  • RESET on D4,
  • DATA on D5.

If using a YaMoRC YD6016ES-CS, check that the green LED indicates module power/activity.

S88 module is powered but no data appears

A common cause is a 4-conductor Ethernet cable. Use a cable tester and verify all eight pins are connected straight through.

Feedback bits flicker or adjacent inputs appear briefly

If an occupied input intermittently appears as two adjacent active bits, for example:

_00000001
_00000011
_00000010

check:

  • full 8-conductor cable,
  • common GND,
  • module chaining direction,
  • S88 bus voltage,
  • CLOCK and DATA signal integrity.

The current firmware default uses approximately 10 kHz S88 clock (50 us HIGH + 50 us LOW) because this proved stable with two chained 16-input modules / 32 feedback inputs.

New I2C address does not respond

Changing the address requires:

SET ADDRESS <new address>
SAVE
REBOOT

Check the result with STATUS.

Byte count changes after reboot

Use SAVE after SET BYTES ....

Safety notes

  • Disconnect power before rewiring the S88 bus.
  • Verify the required S88 bus voltage for the connected feedback module.
  • Do not feed 12 V into a YaMoRC YD6016ES-CS s88-N connection.
  • Verify RJ45 pin numbering instead of trusting wire colors.
  • Use a full 8-conductor straight-through cable.
  • When the DCC-EX controller uses 3.3 V logic, use an appropriate I2C level interface to the 5 V Arduino Uno adapter unless the controller hardware is explicitly 5 V tolerant.

Project status

The S88 adapter is currently considered feature-complete for the intended DCC-EX CommandStation-EX integration and downstream use with DCCExpressHub/JMRI:

  • S88 acquisition: implemented
  • configurable byte/input count: implemented
  • I2C slave snapshot interface: implemented
  • INFO protocol: implemented
  • USB serial configuration: implemented
  • EEPROM persistence: implemented
  • status / diagnostic console: implemented
  • YaMoRC YD6016ES-CS compatibility: tested
  • two-module / 32-input chained operation: tested
  • stable 10 kHz S88 timing: verified

Future changes can focus on additional hardware support, diagnostics or protocol extensions rather than the basic adapter functionality.

References

About

S88 Adapter

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages