Skip to content

Commit f3f933b

Browse files
committed
RTD section ready
1 parent ab5c326 commit f3f933b

File tree

4 files changed

+159
-7
lines changed

4 files changed

+159
-7
lines changed
1.66 MB
Loading
1.66 MB
Loading

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

Lines changed: 159 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3408,26 +3408,178 @@ The Analog Expansion input channels can be used for temperature metering with **
34083408
| Input range | 0...1 MΩ |
34093409
| Bias voltage | 2.5 V |
34103410

3411-
***2 wires RTDs can be connected to any of the eight channels.***
3411+
2 wires RTDs can be connected to any of the eight channels as follows:
34123412

3413-
**3 Wires RTD Connection**
3413+
![2 Wires RTD connection example](assets/rtd-2wires-user.png)
34143414

3415-
RTD with 3 wires has generally two wires with the same color.
3415+
3 wires RTDs has generally two wires with the same color.
34163416

34173417
- Connect the two wires with the same color to the - and the ICx screw terminals respectively.
34183418
- Connect the wire with a different color to the + screw terminal.
34193419

34203420
***3 wires RTD can only be measured by channels __I1__ and __I2__.***
34213421

3422-
![3 Wires RTD connection example](assets/rtd-3wires.png)
3422+
![3 Wires RTD connection example](assets/rtd-3wires-user.png)
34233423

3424-
To perform measurements of an input terminal configured as RTD use built-in function `pinCurrent()` as shown below:
3424+
To perform measurements of an input terminal configured as RTD use the built-in function `getRtd()` as shown below:
34253425

34263426
```arduino
3427-
float value = exp.pinCurrent(<input>);
3427+
float value = exp.getRtd(<input>); // this returns the resistive value measured in the input in ohms
34283428
```
34293429

