Skip to content

Commit 2052fa6

Browse files
committed
Update example a bit
Reduce the output. Come up with a more realistic example monitoring the memory usage of another device. Add USB logging. Now matches ina260 SPI example.
1 parent 14e6b08 commit 2052fa6

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

i2c/ina228_i2c/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ add_executable(ina228_i2c ina228_i2c.c)
22

33
# pull in common dependencies and additional i2c hardware support
44
target_link_libraries(ina228_i2c
5-
pico_stdlib
6-
hardware_i2c)
5+
pico_stdlib
6+
hardware_i2c
7+
)
8+
# Wait at most 3s for stdio_usb to be ready
9+
target_compile_definitions(ina228_i2c PRIVATE
10+
PICO_STDIO_USB_CONNECT_WAIT_TIMEOUT_MS=3000
11+
)
712

813
# create map/bin/hex file etc.
914
pico_add_extra_outputs(ina228_i2c)
1015

1116
# add url via pico_set_program_url
1217
example_auto_set_url(ina228_i2c)
1318

19+
pico_enable_stdio_usb(ina228_i2c 1)
20+
pico_enable_stdio_uart(ina228_i2c 1)

i2c/ina228_i2c/ina228_i2c.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
#include "hardware/i2c.h"
44
#include <math.h>
55

6-
// LED GPIO
7-
#define EXT_LED_GPIO 2
8-
96
// INA228 breakout board shunt resistance in Ohms
107
#define R_SHUNT 0.015
118

@@ -100,11 +97,6 @@ int main()
10097
{
10198
stdio_init_all();
10299

103-
// Initialise external LED and turn it on (so we can measure some current)
104-
gpio_init(EXT_LED_GPIO);
105-
gpio_set_dir(EXT_LED_GPIO, GPIO_OUT);
106-
gpio_put(EXT_LED_GPIO, true);
107-
108100
// I2C initialisation
109101
i2c_init(i2c_default, 400*1000);
110102

@@ -119,7 +111,11 @@ int main()
119111

120112
while (true) {
121113
ina228_read(&vshunt, &vbus, &dietemp, &current, &power, &energy, &charge);
114+
#if 0
122115
printf("INA228 Measurements:\nVSHUNT: %f V\nVBUS: %f V\nDIETEMP: %f °C\nCURRENT: %f A\nPOWER: %f W\nENERGY: %f J\nCHARGE: %f C\n-----------------\n", vshunt, vbus, dietemp, current, power, energy, charge);
116+
#else
117+
printf("current: %.2f mA voltage: %.2f V power: %.2f mW\n", current * 1000, vbus, power * 1000);
118+
#endif
123119
sleep_ms(1000);
124120
}
125121
}

i2c/ina228_i2c/ina228_i2c.fzz

475 KB
Binary file not shown.

i2c/ina228_i2c/ina228_i2c.png

64.1 KB
Loading

0 commit comments

Comments
 (0)