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
Diff: main.cpp
- Revision:
- 1:0940fc3527d9
- Parent:
- 0:63f67464aa31
- Child:
- 2:2c163adb4304
--- a/main.cpp Sat Mar 28 22:57:26 2015 +0000
+++ b/main.cpp Sun Mar 29 00:51:57 2015 +0000
@@ -1,13 +1,57 @@
#include "mbed.h"
+#include "debug.h"
+#include "INA219.h"
+
+#define SAMP_FREQ
-DigitalOut gpo(D0);
-DigitalOut led(LED_RED);
+union packet_t
+{
+ struct
+ {
+ int header;
+ int index;
+ float busVoltage;
+ float shuntVoltage;
+ float shuntCurrent;
+ char zero;
+ };
+
+ const char * str;
+};
+
+Adafruit_INA219 sensor(I2C_SDA, I2C_SCL);
+debug dbg;
int main()
{
- while (true) {
- gpo = !gpo; // toggle pin
- led = !led; // toggle led
- wait(0.2f);
+ dbg.init( 230400 );
+ dbg.filter( DBG );
+ dbg.tag( 0x1 );
+ dbg.out( MSG, "Power Monitor : Initialization Starting, Version is 03/28/15\n" );
+ dbg.srt();
+
+ sensor.begin();
+
+ dbg.stp("Power Monitor : Initialization");
+ dbg.out( MSG, "Power Monitor : Initialization Complete\n" );
+
+ packet_t packet;
+
+ packet.header = 0xFACE;
+ packet.index = 0;
+ packet.busVoltage = 0.0f;
+ packet.shuntVoltage = 0.0f;
+ packet.shuntCurrent = 0.0f;
+ packet.zero = 0;
+
+ Timer timer;
+ timer.start();
+ while(1)
+ {
+ packet.busVoltage = sensor.getBusVoltage_V();
+ packet.shuntVoltage = sensor.getShuntVoltage_mV();
+ packet.shuntCurrent = sensor.getCurrent_mA();
+ packet.index = timer.read_us();
+ dbg.inf_pc->puts( packet.str );
}
}
\ No newline at end of file