1.. zephyr:code-sample:: fuel_gauge
2 :name: Fuel Gauge
3
4 Use fuel gauge API to access fuel gauge properties and get charge information.
5
6Overview
7********
8
9This sample shows how to use the Zephyr :ref:`fuel_gauge_api` API driver for.
10
11First, the sample tries to read all public fuel gauge properties to verify which are supported by
12the used fuel gauge driver.
13Second, the sample then reads the battery percentage and voltage proper periodically using the
14``FUEL_GAUGE_RELATIVE_STATE_OF_CHARGE`` and ``FUEL_GAUGE_VOLTAGE`` properties.
15
16.. note::
17 The sample does not set/write any properties to avoid misconfiguration the IC.
18
19Building and Running
20********************
21
22The sample can be configured to support a fuel gauge.
23
24Features
25********
26By using this fuel gauge you can get the following information:
27
28 * Read all public fuel gauge properties
29 * Battery charge status as percentage (periodically)
30 * Battery voltage (periodically)
31
32Sample output
33*************
34
35.. code-block:: console
36
37 *** Booting Zephyr OS build f95fd665ad26 ***
38 [00:00:00.116,000] <inf> app: Found device "lc709203f@0b"
39 [00:00:00.116,000] <inf> app: Test-Read generic fuel gauge properties to verify which are supported
40 [00:00:00.116,000] <inf> app: Info: not all properties are supported by all fuel gauges!
41 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_AVG_CURRENT" is not supported
42 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_CURRENT" is not supported
43 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_CHARGE_CUTOFF" is not supported
44 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_CYCLE_COUNT" is not supported
45 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_CONNECT_STATE" is not supported
46 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_FLAGS" is not supported
47 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_FULL_CHARGE_CAPACITY" is not supported
48 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_PRESENT_STATE" is not supported
49 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_REMAINING_CAPACITY" is not supported
50 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_RUNTIME_TO_EMPTY" is not supported
51 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_RUNTIME_TO_FULL" is not supported
52 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_SBS_MFR_ACCESS" is not supported
53 [00:00:00.116,000] <inf> app: Property "FUEL_GAUGE_ABSOLUTE_STATE_OF_CHARGE" is not supported
54 [00:00:00.122,000] <inf> app: Property "FUEL_GAUGE_RELATIVE_STATE_OF_CHARGE" is supported
55 [00:00:00.122,000] <inf> app: Relative state of charge: 100
56 [00:00:00.122,000] <err> lc709203f: Thermistor not enabled
57 [00:00:00.122,000] <inf> app: Property "FUEL_GAUGE_TEMPERATURE" is not supported
58 [00:00:00.123,000] <inf> app: Property "FUEL_GAUGE_VOLTAGE" is supported
59 [00:00:00.123,000] <inf> app: Voltage: 4190000
60 [00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_SBS_MODE" is supported
61 [00:00:00.124,000] <inf> app: SBS mode: 1
62 [00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_CHARGE_CURRENT" is not supported
63 [00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_CHARGE_VOLTAGE" is not supported
64 [00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_STATUS" is not supported
65 [00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_DESIGN_CAPACITY" is supported
66 [00:00:00.124,000] <inf> app: Design capacity: 500
67 [00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_DESIGN_VOLTAGE" is not supported
68 [00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_SBS_ATRATE" is not supported
69 [00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_SBS_ATRATE_TIME_TO_FULL" is not supported
70 [00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_SBS_ATRATE_TIME_TO_EMPTY" is not supported
71 [00:00:00.124,000] <inf> app: Property "FUEL_GAUGE_SBS_ATRATE_OK" is not supported
72 [00:00:00.125,000] <inf> app: Property "FUEL_GAUGE_SBS_REMAINING_CAPACITY_ALARM" is not supported
73 [00:00:00.125,000] <inf> app: Property "FUEL_GAUGE_SBS_REMAINING_TIME_ALARM" is not supported
74 [00:00:00.125,000] <err> app: Error: cannot get property "FUEL_GAUGE_MANUFACTURER_NAME": -88
75 [00:00:00.125,000] <err> app: Error: cannot get property "FUEL_GAUGE_DEVICE_NAME": -88
76 [00:00:00.125,000] <err> app: Error: cannot get property "FUEL_GAUGE_DEVICE_CHEMISTRY": -88
77 [00:00:00.125,000] <inf> app: Property "FUEL_GAUGE_CURRENT_DIRECTION" is supported
78 [00:00:00.125,000] <inf> app: Current direction: 0
79 [00:00:00.126,000] <inf> app: Property "FUEL_GAUGE_STATE_OF_CHARGE_ALARM" is supported
80 [00:00:00.126,000] <inf> app: State of charge alarm: 8
81 [00:00:00.127,000] <inf> app: Property "FUEL_GAUGE_LOW_VOLTAGE_ALARM" is supported
82 [00:00:00.127,000] <inf> app: Low voltage alarm: 0
83 [00:00:00.127,000] <inf> app: Polling fuel gauge data 'FUEL_GAUGE_RELATIVE_STATE_OF_CHARGE' & 'FUEL_GAUGE_VOLTAGE'
84 [00:00:00.128,000] <inf> app: Fuel gauge data: Charge: 100%, Voltage: 4190mV
85 [00:00:05.130,000] <inf> app: Fuel gauge data: Charge: 100%, Voltage: 4190mV
86 [00:00:10.131,000] <inf> app: Fuel gauge data: Charge: 100%, Voltage: 4190mV
87