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@2:2c163adb4304, 2015-03-29 (annotated)
- Committer:
- prinonis
- Date:
- Sun Mar 29 06:54:47 2015 +0000
- Revision:
- 2:2c163adb4304
- Parent:
- 1:0940fc3527d9
matlab communication working, sensor reading are not changing.
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 | { |
| prinonis | 2:2c163adb4304 | 11 | unsigned int index; |
| damcclos | 1:0940fc3527d9 | 12 | float busVoltage; |
| damcclos | 1:0940fc3527d9 | 13 | float shuntVoltage; |
| damcclos | 1:0940fc3527d9 | 14 | float shuntCurrent; |
| damcclos | 1:0940fc3527d9 | 15 | }; |
| damcclos | 1:0940fc3527d9 | 16 | |
| prinonis | 2:2c163adb4304 | 17 | char raw[]; |
| damcclos | 1:0940fc3527d9 | 18 | }; |
| damcclos | 1:0940fc3527d9 | 19 | |
| damcclos | 0:63f67464aa31 | 20 | int main() |
| damcclos | 0:63f67464aa31 | 21 | { |
| prinonis | 2:2c163adb4304 | 22 | Adafruit_INA219 sensor(I2C_SDA, I2C_SCL); |
| prinonis | 2:2c163adb4304 | 23 | packet_t packet; |
| prinonis | 2:2c163adb4304 | 24 | Timer timer; |
| prinonis | 2:2c163adb4304 | 25 | debug dbg; |
| damcclos | 1:0940fc3527d9 | 26 | |
| prinonis | 2:2c163adb4304 | 27 | dbg.init( 230400 ); |
| prinonis | 2:2c163adb4304 | 28 | sensor.begin(); |
| prinonis | 2:2c163adb4304 | 29 | timer.start(); |
| prinonis | 2:2c163adb4304 | 30 | |
| prinonis | 2:2c163adb4304 | 31 | unsigned char header[] = { 0xDE, 0xAD }; |
| damcclos | 1:0940fc3527d9 | 32 | |
| prinonis | 2:2c163adb4304 | 33 | while( 1 ) |
| damcclos | 1:0940fc3527d9 | 34 | { |
| prinonis | 2:2c163adb4304 | 35 | dbg.inf_pc->putc( header[0] ); |
| prinonis | 2:2c163adb4304 | 36 | dbg.inf_pc->putc( header[1] ); |
| prinonis | 2:2c163adb4304 | 37 | |
| prinonis | 2:2c163adb4304 | 38 | packet.index = timer.read_us(); |
| prinonis | 2:2c163adb4304 | 39 | packet.busVoltage = sensor.getBusVoltage_V(); |
| damcclos | 1:0940fc3527d9 | 40 | packet.shuntVoltage = sensor.getShuntVoltage_mV(); |
| damcclos | 1:0940fc3527d9 | 41 | packet.shuntCurrent = sensor.getCurrent_mA(); |
| prinonis | 2:2c163adb4304 | 42 | |
| prinonis | 2:2c163adb4304 | 43 | for( int i = 0; i < sizeof( packet ); i++ ) |
| prinonis | 2:2c163adb4304 | 44 | { |
| prinonis | 2:2c163adb4304 | 45 | dbg.inf_pc->putc( packet.raw[i] ); |
| prinonis | 2:2c163adb4304 | 46 | } |
| prinonis | 2:2c163adb4304 | 47 | |
| prinonis | 2:2c163adb4304 | 48 | dbg.flip(); |
| prinonis | 2:2c163adb4304 | 49 | wait_ms( 1 ); |
| damcclos | 0:63f67464aa31 | 50 | } |
| damcclos | 0:63f67464aa31 | 51 | } |