You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Also, it can be directly converted to a voltage reading using the `pinVoltage()` function as:
2877
+
2878
+
```arduino
2879
+
float value = exp.pinVoltage(<input>);
2880
+
```
2881
+
2876
2882
The following example will let you read all the analog inputs of every expansion connected at once, it can be found in the Opta Analog Expansions library by navigating to **File > Examples > Arduino_Opta_Blueprint > Analog > ADC**:
2877
2883
2878
2884
```arduino
@@ -2968,7 +2974,7 @@ void optaAnalogTask() {
2968
2974
if(exp) {
2969
2975
Serial.println("\nAnalog Expansion n. " + String(exp.getIndex()));
2970
2976
2971
-
2977
+
2972
2978
for(int j = 0; j < OA_AN_CHANNELS_NUM; j++) {
2973
2979
Serial.print(" - ch " + String(j));
2974
2980
int value = exp.analogRead((uint8_t)j);
@@ -2999,18 +3005,35 @@ Thanks to this function, the action of plugging in a new expansion will cause th
2999
3005
* Check if an expansion has been removed and remove their objects
3000
3006
* Update any data from or to the expansion
3001
3007
3002
-
3003
3008
The expansion object in the example above is defined using the `OptaController.getExpansion(i);` function, as follows:
3004
3009
3005
-
3006
3010
```arduino
3007
3011
for(int i = 0; i < OptaController.getExpansionNum(); i++) { // check all the available expansion slots
The above method will check if there is an Ext A0602 expansion connected in the `i` index from the five admitted. This will ensure which expansion the read state belongs to.
3012
3016
3013
-
The function `optaAnalogTask()` reads all the analog input raw ADC values and prints out them.
3017
+
The expansion channels are configured as **analog voltage inputs** using the function `beginChannelAsAdc` alongside the following parameters:
3018
+
3019
+
```arduino
3020
+
AnalogExpansion::beginChannelAsAdc(OptaController, // the expansion object
3021
+
i, // the device (connected expansion index from 0 to 5)
3022
+
k, // the output channel you are using (0 to 7)
3023
+
OA_VOLTAGE_ADC, // adc type (voltage input)
3024
+
true, // enable pull down
3025
+
false, // disable rejection
3026
+
false, // disable diagnostic
3027
+
0); // disable averaging
3028
+
```
3029
+
The function `optaAnalogTask()` reads all the analog input raw ADC values and prints out them. If you want to show the voltage reading instead use the following function:
3030
+
3031
+
```arduino
3032
+
//Change
3033
+
int value = exp.analogRead((uint8_t)j); // get the raw ADC reading
3034
+
//for
3035
+
float value = exp.pinVoltage((uint8_t)j); // get the ADC reading and returns it as a voltage
3036
+
```
3014
3037
3015
3038
After the Opta™ controller is programmed with the example sketch, open the Arduino IDE Serial Monitor and you will see each input reading as follows:
3016
3039
@@ -3020,15 +3043,200 @@ Analog Expansion n. 0
3020
3043
- ch 1 -> ADC 0
3021
3044
- ch 2 -> ADC 0
3022
3045
- ch 3 -> ADC 0
3023
-
- ch 4 -> ADC 25112
3024
-
- ch 5 -> ADC 0
3046
+
- ch 4 -> ADC 0
3047
+
- ch 5 -> ADC 25112
3025
3048
- ch 6 -> ADC 0
3026
3049
- ch 7 -> ADC 0
3027
3050
```
3028
3051

3029
3052
3053
+
You can test other ADC functionalities by studying other examples included in the library, for example, the ones listed below:
3054
+
3055
+
- AdcUpdateAll
3056
+
- DiPlusAdc
3057
+
3030
3058
#### Analog Current Input Mode
3031
3059
3060
+
The Analog Expansion input channels can be configured for current loop instrumentation using the 0/4-20 mA standard.
| Short circuit current limit | Min: 25 mA, Max 35 mA (externally powered). |
3067
+
| Programmable current limit | 0.5 mA to 24.5 mA (loop powered) |
3068
+
| Accuracy | +/- 1%, repeatability +/- 1% |
3069
+
3070
+
The current of an input terminal configured in current mode can be read using the built-in function `pinCurrent()` as shown below:
3071
+
3072
+
```arduino
3073
+
float value = exp.pinCurrent(<input>);
3074
+
```
3075
+
3076
+
The following example will let you measure the current in all the analog inputs of every expansion connected at once, this sketch is based on the built-in example found in **File > Examples > Arduino_Opta_Blueprint > Analog > ADC**:
Please take into account that `OptaController.update()` must be called cyclically to support the hot plug of new expansions. In other words, by calling the update() function cyclically, the controller will discover new expansions when they are plugged in while the controller is already running.
3195
+
3196
+
Thanks to this function, the action of plugging in a new expansion will cause the controller to start a completely new discovery process and a new I2C address assignment.
3197
+
3198
+
`OptaController.update()` function DOES NOT:
3199
+
* Check if an expansion has been removed and remove their objects
3200
+
* Update any data from or to the expansion
3201
+
3202
+
The expansion object in the example above is defined using the `OptaController.getExpansion(i);` function, as follows:
3203
+
3204
+
```arduino
3205
+
for(int i = 0; i < OptaController.getExpansionNum(); i++) { // check all the available expansion slots
The above method will check if there is an Ext A0602 expansion connected in the `i` index from the five admitted. This will ensure which expansion the read state belongs to.
3210
+
3211
+
The expansion channels are configured as **analog current inputs** using the function `beginChannelAsAdc` alongside the following parameters:
3212
+
3213
+
```arduino
3214
+
AnalogExpansion::beginChannelAsAdc(OptaController, // the expansion object
3215
+
i, // the device (connected expansion index from 0 to 5)
3216
+
k, // the output channel you are using (0 to 7)
3217
+
OA_CURRENT_ADC, // adc type (voltage input)
3218
+
false, // enable pull down
3219
+
false, // disable rejection
3220
+
false, // disable diagnostic
3221
+
0); // disable averaging
3222
+
```
3223
+
The function `optaAnalogTask()` reads all the analog input current values and prints out them.
3224
+
3225
+
After the Opta™ controller is programmed with the example sketch, open the Arduino IDE Serial Monitor and you will see each input reading as follows:
3226
+
3227
+
```
3228
+
Analog Expansion n. 0
3229
+
- ch 0 -> Current 0.00 mA
3230
+
- ch 1 -> Current 0.00 mA
3231
+
- ch 2 -> Current 0.00 mA
3232
+
- ch 3 -> Current 0.00 mA
3233
+
- ch 4 -> Current 0.00 mA
3234
+
- ch 5 -> Current 18.20 mA
3235
+
- ch 6 -> Current 0.00 mA
3236
+
- ch 7 -> Current 0.00 mA
3237
+
```
3238
+

0 commit comments