Turnout Sensor Commands

{From the laptop (4) to the Raspberry Pi (3)}


To add 24 additional sensors to the system, instead of adding a second Raspberry Pi, a IOPi HAT was added to RPi (3) providing 32 additional IO pins.


The Raspberry Pi will accept the DCC++ sensor commands <S...> with an ID greater than 50 and return results identical to the Base Station i.e. <O>, <X> or <Q ID PIN PULLUP>. Process <Q> commands to report the current status of each defined sensor. In addition, the <H> and <h> commands will be accepted to store or clear EEPROM in this Raspberry PI, similar to the <E>, <e> commands for the Base Station or <N>, <n> commands for stored semaphore data.


       <cmd[[[ value1] value2 value3]


       <response[ value1 value2 value3] 


Command summary

    • < -- Start of added command
    • H|h|Q|S -- command character
    • Zero, 1 or 3 data values
      • ID -- The numeric ID (51 - 32767) of the sensor
      • PIN -- Identifies byte/pin on the IOPi HAT the sensor is connected to.
      • PULLUP -- 1 = Use the internal pull-up resistor for the PIN, 0 = don't use the internal pull-up resistor for the PIN
    • > -- End of added command.


 Command response summary

    • < -- Start of response
    • h|O|Q|q|X -- Response character
    • Zero or 3 data values
      • (see above)
    • > -- End of response


  • Create a new sensor with ID > 50

IF ID > 50 Associate the ID with a IOPi PIN and PULLUP. If sensor ID already exists, it is updated with the specified PIN and PULLUP.

IF ID <= 50 pass command on to Arduino (2)

<S ID PIN PULLUP> 3 values

Returns: <O> if successful or <X> out of range ID, bus, pin, PULLUP

IF OK:        Set RAM only

(See <H> below)


  • Delete definition of sensor with ID > 50

IF ID > 50 Delete definition of sensor ID

IF ID <= 50 pass command on to Arduino (2)

<S ID> 1 value

Returns: <O> if successful or <X> if unsuccessful (e.g. ID does not exist)

IF OK:        Set RAM only

(See <H> below)


  • List all defined sensors

List all defined sensors stored on this Raspberry Pi (ID > 50) and pass the command, unchanged on to the Arduino for additional processing

<S> 0 values

Returns: <Q ID PIN PULLUP> for each defined senor stored on this Raspberry Pi or <X>


  • List the status of all sensors

List the status of all sensors defined on this Raspberry Pi (ID > 50) and pass the command, unchanged on to the Arduino for additional processing.

<Q> 0 values

Return: <Q ID> when sensor ID is active or <q ID> when sensor ID is inactive for each ID defined


  • Store Raspberry Pi (3) sensors in RAM to EPPROM

       Store sensors with ID > 50 in this Raspberry Pi RAM into Pi EPPROM

<H> 0 values

       Returns: <h nsensors>


  • Erase all Raspberry Pi (3) sensors in EPPROM

       Erase all sensors data from this Raspberry Pi EPPROM

<h> 0 values

Returns: <U> Done

               Erase all EPPROM data. Read EPROM into RAM


Sensor Status Change


When the status of a sensor connected to Raspberry Pi (3) and associated with an ID changes, Raspberry Pi (3) will return one of the following to the laptop:


  • When a sensor goes active, IOPi pin transitions from a HIGH state to a LOW state

       <Q ID>


  • When a sensor goes inactive, IOPi pin transitions from a LOW state to a HIGH state

       <q ID>


All sensors defined as described above are connected to a IOPi pin. When a pin in one of three bytes changes an interrupt notifies the Raspberry Pi which identifies which pins changed. For each sensor the last reported state is stored.