-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathRAK5801_4-20mA.ino
61 lines (51 loc) · 1.13 KB
/
RAK5801_4-20mA.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @file RAK5801_4-20mA.ino
* @author rakwireless.com
* @brief Print current value.
* @version 0.2
* @date 2020-07-28
* @copyright Copyright (c) 2020
*/
#include <Arduino.h>
#include <Wire.h>
#ifdef _VARIANT_RAK4630_
#include <Adafruit_TinyUSB.h>
#endif
#define NO_OF_SAMPLES 32
void setup()
{
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
/* WisBLOCK 5801 Power On*/
pinMode(WB_IO1, OUTPUT);
digitalWrite(WB_IO1, HIGH);
/* WisBLOCK 5801 Power On*/
}
void loop()
{
int i;
int mcu_ain_raw = 0;
int average_raw;
float voltage_ain;
float current_sensor; // variable to store the value coming from the sensor
for (i = 0; i < NO_OF_SAMPLES; i++)
{
mcu_ain_raw += analogRead(WB_A1); // select the input pin A1 for the potentiometer
}
average_raw = mcu_ain_raw / i;
voltage_ain = average_raw * 3.6 / 1024; //raef 3.6v / 10bit ADC
current_sensor = voltage_ain / 149.9*1000; //WisBlock RAK5801 (0 ~ 20mA) I=U/149.9(mA)
Serial.printf("-------current_sensor------ = %f mA\n", current_sensor);
delay(2000);
}