Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@1:0940fc3527d9, 2015-03-29 (annotated)
- Committer:
- damcclos
- Date:
- Sun Mar 29 00:51:57 2015 +0000
- Revision:
- 1:0940fc3527d9
- Parent:
- 0:63f67464aa31
- Child:
- 2:2c163adb4304
Finished
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| damcclos | 0:63f67464aa31 | 1 | #include "mbed.h" |
| damcclos | 1:0940fc3527d9 | 2 | #include "debug.h" |
| damcclos | 1:0940fc3527d9 | 3 | #include "INA219.h" |
| damcclos | 1:0940fc3527d9 | 4 | |
| damcclos | 1:0940fc3527d9 | 5 | #define SAMP_FREQ |
| damcclos | 0:63f67464aa31 | 6 | |
| damcclos | 1:0940fc3527d9 | 7 | union packet_t |
| damcclos | 1:0940fc3527d9 | 8 | { |
| damcclos | 1:0940fc3527d9 | 9 | struct |
| damcclos | 1:0940fc3527d9 | 10 | { |
| damcclos | 1:0940fc3527d9 | 11 | int header; |
| damcclos | 1:0940fc3527d9 | 12 | int index; |
| damcclos | 1:0940fc3527d9 | 13 | float busVoltage; |
| damcclos | 1:0940fc3527d9 | 14 | float shuntVoltage; |
| damcclos | 1:0940fc3527d9 | 15 | float shuntCurrent; |
| damcclos | 1:0940fc3527d9 | 16 | char zero; |
| damcclos | 1:0940fc3527d9 | 17 | }; |
| damcclos | 1:0940fc3527d9 | 18 | |
| damcclos | 1:0940fc3527d9 | 19 | const char * str; |
| damcclos | 1:0940fc3527d9 | 20 | }; |
| damcclos | 1:0940fc3527d9 | 21 | |
| damcclos | 1:0940fc3527d9 | 22 | Adafruit_INA219 sensor(I2C_SDA, I2C_SCL); |
| damcclos | 1:0940fc3527d9 | 23 | debug dbg; |
| damcclos | 0:63f67464aa31 | 24 | |
| damcclos | 0:63f67464aa31 | 25 | int main() |
| damcclos | 0:63f67464aa31 | 26 | { |
| damcclos | 1:0940fc3527d9 | 27 | dbg.init( 230400 ); |
| damcclos | 1:0940fc3527d9 | 28 | dbg.filter( DBG ); |
| damcclos | 1:0940fc3527d9 | 29 | dbg.tag( 0x1 ); |
| damcclos | 1:0940fc3527d9 | 30 | dbg.out( MSG, "Power Monitor : Initialization Starting, Version is 03/28/15\n" ); |
| damcclos | 1:0940fc3527d9 | 31 | dbg.srt(); |
| damcclos | 1:0940fc3527d9 | 32 | |
| damcclos | 1:0940fc3527d9 | 33 | sensor.begin(); |
| damcclos | 1:0940fc3527d9 | 34 | |
| damcclos | 1:0940fc3527d9 | 35 | dbg.stp("Power Monitor : Initialization"); |
| damcclos | 1:0940fc3527d9 | 36 | dbg.out( MSG, "Power Monitor : Initialization Complete\n" ); |
| damcclos | 1:0940fc3527d9 | 37 | |
| damcclos | 1:0940fc3527d9 | 38 | packet_t packet; |
| damcclos | 1:0940fc3527d9 | 39 | |
| damcclos | 1:0940fc3527d9 | 40 | packet.header = 0xFACE; |
| damcclos | 1:0940fc3527d9 | 41 | packet.index = 0; |
| damcclos | 1:0940fc3527d9 | 42 | packet.busVoltage = 0.0f; |
| damcclos | 1:0940fc3527d9 | 43 | packet.shuntVoltage = 0.0f; |
| damcclos | 1:0940fc3527d9 | 44 | packet.shuntCurrent = 0.0f; |
| damcclos | 1:0940fc3527d9 | 45 | packet.zero = 0; |
| damcclos | 1:0940fc3527d9 | 46 | |
| damcclos | 1:0940fc3527d9 | 47 | Timer timer; |
| damcclos | 1:0940fc3527d9 | 48 | timer.start(); |
| damcclos | 1:0940fc3527d9 | 49 | while(1) |
| damcclos | 1:0940fc3527d9 | 50 | { |
| damcclos | 1:0940fc3527d9 | 51 | packet.busVoltage = sensor.getBusVoltage_V(); |
| damcclos | 1:0940fc3527d9 | 52 | packet.shuntVoltage = sensor.getShuntVoltage_mV(); |
| damcclos | 1:0940fc3527d9 | 53 | packet.shuntCurrent = sensor.getCurrent_mA(); |
| damcclos | 1:0940fc3527d9 | 54 | packet.index = timer.read_us(); |
| damcclos | 1:0940fc3527d9 | 55 | dbg.inf_pc->puts( packet.str ); |
| damcclos | 0:63f67464aa31 | 56 | } |
| damcclos | 0:63f67464aa31 | 57 | } |