Here is a MM2 tested program for monitoring the tilt switch and Li-ion cell.
It can read the cell volts up to 4.1V with the divider values shown in the diagram. If you only need up to 3.3V the lower leg can be removed.
The current through the upper leg of the divider doesn't get wasted while the MM2 is sleeping. The lower leg of the divider gets switched off and the diode diverts the current to the 3.3V rail, helping power the MM2. When the cell volts are less than 3.4V no current will flow through it anyway.
' "Test cell V & tilt.bas"
Print "Time",,"count","Cell V",,"Tilt"
Do
SetPin 25, DOUT, OC 'switch for voltage divider lower leg
Pin(25) = 0
SetPin 24, AIN 'Cell Volts
SetPin 21, DIN, Pullup 'Tilt switch input
SetPin 22, DOUT, OC 'Tilt switch simulator, link to pin 21. Delete if real tilt sw. used
Pin(22) = 1
If (n Mod 5)=4 Then Pin(22)=0 'activate simulated tilt switch
' Pause 10 'Allow time for capacitor on AIN to settle. If cap. isn't used remove this
RTC gettime 'optional
Print Time$, n, Pin(24)*(390+100)/390, Not Pin(21) 'insert your voltage divider values here
SetPin 24, off
SetPin 25, off
SetPin 21, off
SetPin 22, off
n=n+1 'n = loop counter - optional
If n > 19 Then End 'remove this for continuous running
CPU sleep 5
Loop

> RUN
Time count Cell V Tilt
01:37:18 0 4.10765 0
01:37:23 1 4.12724 0
01:37:27 2 3.99417 0
01:37:32 3 3.96918 0
01:37:37 4 3.81719 1
01:37:42 5 3.74221 0
01:37:46 6 3.64764 0
01:37:51 7 3.44229 0
01:37:56 8 3.33219 0
01:38:01 9 3.25045 1
01:38:06 10 3.05997 0
01:38:10 11 2.85259 0
01:38:15 12 2.68441 0
01:38:20 13 2.16494 0
01:38:25 14 1.79613 1
01:38:30 15 1.41112 0
01:38:34 16 1.19629 0
01:38:39 17 0.880838 0
01:38:44 18 0.426234 0
01:38:49 19 0.263979 1
>
Edited 2025-10-05 20:05 by phil99Footnote added 2025-10-06 08:58 by phil99In the circuit above the 5V to 3.3V regulator is a switch-mode type which is why I added the capacitor on the AIN pin (and Pause in the program). I assumed that noise would be an issue (similar to the cell-to-5V converter in Grogster's setup), however removing the capacitor and Pause make little difference. The noise is fairly low at about 20mV.