The demonstration Cube runs on two 18650 Li-ion cells in a small backup module (a UPS, for uninterruptible power supply). In the workshop we plug it into the mains, yet it knows neither whether it is properly powered nor how much runtime it has left if the power is cut. Rather than one large, complete PMIC board, we added four small circuits around the module to feed our microcontrollers the information they need, and a fifth to know when the Cube is being moved.
Where the wires go
Everything starts from the terminal block that takes the UPS on the perfboard: 1 = the 5 V
coming from the rear USB-C port (VBUS_IN), 2 = ground, 3 = the positive terminal of the two cells wired in parallel (CELL_P, 3.0 to 4.2 V).
Everything arrives at our low-level “ambience” control MCU (no radio listening, no business rules: those are still handled by the Walter), an ESP32-C6 whose main job is to drive the eyes and the RGB ring. We use free pins on the same side of the board: GP14, GP18, GP19 and GP20. The I²C bus takes GP20 (SDA) and GP19 (SCL), right next to the link with the Walter (GP21 and GP22), and the ring takes GP18. The advantage of the C6 is that it reads the battery and shows the result on the ring itself. If the wires have to move to another board later, a small four-pin connector on the perfboard will be enough to move them. Only the useful power figures are passed up: available voltage, connected source, and capacity consumed, hence capacity remaining, thanks to a record of the charge and discharge cycles. So it is an MCU for basic tasks, but with a little intelligence all the same ;)
Circuit 1: is the USB cable plugged in?
Two resistors are enough to form a voltage divider that brings the 5 V from USB down to about 3 V, a voltage the C6 input accepts safely (it tolerates no more than 3.6 V).
| Ref. | Component | Between |
|---|---|---|
| R1 | 100 kΩ, ¼ W | terminal 1 (VBUS_IN) and the node |
| R2 | 150 kΩ, ¼ W | the node and ground |
| C1 | 100 nF ceramic (optional) | the node and ground |
| wire | — | the node and GP14 on the C6 |
Test, with a multimeter, before connecting GP14:
- USB cable plugged in: about 3.0 V between the node and ground.
- Cable unplugged, Cube on battery: 0 V. If we still read 5 V, the UPS is feeding its own voltage back to its input. A diode will then be needed between the USB port and the terminal block: we stop there and talk it over before going any further.
- Only then: the wire to GP14.
This voltage divider is no longer the only witness: the gauge in circuit 2 also sees the USB cable being plugged in (see below). The two cross-check each other, and the Cube still has an answer if one of the two wires breaks.
Circuit 2: the battery level
The component is a MAX17048 fuel gauge from Maxim (Analog Devices), on a small ready-made module, for example the Adafruit 5580. It is set up for a single cell (“1S”); that is the case here, because two 18650s in parallel behave like one cell of larger capacity. It is powered from the battery itself and estimates the remaining percentage from the voltage, without a sense resistor. The C6 reads it over an I²C bus, at address 0x36.
Powering and connecting the gauge
On our module, the battery comes in through one of the two JST PH connectors. The two are wired together: the second brings the battery voltage back out to the terminal block on the perfboard, which thus remains a measurement point. This wire carries no current to speak of, since the gauge draws a few tens of microamps. On the C6 side, we use the 2.54 mm pin header rather than the Qwiic connector: SDA, SCL, ground, and the logic supply pin (VIN) to the C6’s 3.3 V, never to the 5 V.
Before plugging in the battery, we check the polarity of the JST cable with a multimeter: many cables sold separately have positive and negative swapped relative to the “+” mark on the module. That is what happened to us on the first try: the battery voltage fell to 0 V, because the UPS protection cut out at once. With the wires swapped over, the gauge worked.
The point to check before connecting SDA and SCL.
On some modules, the I²C pull-up resistors are tied to the battery, which rises to 4.2 V, whereas the C6 pins tolerate no more than 3.6 V. With the module powered by the battery and the SDA and SCL wires still disconnected, measure their voltage relative to ground. Below 3.6 V (ideally 0 V or 3.3 V): go ahead and connect. Above that: remove those resistors from the module, or tie its logic supply pin to the C6’s 3.3 V if it has one, then fit the two 4.7 kΩ resistors shown in the schematic.
Test:
- A scan of the I²C bus from the C6 finds a single device, at address
0x36. - The voltage read by the gauge is within a few hundredths of a volt of what the multimeter measures on pin 3 of the terminal block.
- The percentage is reliable only after a few minutes: the gauge learns the battery at start-up.
The gauge also sees the USB cable
When we plugged in the cable, we saw the battery voltage jump up. That makes sense: the UPS starts
charging, and the charge current, multiplied by the battery’s internal resistance, adds anything from a few tens of millivolts to a hundred or so. With the cable unplugged, the battery powers the Cube and its voltage drops back by the same amount. The
gauge also gives a charge rate (CRATE register, in per cent per hour), positive when the
battery is charging, negative when it is discharging.
The C6 firmware at first relied on these voltage jumps and on the sign of the rate. In testing, that was not enough: the current surges of the 4G modem make the voltage ripple by 20 to 120 mV, and the UPS charges in pulses that raise it by 30 to 55 mV for two minutes. Since version 1.4.6, it relies on the shape of the voltage trace rather than its level. On battery, the modem makes it dip below its usual level: a downward ripple of at least 25 mV, held for three seconds, signals that the cable is unplugged. On mains, it stays within a 10 mV band for five minutes, without sagging from one minute to the next: the cable is plugged back in. The remaining percentage gives two thresholds, low at 20% and critical at 8%, with some hysteresis to avoid oscillating. We also switch off the gauge’s automatic sleep mode: otherwise, when the rate is low, it measures only every 45 seconds and would notice the cable that much later.
The percentage: a curve, not a straight line
The voltage of a lithium cell does not follow its charge in a straight line. At the bottom, between 3.0 and 3.5 V, it rises quickly for very little energy. In the middle, from about 3.6 to 4.0 V, it forms a long plateau where most of the energy is stored. Finally it climbs towards 4.2 V. Charging is not linear either: constant current up to 4.2 V, then constant voltage with a falling current, so that the last 15 to 20% take almost as long as the rest. That is why the gauge estimates the percentage from a model, and does not simply read the voltage.
That model does not match our cells: the gauge reported 49% on full cells and 7.5% when the Cube was about to switch off. The C6 therefore corrects its reading with a table, calibrated on a real three-hour discharge (extract below), and the displayed percentage never goes below 1%. Below the old zero, the Cube still ran for tens of minutes: at that stage, what matters is no longer the figure but the instruction to recharge, which the eyes then show continuously.
| Read by the gauge | Actual charge |
|---|---|
| 7.5% | 0%, displayed as 1% |
| 16% | 8% |
| 30% | 33% |
| 45% | 72% |
| 48.9% | 100% |
The top of the table still has to be redone. During these tests the Cube stayed plugged in, but the UPS was not really charging: under the current surges of the 4G board, the input voltage sagged, the module’s LED stayed blue (“full or waiting”) instead of red, and the battery was merely delaying its discharge. The module’s instruction sheet says as much: the input current must exceed what the output supplies. A 90 W laptop charger makes no difference, because without USB Power Delivery negotiation it supplies only 5 V at 3 A. A true full charge will therefore go beyond the old 100% and will let us recalibrate the model.
Circuit 3: the top ring, without a level shifter
The ring of 24 WS2812B LEDs goes on top of the Cube, the most visible spot. The plan called for a 74AHCT125 to raise the signal from 3.3 to 5 V. A WS2812B reads a “1” above 70% of its supply voltage: 3.5 V on a supply of exactly 5 V, which the C6 does not reach. But the UPS’s 5 V actually comes out between 4.5 and 4.8 V, which brings that threshold down to between 3.15 and 3.36 V. It is marginal, and to be settled by a test rather than by a calculation.
Before connecting: measure the UPS’s 5 V with the Cube switched on. Below about 4.7 V, the direct connection has a good chance of working. The signal goes from the C6 to the ring only: the C6 pin never receives 5 V, so the test carries no risk for it.
Test: cycle colours on the ring during an update over 4G and then a Bluetooth session with the phone, the moments when the radio causes the most interference. LEDs that light up in a random colour, or that flicker, point to a signal that is too weak.
If the ring flickers: the relay pixel
Without going back to the 74AHCT125, a single stand-alone WS2812B LED, hidden inside the enclosure, can act as a relay. Powered through a diode, it receives about 0.7 V less, so its threshold drops accordingly, and the C6 drives it without difficulty. It then regenerates the signal at full voltage for the ring. The firmware simply counts it as LED zero, always off.
Circuit 4: the current the Cube draws
The gauge says what is left in the cells; it does not say what the Cube is drawing at a given moment. For that, a Texas Instruments INA226 measures the voltage across a very small resistor, the shunt, placed in series with the 5 V coming out of the UPS. From it the chip derives the current. It also measures the voltage of the 5 V itself, and the C6 reads it on the same I²C bus as the gauge, at address 0x40.
Our module, with screw terminals, has a 0.002 Ω shunt (marked “R002”). At 3 A, it drops the 5 V by only 6 mV, and it resolves differences of about 1.25 mA. It is the right tool for the Cube when running, not for its sleep mode, which is measured in hundreds of microamps: for that, a bench multimeter is needed.
Wiring the INA226 module
| Module terminal | Goes to |
|---|---|
| VIN+ (“Current +” on our module) | the +5 V coming out of the UPS |
| VIN− (“Current −”) | the 5 V rail of the perfboard (Walter, C6, ring) |
| V+ (VBUS) | VIN−, to read the voltage of the 5 V |
| V− | ground |
| VCC | the C6’s 3.3 V, never the 5 V |
| GND | common ground |
| SDA, SCL | GP20 and GP19, on the same wires as the gauge |
| ALERT | nothing for now |
On our module, the V+ (VBUS) terminal is not connected to anything as supplied: without a wire to
VIN−, the INA226 measures the current correctly but reads 0 V, and so cannot compute the power. The small
IN+ and IN− holes duplicate the large terminals for a thin wire: they suit measurement, not the Cube’s
2 A. The address pins A0 and A1 stay at ground, which gives 0x40.
Test:
- Before powering up: the resistance between VIN+ and VIN− is close to zero on the multimeter. If we read anything else, the wiring bypasses the shunt.
- A scan of the I²C bus now finds two devices:
0x36(the gauge) and0x40(the INA226). - The voltage read is within a few hundredths of a volt of the multimeter’s reading on the 5 V rail. This is also the measurement that tells us whether the 5 V stays below 4.7 V, which is useful for the ring in circuit 3.
- The current read moves when the Walter connects over 4G or when the ring lights up: the direction is right. If it is negative, VIN+ and VIN− are swapped.
Circuit 5: knowing when the Cube is moved
The last circuit is not about power. It may look like a bit of a gimmick; we shall see in use. An accelerometer tells the Cube that it is being lifted, tilted or shaken, or that it has been moved within the workshop. The eyes can react to it, and the Walter can write “Cube moved” in its log. If we think the Cube might be tampered with, that is already a useful means of detection (though the best is the “honeypot” of an open Wi-Fi network, or the detection of the USB cables used in the USB-C charging port, already in place).
We use a GY-521 module, which carries an MPU-6050 (three-axis accelerometer and gyroscope) and its own regulator. Powered from the C6’s 3.3 V, it gives about 3.2 V to the chip, which accepts 2.4 to 3.46 V. Its I²C pull-up resistors pull up to this internal 3.3 V: nothing exceeds what the C6 pins tolerate. It answers at address 0x68, with no conflict with the gauge (0x36) or the INA226 (0x40).
Wiring the accelerometer
We are not wiring the alert output (INT) for now. The free pins on the GP18 to GP20 side are all taken, and the C6 reads the accelerometer about ten times a second, which is enough for “I have been moved”. If one day the C6 has to sleep and wake up when someone touches the Cube, INT will go to GP23, underneath the board.
Mounting and I²C bus
The module is mounted flat and with no play, screwed or glued to a perfboard: if it moves inside the enclosure, it reports movements that did not happen. Note also the orientation of the axes printed on the module, because the firmware will need it to know which way is up.
Three modules on the same bus means three sets of pull-up resistors in parallel, between 1.5 and 2 kΩ in total: that remains acceptable at 3.3 V. If the bus becomes temperamental, we remove those on one of the modules.
Test:
- The scan of the I²C bus finds three devices:
0x36,0x40and0x68. - The identity register (
WHO_AM_I, 0x75) returns0x68on a genuine MPU-6050. The manufacturer no longer makes this chip, and the modules sold today often carry clones, which return something else (0x70, 0x72, 0x98…): they work, but the firmware will have to accept those values. - Cube at rest: the vertical axis reads about 1 g, the other two close to zero. Cube lifted, tilted or shaken: the values move clearly.
The C6 measures and stores, the Walter collects when it chooses
The C6 reads the gauge and the INA226 every second. It could send each change to the Walter as soon as it happens. We did the opposite: the C6 stores, the Walter comes to collect. The Walter carries the 4G radio and the signed log; it is the one that knows when the modem is awake, when an update is tying up the link, when it is about to send its log to the server. So it chooses the right moment to collect the counters, the way one reads an electricity meter.
The C6 holds three things in memory:
- the present state: battery voltage and percentage, charge rate, mains or battery, charging, full or discharging, normal, low or critical level, and the 5 V and the current read by the INA226;
- counters since it started up: energy consumed in milliwatt-hours, time spent on battery, number of times plugged in, lowest voltage seen, highest current;
- the latest events (cable plugged in or unplugged, charging, full, low level, sensor found or lost), numbered consecutively in a 64-slot ring buffer.
The Walter sends a single request, POWER_GET, with the number of the last event it
received. The C6 replies with POWER: the state, the counters and the events more recent than that
number, 24 at most per reply, with a “more to come” flag that makes the Walter ask again at once. Both
frames travel over the same serial link as the commands for the eyes, delimited and checked by a CRC. On the
Walter side, collection takes place every 10 seconds, never during an update of the C6, and the
useful events go into the log under the names the Walter already used for its own sensors (mains lost,
mains restored, battery low, battery critical).
A regular collection, and an alert that does not wait
To plot the charge and discharge curves, the C6 also keeps a sample every 10 seconds (voltage, charge,
rate, cable, current), for one hour. The Walter comes to fetch them every 30 seconds, with a second request (POWER_SAMPLES_GET), and sends them to the server in batches, with its
once-a-minute status: the radio does not wake up for every measurement, and every point keeps its exact
time. Once the curves are established, the rate can come down.
An unplugged cable, on the other hand, must not wait for the next collection. The C6 then sends, of its own
accord, a very short frame, a doorbell (POWER_NOTIFY), which carries no data:
it only says “come and look”. The Walter collects at once, writes the event to the log and sends it to the
server without waiting for its usual period. If the doorbell is lost, the next collection, at most 10 seconds
later, catches the event: it is in the C6’s numbered log, not in the doorbell.
This is what industrial monitoring protocols have long done:
- DNP3 (IEEE 1815), used in electricity and water networks, combines an integrity poll, which re-reads the whole state, event polls, and unsolicited responses, which the outstation sends of its own accord for an event and which the master confirms;
- IEC 60870-5-104 marks every message with a cause of transmission: cyclic, spontaneous (an event) or a response to a general interrogation, the one that resynchronises everything;
- OPC UA separates the sampling interval, at which the measurement is read, from the publishing interval, at which it is sent, with a queue so that nothing is lost between two sends: our per-second measurement and our per-minute batch;
- LwM2M sets, for each observed value, a minimum and a maximum period between two notifications, and thresholds that trigger an immediate send; MQTT Sparkplug publishes only on change (“report by exception”), with sequence numbers that reveal a gap;
- SNMP distinguishes the trap, an unconfirmed notification, from the inform, which is confirmed: our doorbell is a trap; the alert sent to the server, which waits for its acknowledgement, is an inform;
- conversely, Modbus has no events: everything is read by polling, and a brief change between two reads is lost if it is not recorded.
The doorbell is also the principle behind a sensor’s alert pin, such as that of the Texas Instruments INA228, which stays active until the sensor is read. The cost is paid in radio time: in LTE-M, the modem saves energy by sleeping (PSM and eDRX modes), and one transmission a minute all but prevents that. This is justified on mains, less so on battery, where the batches will have to be spaced out, with the alert still going out at once.
The C6’s LED says what it sees
The C6 board carries a colour LED, off until now. It now shows, at low brightness, the state the gauge detects: flashing green when the USB cable is plugged in and the battery is charging, steady green when it is full, steady orange on battery, flashing orange when the battery is low, flashing red when it is critical, a blue flash every two seconds when the gauge does not answer, and a brief white flash at each collection by the Walter, which shows that the link is alive. If nothing answers on the I²C bus, the C6 also tries SDA and SCL the other way round, and says so in the log.
Known patterns, assembled
None of these choices is new; each one reuses an architecture pattern proven elsewhere.
- Collecting rather than sending (pull). This is the Prometheus model, which goes and fetches the measurements from each service: the collector is never swamped, and a silent target shows up straight away. Serial Modbus works the same way: the slave speaks only when the master polls it.
- The sensor hub. Phones entrust their sensors to a small, low-power processor that accumulates events in a queue while the main processor sleeps, and hands them over in one batch when it wakes (Android, “sensor batching” and “context hub”). The C6 plays that role for the Walter.
- Resuming from a cursor. The Walter keeps the number of the last event received and
asks for “what comes after”, like a client of CouchDB’s
_changes?since=feed or a Kafka consumer that keeps track of its own position. The “more to come” flag is the one found in paginated APIs (has_more). - The idempotent read. Asking the same question again changes nothing on the C6 side. A frame lost or rejected by the CRC is recovered by asking again; an event received twice is recognised by its number.
- The ring buffer that overflows, and the gap that shows. If the Walter is slow, the oldest
events are overwritten. The C6 announces the oldest one it still holds: a difference from the expected
number says how many were lost, as with the Linux kernel log (
/dev/kmsg), in which every line carries a sequence number. The Walter then records this gap in its log. - The boot epoch. At each start-up, the C6 picks a random identifier,
like Linux’s
boot_id. If it changes, the Walter knows that the numbers and the counters have started again from zero, without having to guess it from a value that goes down, which is what Prometheus and SNMP have to do for their counters. - The radio in charge of its own wake-ups. In LTE-M, the modem sleeps for long periods (PSM and eDRX modes) and cannot be reached during that time. A C6 that pushed its events would force wake-ups; by collecting them itself, the Walter aligns them with its own radio windows.
The C6 has no authority: it measures and it reports. The Walter decides what goes into the signed log, and its log, not the C6’s, is the authoritative one.
Where we stand.
The gauge is soldered in and responding (28 November 2026). The INA226 is wired on the schematic, not yet on the perfboard. Eyes firmware 1.4.2 reads the gauge and the INA226, detects the USB cable, keeps a sample every ten seconds as well as the events, and lights the status LED; Walter 0.8.29 collects them every ten seconds and sends them to the server, where the console plots the curves. The detection thresholds (40 mV, 2% per hour) come from reasoning, not yet from measurements on our cells: they will be tuned in testing. The voltage divider on GP14, the accelerometer and the ring are not read yet. The LED threshold values come from the datasheet, not from a measurement on our ring.
29 November 2026. Cable detection by the shape of the voltage trace (eyes 1.4.6), percentage corrected by a table and never below 1% (1.4.8). Flat cells: on USB power alone, the UPS does not charge while the 4G board is running; with the Walter unplugged, the LED turns red. Top of the table to be recalibrated after a full charge.
Sources
- DNP Users Group, Overview of DNP3, and Schneider Electric, unsolicited responses and data classes.
- Svenska kraftnät, TR02-04-04E: use of IEC 60870-5-104, cyclic and spontaneous transmission, general interrogation.
- OPC Foundation, OPC UA Part 4, monitored items and subscriptions.
- OMA, LwM2M Core 1.2.1 (pmin and pmax attributes, thresholds); IETF, RFC 7641 (CoAP Observe).
- Eclipse Foundation, Sparkplug 3.0: report by exception, birth and death of nodes.
- IETF, RFC 3416: SNMP operations, trap and inform.
- Texas Instruments, INA228: alert pin held until the sensor is read.
- Prometheus, FAQ: why collection is done by fetching (pull).
- Android, Batching and Context Hub Runtime Environment: the sensor processor that keeps the events while the main processor sleeps.
- Apache CouchDB, changes feed
and the
sinceparameter: resuming from a cursor. - Linux kernel, /dev/kmsg: numbered circular log, lost messages spotted by the sequence number.
- IETF, RFC 9110, § 9.2: safe and idempotent methods.
- GSMA, LTE-M Deployment Guide: PSM and eDRX power-saving modes.
- TDK InvenSense, MPU-6050: three-axis accelerometer and gyroscope, read over I²C; the chip is no longer recommended for new products.
- Texas Instruments, INA226: current and voltage measurement across a shunt, read over I²C.
- Analog Devices, MAX17048: fuel gauge for a single lithium cell, read over I²C.
- Adafruit, MAX17048 LiPoly / LiIon Fuel Gauge, ref. 5580: a ready-made module.
- Worldsemi, datasheet for the WS2812B: logic-high threshold at 0.7 × VDD.
- Espressif, ESP32-C6: inputs limited to the 3.3 V supply voltage plus a margin, that is 3.6 V.
- Ops-Devices, Hardware v1.5: a Cube that survives a power cut, on paper and Any cable, no jumper: the complete power board that will replace these small circuits; Choosing the Walter board: the board that carries the 4G radio and the log; Making a connected device last: how cells age, and the indicators to watch in service.
A question, an objection? contact@ops-devices.eu, or on Bluesky.