Skip to content

Commit 5a4199e

Browse files
committed
Current input section
1 parent 40c6828 commit 5a4199e

File tree

1 file changed

+219
-11
lines changed
  • content/hardware/07.opta/opta-family/opta/tutorials/01.user-manual

1 file changed

+219
-11
lines changed

content/hardware/07.opta/opta-family/opta/tutorials/01.user-manual/content.md

Lines changed: 219 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,7 +2687,7 @@ Input terminals are mapped as described in the following table:
26872687

26882688
#### Digital Input Mode
26892689

2690-
Here's the HTML table converted to Markdown format:
2690+
The Analog Expansion input channels can be configured as digital inputs to read 0-10 V or 0-24 V digital sensors:
26912691

26922692
| Characteristics | Details |
26932693
|-----------------------------------|-------------------------------------------|
@@ -2696,7 +2696,7 @@ Here's the HTML table converted to Markdown format:
26962696
| Digital input current | 4.12mA at 24V \| 2.05mA at 10V |
26972697
| Digital input frequency | 300 Hz |
26982698

2699-
The state of an input terminal, configured as digital, can be read using the built-in function `digitalRead()` as shown below:
2699+
The state of an input terminal configured as digital can be read using the built-in function `digitalRead()` as shown below:
27002700

27012701
```arduino
27022702
state = <ExpObject>.digitalRead(<input>);
@@ -2842,8 +2842,8 @@ The function `optaAnalogTask()` updates all the inputs with their current states
28422842
After the Opta™ controller is programmed with the example sketch, open the Arduino IDE Serial Monitor and you will see each input state as follows:
28432843

28442844
```
2845-
DI channel 0 value 0
2846-
DI channel 1 value 1
2845+
DI channel 0 value 1
2846+
DI channel 1 value 0
28472847
DI channel 2 value 0
28482848
DI channel 3 value 0
28492849
DI channel 4 value 0
@@ -2868,11 +2868,17 @@ The Analog Expansion input channels can be configured for 0-10 V analog sensors.
28682868
| Accuracy | +/- 1%, repeatability +/- 1% |
28692869
| Input impedance | Min: 175 kΩ (200 kΩ to GND enabled) |
28702870

2871-
The state of an input terminal, configured as analog, can be read using the built-in function `analogRead()` as shown below:
2871+
The raw value of an input terminal configured as analog can be read using the built-in function `analogRead()` as shown below:
28722872

28732873
```arduino
28742874
uint16_t raw_adc = <ExpObject>.analogRead(<input>);
28752875
```
2876+
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+
28762882
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**:
28772883

28782884
```arduino
@@ -2968,7 +2974,7 @@ void optaAnalogTask() {
29682974
if(exp) {
29692975
Serial.println("\nAnalog Expansion n. " + String(exp.getIndex()));
29702976
2971-
2977+
29722978
for(int j = 0; j < OA_AN_CHANNELS_NUM; j++) {
29732979
Serial.print(" - ch " + String(j));
29742980
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
29993005
* Check if an expansion has been removed and remove their objects
30003006
* Update any data from or to the expansion
30013007

3002-
30033008
The expansion object in the example above is defined using the `OptaController.getExpansion(i);` function, as follows:
30043009

3005-
30063010
```arduino
30073011
for(int i = 0; i < OptaController.getExpansionNum(); i++) { // check all the available expansion slots
30083012
AnalogExpansion exp = OptaController.getExpansion(i);
30093013
}
30103014
```
30113015
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.
30123016

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+
```
30143037

30153038
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:
30163039

