-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCosaINA219.ino
72 lines (54 loc) · 1.6 KB
/
CosaINA219.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
62
63
64
65
66
67
68
69
70
71
72
/**
* @file CosaINA219.ino
* @version 0.8
*
* @section License
* Copyright (C) 2014-2015, jeditekunum
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
#include "Cosa/IOStream.hh"
#include "Cosa/UART.hh"
#include "Cosa/OutputPin.hh"
#include "INA219.hh"
OutputPin led(Board::LED);
IOStream ios(&uart);
INA219 sensor;
void setup()
{
uart.begin(9600);
led.on();
sleep(2);
led.off();
ios << PSTR("CosaINA219: started") << endl;
sensor.begin();
ios << PSTR("bus conversion every ") << sensor.bus_time() << PSTR(" us") << endl;
ios << PSTR("shunt conversion every ") << sensor.shunt_time() << PSTR(" us") << endl;
}
void loop()
{
uint16_t uv;
uint16_t whole, fraction;
ios << PSTR("bus ") << sensor.bus() << PSTR(" mV, ");
uv = sensor.shunt();
ios << PSTR("shunt ") << uv << PSTR(" uV, ");
fraction = sensor.current(uv);
whole = fraction / 10;
fraction %= 10;
ios << PSTR("current ") << whole << PSTR(".") << fraction << PSTR(" mA, ");
fraction = sensor.power(uv);
whole = fraction / 10;
fraction %= 10;
ios << PSTR("power ") << whole << PSTR(".") << fraction << PSTR(" mW");
ios << endl;
sleep(5);
}