<Q> <S «id» [«vpin» «pullup»>]
Manage Sensors¶
Serial commands to create and manage sensors
Commands¶
<Q>List all sensors<S>List sensors<S «id» «vpin» «pullup»>Create Sensor<S «id»>Delete sensor
Parameters¶
- id: identifier of the Sensor. (0-32767)
- vpin: pin number of the input to be controlled by the sensor object
- pullup: one of:
1= Use pull-up resistor ACTIVE=LOW0= don’t use pull-up resistor ACTIVE=HIGH
Responses¶
Response for <Q>¶
(successful) Repeated for each inactive defined sensor: <q «id»>
(fail): N/A
Response for <S>¶
(successful) Repeated for each inactive defined sensor: <Q «id» «vpin» «pullup»>
(fail): X
- id: identifier of the Sensor. (0-32767)
- vpin: pin number of the input to be controlled by the sensor object
- pullup: one of:
1= Use pull-up resistor ACTIVE=LOW0= don’t use pull-up resistor ACTIVE=HIGH
Response for <S «id» «vpin» «pullup»>¶
(Successful): <O>
(Fail): <X> (e.g. out of memory)
Response for <S «id»>¶
(Successful): <O>
(Fail): <X> (e.g. ID does not exist)
Notes¶
-
EX‑CommandStation supports Sensor inputs that can be connected to any Arduino Pin not in use by this program, as well as pins on external I/O expanders and other devices. Physical sensors can be of any type (infrared, magnetic, mechanical…). They may be configured to pull-up or not. When configured for pull-up, the input is connected (within the CS) to +5V via a resistor. This sort of input is suited to sensors that have two wires - a switch or relay contacts, or a device with an 'open collector'’' or '‘'open drain'’' output. Some sensors may be sensitive to the pull-up resistor and not operate as expected - in this case you can turn off the pull-up.
The sensor is considered INACTIVE when at +5V potential, and ACTIVE when the pin is pulled down to 0V.
To ensure proper voltage levels, some part of the Sensor circuitry MUST be tied back to the same ground as used by the Arduino.
The Sensor code utilises debouncing logic to eliminate contact ‘bounce’ generated by mechanical switches on transitions. This avoids the need to create smoothing circuitry for each sensor. You may need to change the parameters in Sensor.cpp through trial and error for your specific sensors, but the default parameters protect against contact bounces for up to 20 milliseconds, which should be adequate for almost all mechanical switches and all electronic sensors.
To monitor one or more Arduino pins for sensor triggers, first define/edit/delete sensor definitions using one of the variations of the<S>command. -
Arduino Mega only (not **EX-CSB1 or ESP32):** Once all sensors have been properly defined, you can use the
<E>command to store their definitions to EEPROM. If you later make edits/additions/deletions to the sensor definitions, you must invoke the<E>command if you want those new definitions updated in the EEPROM. You can also clear everything (turnouts, sensors, and outputs) stored in the EEPROM by invoking the<e>command. (There is NO UN-Delete) -
All sensors defined as per above are repeatedly and sequentially checked within the main loop of this sketch. If a Sensor Pin is found to have transitioned from one state to another, one of the following serial messages are generated:
-
<Q id>- for transition of Sensor ID from INACTIVE state to ACTIVE state (i.e. the sensor is triggered) -
<q id>- for transition of Sensor ID from ACTIVE state to INACTIVE state (i.e. the sensor is no longer triggered)
-
-
Depending on whether the physical sensor is acting as an 'event-trigger' or a 'detection-sensor', you may decide to ignore the
<q id>` return and only react to`` triggers.
Examples¶
Also search for '/ latch' or search for '/ unlatch'
Example Commands¶
- TODO LOW - Example Commands
Example Responses:¶
- TODO LOW - Example Responses