@@ -3020,15 +3043,200 @@ Analog Expansion n. 0
30203043
- ch 1 -> ADC 0
30213044
- ch 2 -> ADC 0
30223045
- ch 3 -> ADC 0
3023-
- ch 4 -> ADC 25112
3024-
- ch 5 -> ADC 0
3046+
- ch 4 -> ADC 0
3047+
- ch 5 -> ADC 25112
30253048
- ch 6 -> ADC 0
30263049
- ch 7 -> ADC 0
30273050
```
30283051
![Analog voltage input wiring example](assets/volt-in-a.png)
30293052

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+
30303058
#### Analog Current Input Mode
30313059

3060+
The Analog Expansion input channels can be configured for current loop instrumentation using the 0/4-20 mA standard.
3061+
3062+
| Characteristics | Details |
3063+
|-----------------------------|---------------------------------------------|
3064+
| Analog input current | 0...25 mA |
3065+
| Analog input LSB value | 381.5 nA |
3066+
| 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**:
3077+
3078+
```arduino
3079+
#include "OptaBlue.h"
3080+
3081+
#define PERIODIC_UPDATE_TIME 500
3082+
#define DELAY_AFTER_SETUP 5000
3083+
3084+
using namespace Opta;
3085+
3086+
3087+
/* -------------------------------------------------------------------------- */
3088+
void printExpansionType(ExpansionType_t t) {
3089+
/* -------------------------------------------------------------------------- */
3090+
if(t == EXPANSION_NOT_VALID) {
3091+
Serial.print("Unknown!");
3092+
}
3093+
else if(t == EXPANSION_OPTA_DIGITAL_MEC) {
3094+
Serial.print("Opta --- DIGITAL [Mechanical] ---");
3095+
}
3096+
else if(t == EXPANSION_OPTA_DIGITAL_STS) {
3097+
Serial.print("Opta --- DIGITAL [Solid State] ---");
3098+
}
3099+
else if(t == EXPANSION_DIGITAL_INVALID) {
3100+
Serial.print("Opta --- DIGITAL [!!Invalid!!] ---");
3101+
}
3102+
else if(t == EXPANSION_OPTA_ANALOG) {
3103+
Serial.print("~~~ Opta ANALOG ~~~");
3104+
}
3105+
else {
3106+
Serial.print("Unknown!");
3107+
}
3108+
}
3109+
3110+
/* -------------------------------------------------------------------------- */
3111+
void printExpansionInfo() {
3112+
/* -------------------------------------------------------------------------- */
3113+
static long int start = millis();
3114+
3115+
if(millis() - start > 5000) {
3116+
start = millis();
3117+
Serial.print("Number of expansions: ");
3118+
Serial.println(OptaController.getExpansionNum());
3119+
3120+
for(int i = 0; i < OptaController.getExpansionNum(); i++) {
3121+
Serial.print("Expansion n. ");
3122+
Serial.print(i);
3123+
Serial.print(" type ");
3124+
printExpansionType(OptaController.getExpansionType(i));
3125+
Serial.print(" I2C address ");
3126+
Serial.println(OptaController.getExpansionI2Caddress(i));
3127+
}
3128+
}
3129+
}
3130+
3131+
int8_t oa_index = -1;
3132+
/* -------------------------------------------------------------------------- */
3133+
/* SETUP */
3134+
/* -------------------------------------------------------------------------- */
3135+
void setup() {
3136+
/* -------------------------------------------------------------------------- */
3137+
Serial.begin(115200);
3138+
delay(2000);
3139+
3140+
OptaController.begin();
3141+
3142+
3143+
for(int i = 0; i < OptaController.getExpansionNum(); i++) {
3144+
3145+
for(int k = 0; k < OA_AN_CHANNELS_NUM;k++){
3146+
/* all channels are initialized in the same way as VOLTAGE ADC */
3147+
AnalogExpansion::beginChannelAsAdc(OptaController, i, // the device
3148+
k, // the output channel you are using
3149+
OA_CURRENT_ADC, // adc type
3150+
false, // enable pull down
3151+
false, // disable rejection
3152+
false, // disable diagnostic
3153+
0); // disable averaging
3154+
}
3155+
}
3156+
3157+
}
3158+
3159+
3160+
/* -------------------------------------------------------------------------- */
3161+
void optaAnalogTask() {
3162+
/* -------------------------------------------------------------------------- */
3163+
static long int start = millis();
3164+
if(millis() - start > PERIODIC_UPDATE_TIME) {
3165+
start = millis();
3166+
for(int i = 0; i < OptaController.getExpansionNum(); i++) {
3167+
AnalogExpansion exp = OptaController.getExpansion(i);
3168+
3169+
if(exp) {
3170+
Serial.println("\nAnalog Expansion n. " + String(exp.getIndex()));
3171+
3172+
3173+
for(int j = 0; j < OA_AN_CHANNELS_NUM; j++) {
3174+
Serial.print(" - ch " + String(j));
3175+
float value = exp.pinCurrent((uint8_t)j);
3176+
Serial.println(" -> Current " + String(value) + " mA");
3177+
}
3178+
Serial.println();
3179+
}
3180+
}
3181+
}
3182+
}
3183+
3184+
/* -------------------------------------------------------------------------- */
3185+
/* LOOP */
3186+
/* -------------------------------------------------------------------------- */
3187+
void loop() {
3188+
/* -------------------------------------------------------------------------- */
3189+
OptaController.update();
3190+
optaAnalogTask();
3191+
3192+
}
3193+
```
3194+
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
3206+
AnalogExpansion exp = OptaController.getExpansion(i);
3207+
}
3208+
```
3209+
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+
![Analog current input wiring example](assets/volt-in-a.png)
3239+
30323240
#### Analog RTD Input Mode
30333241

30343242
### Programmable Outputs

0 commit comments

Comments
 (0)