Skip to content

INA219

This leaf controls a INA219 current/voltage sensor through I2C protocol.

It is useful when you need control over an electrical load or when running with batteries and you need to measure the battery status.

It can also be used to build an oscilloscope.

Functionalities

It collects measurements from sensor for samp_cycles cycles waiting each cycle a samp_interval. After this collection time, it computes the average measure and updates the final value.

This leaf can be used in two ways through the working_mode parameter:

  • sending measurement to a telegraf server, in influxdb protocol through UDP. This is useful if you want to analyze metrics through influxdb or eg. directly connected to a grafana server

  • using internal parameters to store measured values

Parameters

name description type default access storage valid values
active whether INA219 shall be enabled boolean true GN_LEAF_PARAM_ACCESS_ALL GN_LEAF_PARAM_STORAGE_PERSISTED true/false
ip ip address of the server string null GN_LEAF_PARAM_ACCESS_ALL GN_LEAF_PARAM_STORAGE_PERSISTED 16 char array
port port of the server double 8094 GN_LEAF_PARAM_ACCESS_ALL GN_LEAF_PARAM_STORAGE_PERSISTED true/false
samp_cycles sampling cycles double 1 GN_LEAF_PARAM_ACCESS_ALL GN_LEAF_PARAM_STORAGE_PERSISTED positive double
samp_interval sampling interval, (approx) in msec double 1000 GN_LEAF_PARAM_ACCESS_ALL GN_LEAF_PARAM_STORAGE_PERSISTED positive double
sda SDA PIN double 26 GN_LEAF_PARAM_ACCESS_NODE_INTERNAL GN_LEAF_PARAM_STORAGE_PERSISTED positive double
scl SCL PIN double 26 GN_LEAF_PARAM_ACCESS_NODE_INTERNAL GN_LEAF_PARAM_STORAGE_PERSISTED positive double
working_mode 0 = through UDP via influxdb protocol, 1 = parameters, 2 both double 1 GN_LEAF_PARAM_ACCESS_ALL GN_LEAF_PARAM_STORAGE_PERSISTED double positive
power last power measured, in mW double 0 GN_LEAF_PARAM_ACCESS_NETWORK GN_LEAF_PARAM_STORAGE_VOLATILE any
voltage last voltage measured, in mV double 0 GN_LEAF_PARAM_ACCESS_NETWORK GN_LEAF_PARAM_STORAGE_VOLATILE any
shunt_voltage last shunt voltage measured, in mV double 0 GN_LEAF_PARAM_ACCESS_NETWORK GN_LEAF_PARAM_STORAGE_VOLATILE any
bus_voltage last bus voltage measured, in mV double 0 GN_LEAF_PARAM_ACCESS_NETWORK GN_LEAF_PARAM_STORAGE_VOLATILE any
current last current measured, in mA double 0 GN_LEAF_PARAM_ACCESS_NETWORK GN_LEAF_PARAM_STORAGE_VOLATILE any

Example

    gn_leaf_handle_t ina219 = gn_leaf_create(node, "ina219", gn_leaf_ina219_config, 8192, GN_LEAF_TASK_PRIORITY);
    gn_leaf_param_init_bool(ina219, GN_LEAF_INA219_PARAM_ACTIVE, true);

    char* ip = calloc(16, sizeof(char));
    strncpy(ip, "192.168.1.20", 16);

    gn_leaf_param_init_string(ina219, GN_LEAF_INA219_PARAM_IP, ip);
    gn_leaf_param_init_double(ina219, GN_LEAF_INA219_PARAM_PORT, 8094);
    gn_leaf_param_init_double(ina219, GN_LEAF_INA219_PARAM_SAMPLING_CYCLES, 5);
    gn_leaf_param_init_double(ina219, GN_LEAF_INA219_PARAM_SAMPLING_INTERVAL, 10);
    gn_leaf_param_init_double(ina219, GN_LEAF_INA219_PARAM_SDA, 26);
    gn_leaf_param_init_double(ina219, GN_LEAF_INA219_PARAM_SCL, 27);
    gn_leaf_param_init_double(ina219, GN_LEAF_INA219_PARAM_WORKING_MODE, 1);