voltage and current sensing

This commit is contained in:
2024-04-23 23:25:03 -06:00
parent 8bf321c11c
commit e1772508fe
2 changed files with 43 additions and 9 deletions

View File

@ -78,14 +78,46 @@ int main(void)
rows,
cfb_get_display_parameter(dev, CFB_DISPLAY_COLS));
cfb_framebuffer_invert(dev);
cfb_set_kerning(dev, 3);
const struct device *ina;
ina = DEVICE_DT_GET(DT_NODELABEL(ina231));
if (!device_is_ready(dev))
{
printf("Device %s not ready\n", ina->name);
return 0;
}
while (1)
{
for (int i = 0; i < MIN(x_res, y_res); i++)
{
int ret;
ret = sensor_sample_fetch(ina);
if (ret < 0)
{
LOG_ERR("Could not fetch sample (%d)", ret);
return 0;
}
struct sensor_value voltage, current;
ret = sensor_channel_get(ina, SENSOR_CHAN_VOLTAGE, &voltage);
if (ret < 0)
{
LOG_ERR("Could not get sample (%d)", ret);
return 0;
}
ret = sensor_channel_get(ina, SENSOR_CHAN_CURRENT, &current);
if (ret < 0)
{
LOG_ERR("Could not get sample (%d)", ret);
return 0;
}
printf("voltage: %d.%06d\tcurrent: %d.%06d\n", voltage.val1, voltage.val2, current.val1, current.val2);
cfb_framebuffer_clear(dev, false);
if (cfb_print(dev,
"0123456789mMgj!\"§$%&/()=",

View File

@ -101,12 +101,6 @@
label = "Interrupt from BMP388 barometer";
zephyr,code = <INPUT_KEY_0>;
};
int_pow: int_pow {
gpios = <&gpio0 31 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Interrupt from current sensor";
zephyr,code = <INPUT_KEY_0>;
};
};
@ -145,7 +139,6 @@
pinctrl-1 = <&i2c0_sleep>;
pinctrl-names = "default", "sleep";
ssd1306: ssd1306@3d {
compatible = "solomon,ssd1306fb";
reg = <0x3d>;
@ -159,6 +152,15 @@
com-invdir;
prechargep = <0x22>;
};
ina231: ina231@45 {
compatible = "ti,ina230";
reg = <0x45>;
// irq-gpios = <&gpio0 31 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
current-lsb-microamps = <7>;
rshunt-micro-ohms = <50000>;
adc-mode = "Bus and shunt voltage continuous";
};
};
&spi1 {