-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathINA232.cpp
More file actions
41 lines (34 loc) · 795 Bytes
/
Copy pathINA232.cpp
File metadata and controls
41 lines (34 loc) · 795 Bytes
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
#include "Arduino.h"
#include "INA232.h"
INA232::INA232(TwoWire* wire, byte adr) {
_Wire = wire;
_adr = adr;
}
void INA232::begin() {
_Wire->begin();
_Wire->beginTransmission(_adr);
_Wire->write(0x00);
_Wire->write(0x51);
_Wire->write(0x27);
_Wire->endTransmission();
}
int16_t INA232::_readReg(uint8_t reg) {
_Wire->beginTransmission(_adr);
_Wire->write(reg);
_Wire->endTransmission(false);
_Wire->requestFrom(_adr, 2);
_Wire->readBytes(_buf, 2);
return (_buf[0] << 8) | _buf[1];
}
float INA232::voltage() {
return _readReg(0x02) * 0.0016;
}
float INA232::current() {
return _readReg(0x01) * 0.000625;
}
int16_t INA232::voltageRaw() {
return _readReg(0x02);
}
int16_t INA232::currentRaw() {
return _readReg(0x01);
}