Skip to content

Fix accelerometer INT1 polarity so low-power mode can go idle - #78

Merged
thePunderWoman merged 2 commits into
mainfrom
fix-accel-int-polarity
Oct 25, 2026
Merged

thePunderWoman merged 2 commits into
mainfrom
fix-accel-int-polarity

Conversation

@thePunderWoman

Copy link
Copy Markdown
Member

Problem

Low-power mode still never dimmed, turned the display off, or slept the XBee, with the mode set. The serial log showed Activity: motion once at boot and never again.

The accelerometer setup wrote 0x02 to INTPIN_CONF (0x20), assuming bit 1 is INT1_LVL. The QMA6100P datasheet (Rev A1, register 0x20, p. 32) puts INT1_LVL at bit 0 and INT1_OD at bit 1, so 0x02 made INT1 open-drain and active-low. GPIO46 is a plain input with no pull-up, so the released pin floated. Reading HIGH, it counted as motion on every loop, and the idle timer never advanced. The log printed motion only once because it reports rising edges only.

Fix

  • Write 0x05: INT1 active-high, push-pull. This is also the register's reset default, and INT1 idling low is safe for GPIO46's boot strapping.
  • Move the QMA6100P register constants out of the hardware adapter into include/qma6100p_registers.h, so a native test can check every written value against the datasheet's bit layout. I re-checked the other values (RANGE, INT_EN2, INT_MAP1, MOT_CONF0, PM) against the datasheet; all were correct.
  • Add a once-a-second serial line, Power <tier>, idle <n>s, active: <sources>, so an input stuck active is visible rather than hidden by the rising-edge-only Activity: lines.

Testing

  • New test_qma6100p_registers (7 tests), including a regression test that INT1 is active-high push-pull. It fails with the old 0x02.
  • PowerManager::idleMs() covered by a new test; power_management.cpp at 100%.
  • pio test -e native: 335 tests pass. gcovr total 98%. pio run builds.

Not yet tried on hardware. Expect active: none on the new line while the controller sits still, with the idle count climbing and the tiers following.

🤖 Generated with Claude Code

thePunderWoman and others added 2 commits October 24, 2026 18:21
INTPIN_CONF (0x20) was written as 0x02 on the belief that bit 1 is
INT1_LVL. Per the QMA6100P datasheet, bit 0 is INT1_LVL and bit 1 is
INT1_OD, so 0x02 made INT1 open-drain and active-low. GPIO46 has no
pull-up, so the released pin floated, read HIGH as constant motion, and
the idle timer never advanced: no dim, no display off, no XBee sleep.
The log showed "Activity: motion" once because it only prints rising
edges.

- Write 0x05 (INT1 active-high push-pull; also the reset default).
- Move the QMA6100P register constants into qma6100p_registers.h so a
  native test can pin them to the datasheet's bit layout.
- Log the power tier, seconds idle and currently active sources once a
  second, so an input stuck active is visible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On hardware, motion registered once and never again: shaking never woke
the controller. Match Meshtastic's working wake-on-motion setup for the
QMA6100P:

- Soft reset at startup (S_RESET 0x36 = 0xB6, then 0x00): the chip stays
  powered across an ESP32 reset and can hold stale state.
- Latched interrupt, cleared on status read (INT_CFG |= 0x81).
  motionDetected() reads INT_ST0 whenever INT1 is high, so every new
  movement reports again, and a short one can't be missed between loop
  passes or during light sleep.
- Any-motion threshold 0x30 -> 0x08 (~31mg per sample step) over 2
  samples instead of 4. The datasheet gives no sample rate, and the
  stricter setting never fired.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thePunderWoman

Copy link
Copy Markdown
Member Author

Hardware test of the first commit: INT1 polarity was fixed and the controller went idle, but motion registered once and never again, so shaking didn't wake it.

Second commit adopts Meshtastic's working wake-on-motion setup for this chip (QMA6100PSensor.cpp):

  • Soft reset at startup (S_RESET 0x36 = 0xB6, then 0x00), since the chip stays powered across an ESP32 reset.
  • Latched interrupt, cleared on status read (INT_CFG |= 0x81). motionDetected() reads INT_ST0 whenever INT1 is high, so each new movement reports again and none are missed during light sleep. The datasheet contradicts itself on whether non-latched interrupts clear without that read (section 8 vs the INT_RD_CLR description).
  • Any-motion threshold lowered from 0x30 (~190 mg) over 4 samples to 0x08 (~31 mg) over 2. The preliminary datasheet has no sample-rate table to work a value out from; Meshtastic leaves it at 0.

337 tests pass, including new register tests for the latch and soft reset. pio run builds. Needs another hardware test.

@thePunderWoman
thePunderWoman merged commit e9564dd into main Oct 25, 2026
3 checks passed
@thePunderWoman
thePunderWoman deleted the fix-accel-int-polarity branch October 25, 2026 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant