USB command interface¶
When present, “#” refers to the Arduino pin number used in the operation
| command | value | action |
|---|---|---|
| ?#ai | int | returns NUM_ANALOG_INPUTS |
| ?ai | 0..1023 | returns current value of numbered analog input |
| !ai:watch | 0..1 | sets up ai pin for averaging |
| ?ai:mean | long | returns <ai>*k |
| ?#bi | int | returns NUM_DIGITAL_PINS |
| ?bi | 0..1 | returns current value of numbered digital input |
| !bo | 0..1 | sets numbered digital output to value v |
| !pwm | 0..255 | sets numbered PWM digital output to value v |
| !pin | 0..1 | sets mode of digital pin to value v (value: 1=OUTPUT, not 1=INPUT) |
| !t | long | sets averaging time, ms |
| ?t | long | returns averaging time, ms |
| ?t:min | long | returns minimum allowed averaging time, ms |
| ?t:max | long | returns maximum allowed averaging time, ms |
| !k | long | sets averaging factor (k) |
| ?k | long | returns averaging factor (k) |
| ?k:min | long | returns minimum allowed averaging factor (k) |
| ?k:max | long | returns maximum allowed averaging factor (k) |
| ?v | string | returns version string |
| ?id | 0 | returns identification string |
| ?rate | long | returns number of updates (technically: loops) per second |
| other | returns “ERROR_UNKNOWN_COMMAND:text” |
notes:
- must use lower case (as shown in table)
- integers must be specified in decimal (no octal or hex interpreted)
- pin numbers are not checked for correctness in the current version
?commands return an integer!commands returnOk- Errors, starting with
ERROR_will substitute for expected output
commands
Note
Note about code examples below
In all code examples below, command input to the Arduino is shown as:
>>> some command
Response from the Arduino appears on the next line. When entering commands, do not type the “>>>” symbols.
?#ai¶
| purpose: | How many ANALOG IN channels on this Arduino? |
|---|---|
| command: |
|
| returns: | value of |
| example: | (on Arduino Mega2560) >>> ?#ai
16
|
?ai¶
| purpose: | read an ANALOG IN channel value |
|---|---|
| command: |
|
| returns: | Returns the analog input pin value specified.
The returned value is between 0 and 1023 (10-bit ADC) which represents
a measured voltage between 0 and 5 VDC.
The pin must be within the range of |
| example: | >>> ?ai 0
171
|
!ai:watch¶
| purpose: | Enables (or disables) signal averaging for the specified analog input pin. Note that it is possible to turn this feature on and off at run time. |
|---|---|
| command: |
|
| returns: |
|
| default: | by default, no ai pins are averaged |
| example: | >>> !ai:watch 0 1
Ok
|
To optimize the time to process the Arduino’s loop() function, only those ANALOG IN channels to be averaged will be watched. By default, when the Arduino sketch starts, no channels are watched. (That is, the configuration of watched channels is not stored in persistent memory on the Arduino.)
?ai:mean¶
| purpose: | read a time-averaged ANALOG IN channel value |
|---|---|
| command: |
|
| returns: | Returns the average analog input pin value specified,
multiplied by a factor \(k\). The factor is
requested by the |
| example: | >>> !ai:watch 0
Ok
>>> ?ai:mean 0
171000
|
?#bi¶
| purpose: | How many DIGITAL channels on this Arduino? |
|---|---|
| command: |
|
| returns: | value of |
| example: | (on Arduino Mega2560) >>> ?#bi
70
|
?bi¶
| purpose: | Reads the digital input pin specified in the first argument.
The returned value is either 0 or 1.
The pin must be within the range of |
|---|---|
| command: |
|
| returns: |
|
| example: | >>> ?bi 3
0
|
!bo¶
| purpose: | Sets the digital output pin specified in the first argument
to the value specified in the second argument. If the syntax
is correct and the value is within range, returns |
|---|---|
| command: |
|
| returns: |
|
| example: | >>> !pin 6 1
Ok
>>> !bo 6 0
Ok
|
Note
Selection of a digital pin as INPUT (0)
or OUTPUT (1) is based on the hardware wiring
for that channel. While configurable at run time,
it is not expected to change this after its first
setting.
!pwm¶
| purpose: | Sets the PWM-enabled digital output pin specified in the first argument
to the value specified in the second argument. If the syntax
is correct and the value is within range, returns The pin number is checked for PWM hardware-support by a call to the
|
|---|---|
| command: |
|
| returns: |
|
| example: | >>> !pwm 11 127
Ok
|
!pin¶
| purpose: | Configures the digital output pin specified in the first argument for output as a binary digital output and also as a PWM digital output if the hardware enables this.
|
||||||
|---|---|---|---|---|---|---|---|
| command: |
|
||||||
| returns: |
|
||||||
| default: | all pins are configured for input by default |
||||||
| example: | >>> !pin 11 1
Ok
|
Note
Selection of a digital pin as INPUT (0)
or OUTPUT (1) is based on the hardware wiring
for that channel. While configurable at run time,
it is not expected to change this after its first
setting.
!t¶
| purpose: | Sets the length of the averaging period (milliseconds).
The argument The period can be changed at run time as fits the application. |
|---|---|
| command: |
|
| returns: |
|
| example: | >>> !t 100
Ok
|
?t¶
| purpose: | Read the length of the averaging period (milliseconds). |
|---|---|
| command: |
|
| returns: | length of averaging period (ms) |
| default: |
|
| example: | >>> ?t
1000
|
?t:min¶
| purpose: | Returns \(t_l\), the minimum permitted length of the averaging period (milliseconds). The minimum length is fixed, somewhat arbitrarily, to allow for at least a couple of updates if as many as 16 AI channels are to be averaged. |
|---|---|
| command: |
|
| returns: | minimum allowed value of averaging period (ms) |
| default: |
|
| example: | >>> ?t:min
5
|
?t:max¶
| purpose: | Returns \(t_h\), the maximum permitted length of the averaging period (milliseconds). The maximum length is fixed, somewhat arbitrarily, to ~1 hour. Is any longer really necessary? |
|---|---|
| command: |
|
| returns: | maximum allowed value of averaging period (ms) |
| default: |
|
| example: | >>>
1000000
|
!k¶
| purpose: | Sets the multiplier to use when reporting
averaged AI values.
The argument |
|---|---|
| command: |
|
| returns: |
|
| example: | >>> !k 100
Ok
|
?k¶
| command: |
|
|---|---|
| returns: | multiplier \(k\) used when reporting averaged AI values |
| default: |
|
| example: | >>> ?k
1000
|
?k:min¶
| purpose: | Returns \(k_l\), the minimum permitted multiplier used when reporting averaged AI values. The minimum multiplier is set, logically, at 1. |
|---|---|
| command: |
|
| returns: | minimum allowed value of multiplier \(k\) |
| default: |
|
| example: | >>> ?k:min
1
|
?k:max¶
| purpose: | Returns \(k_h\), the maximum permitted multiplier used when reporting averaged AI values. The maximum length is fixed, somewhat arbitrarily, at some large number. |
|---|---|
| command: |
|
| returns: | maximum allowed value of multiplier \(k\) |
| default: |
|
| example: | >>> ?k:max
1000000
|
?rate¶
| purpose: | How many ADC readings per second? |
|---|---|
| command: |
|
| returns: | Returns the number of update loops per second. Each additional AI to be watched will decrease this number due to the operations of reading, accumulating, and averaging the signal. The update rate serves no purpose to the operation of the Arduino as an I/O controller. It is only provided as a diagnostic signal for the remote control system. |
| example: | (Arduino Mega2560 with no AI channels watched) >>> ?rate
25867
|
?v¶
| command: | ?v |
|---|---|
| returns: | Returns the software version string. |
example:
>>> ?v
2013-12-01
(Actual value will be different than shown.)
Example Commands¶
- Read analog input from pin 0:
>>> ?ai 0
41
- Set digital pin 11 for PWM output:
>>> !pin 11 1
Ok
- Set PWM output pin 11 to 128:
>>> !pwm 11 128
Ok
- Show how a bad command (no space between baseCmd and pin) is handled:
>>> !pwm11 128
ERROR_UNKNOWN_COMMAND:!pwm11 128
Communications Parameters¶
| term | value |
|---|---|
| communications rate | 115200 |
| line terminator | \n |
| buffer length (chars) | 40 |
| command length (chars) | 16 |
file: cmd_reponse.ino¶
The full Arduino cmd_response.ino
code listing is too large for this documentation.
| EPICS Streams protocol: | |
|---|---|
cmd_response.ino |
|