3430-
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**:
3430+
For the following example a 2 wires **PT1000** will be used connected to **I1**. The sketch below will let you measure the resistance and convert it to a temperature value. This sketch is based on the built-in example found in **File > Examples > Arduino_Opta_Blueprint > Analog > RTD**:
3431+
3432+
```arduino
3433+
#include "OptaBlue.h"
3434+
3435+
#define PERIODIC_UPDATE_TIME 2000
3436+
#define DELAY_AFTER_SETUP 1000
3437+
// RTD constants
3438+
float a = 0.0039083;
3439+
float b = -0.0000005775;
3440+
3441+
/* -------------------------------------------------------------------------- */
3442+
void printExpansionType(ExpansionType_t t) {
3443+
/* -------------------------------------------------------------------------- */
3444+
if (t == EXPANSION_NOT_VALID) {
3445+
Serial.print("Unknown!");
3446+
} else if (t == EXPANSION_OPTA_DIGITAL_MEC) {
3447+
Serial.print("Opta --- DIGITAL [Mechanical] ---");
3448+
} else if (t == EXPANSION_OPTA_DIGITAL_STS) {
3449+
Serial.print("Opta --- DIGITAL [Solid State] ---");
3450+
} else if (t == EXPANSION_DIGITAL_INVALID) {
3451+
Serial.print("Opta --- DIGITAL [!!Invalid!!] ---");
3452+
} else if (t == EXPANSION_OPTA_ANALOG) {
3453+
Serial.print("~~~ Opta ANALOG ~~~");
3454+
} else {
3455+
Serial.print("Unknown!");
3456+
}
3457+
}
3458+
3459+
/* -------------------------------------------------------------------------- */
3460+
void printExpansionInfo() {
3461+
/* -------------------------------------------------------------------------- */
3462+
static long int start = millis();
3463+
3464+
if (millis() - start > 5000) {
3465+
start = millis();
3466+
Serial.print("Number of expansions: ");
3467+
Serial.println(OptaController.getExpansionNum());
3468+
3469+
for (int i = 0; i < OptaController.getExpansionNum(); i++) {
3470+
Serial.print("Expansion n. ");
3471+
Serial.print(i);
3472+
Serial.print(" type ");
3473+
printExpansionType(OptaController.getExpansionType(i));
3474+
Serial.print(" I2C address ");
3475+
Serial.println(OptaController.getExpansionI2Caddress(i));
3476+
}
3477+
}
3478+
}
3479+
3480+
int8_t oa_index = -1;
3481+
/* -------------------------------------------------------------------------- */
3482+
/* SETUP */
3483+
/* -------------------------------------------------------------------------- */
3484+
void setup() {
3485+
/* -------------------------------------------------------------------------- */
3486+
Serial.begin(115200);
3487+
delay(2000);
3488+
Serial.println("*** Opta Analog RTD example ***");
3489+
3490+
OptaController.begin();
3491+
3492+
for (int i = 0; i < OptaController.getExpansionNum(); i++) {
3493+
3494+
for (int k = 0; k < OA_AN_CHANNELS_NUM; k++) {
3495+
/* all channels are initialized in the same way as RTD */
3496+
AnalogExpansion::beginChannelAsRtd(OptaController, i, // the device
3497+
k, // the output channel you are using
3498+
false, // use 3 wire RTD
3499+
0.2); // current used on RTD in mA
3500+
}
3501+
}
3502+
}
3503+
3504+
/* -------------------------------------------------------------------------- */
3505+
void optaAnalogTask() {
3506+
/* -------------------------------------------------------------------------- */
3507+
3508+
static long int start = millis();
3509+
if (millis() - start > PERIODIC_UPDATE_TIME) {
3510+
start = millis();
3511+
3512+
for (int i = 0; i < OptaController.getExpansionNum(); i++) {
3513+
AnalogExpansion aexp = OptaController.getExpansion(i);
3514+
if (aexp) {
3515+
Serial.println("Expansion n. " + String(aexp.getIndex()));
3516+
for (int j = 0; j < 8; j++) {
3517+
float value = aexp.getRtd((uint8_t)j);
3518+
if (value != -1.00 && value < 1000000.0) { // if the channel reading is valid
3519+
Serial.print("ch ");
3520+
Serial.print(j);
3521+
Serial.print(" -> ");
3522+
Serial.print(value);
3523+
Serial.print(" Ω");
3524+
float temp = ((1.0 / 1000.0) * (-10.0 * sqrt(10.0) * sqrt(-b * value + 250.0 * pow(a, 2.0) + 1000.0 * b) + 500.0 * a)) / b;
3525+
Serial.print(" -> ");
3526+
Serial.print(temp);
3527+
Serial.print(" C");
3528+
Serial.println();
3529+
}
3530+
}
3531+
}
3532+
}
3533+
}
3534+
}
3535+
3536+
/* -------------------------------------------------------------------------- */
3537+
/* LOOP */
3538+
/* -------------------------------------------------------------------------- */
3539+
void loop() {
3540+
/* -------------------------------------------------------------------------- */
3541+
OptaController.update();
3542+
//printExpansionInfo();
3543+
optaAnalogTask();
3544+
}
3545+
```
3546+
3547+
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.
3548+
3549+
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.
3550+
3551+
`OptaController.update()` function DOES NOT:
3552+
* Check if an expansion has been removed and remove their objects
3553+
* Update any data from or to the expansion
3554+
3555+
The expansion object in the example above is defined using the `OptaController.getExpansion(i);` function, as follows:
3556+
3557+
```arduino
3558+
for(int i = 0; i < OptaController.getExpansionNum(); i++) { // check all the available expansion slots
3559+
AnalogExpansion exp = OptaController.getExpansion(i);
3560+
}
3561+
```
3562+
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.
3563+
3564+
The expansion channels are configured as **RTD inputs** using the function `beginChannelAsRtd` alongside the following parameters:
3565+
3566+
```arduino
3567+
AnalogExpansion::beginChannelAsRtd(OptaController, i, // the device
3568+
k, // the output channel you are using
3569+
false, // use 3 wire RTD
3570+
0.2); // current used on RTD in mA
3571+
```
3572+
3573+
The current parameter in the function above will depend on your RTD type, study your sensor datasheet to find the more suitable for it, in this case, the **PT1000** used recommends a **0.2 mA** current.
3574+
3575+
The function `optaAnalogTask()` reads all the RTDs connected and converts their resistive value to a temperature.
3576+
3577+
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:
3578+
3579+
```
3580+
Expansion n. 0
3581+
ch 0 -> 1101.66 Ω -> 25.91 C
3582+
```
34313583

34323584
### Programmable Outputs
34333585

0 commit comments

Comments
 (0)