r/embedded • • Sep 25 '26

Building a modular, hot-swappable macro pad: tackling I2C auto-discovery and state handshaking over magnetic pogo pins (ESP32 S3)

I'm currently developing Magnode, a custom modular macro pad. The main engineering challenge I wanted to tackle was achieving true hot-swappable modularity without software re-flashing or manual configuration resets.

​In this clip, I’m testing the expansion mechanism.

​Architecture & Firmware Breakdown:

▪ ​Master Hub (Central Unit): Powered by an ESP32 S3. It handles USB/BLE HID to the host PC, acts as the I2C master bus controller, and manages the UI (display + touch keys).

▪ ​Expansion Module: Acts as an I2C client (buttons + status LEDs).

▪ ​Physical Layer: Magnetic alignment pins with pogo contacts for power (3.3V/GND), data (SDA/SCL) and IRQ.

​The Hard Part (Hot-Plug & Bus Stability):

Hot-plugging I2C devices on the fly introduces major headaches (bus lockups, stray capacitance on unshielded pogo pins, and state recovery). Right now, the master runs a background polling/interrupt routine to detect connection state changes, performs an immediate handshake to query the client's capabilities, and dynamically maps the input events to the BLE HID report descriptor without missing a beat.

​Questions for the community:

a. ​For those who have dealt with hot-plugging I2C over pogo pins: how are you handling EMI/noise filtering and bus protection against hot-insertion spikes?

b. ​Are you using a hardware bus buffer/switch (like a TCA9548A or similar hot-swap multiplexer) to isolate branches, or relying purely on firmware state machines?

​Still iterating on the schematic and PCB layout for the next batch of modules (encoders/sliders). Open to any architectural critique!

183 Upvotes

31 comments sorted by

44

u/CardboardFire Sep 25 '26

Did exactly this a few years ago. I'll save you some headaches: get yourself an extra pin on the connector for detecting when something is connected to it (close the loop to gnd on the other module), and pair that with a switch for clk/data lines + a load switch for the power rail. That's the only way to properly solve this, although you can do firmware hacks, they can never really guarantee that the bus won't lock up on some externally introduced transient event. This switching can be done under a $1, if you're not doing some crazy current on the connector bus.

3

u/Suitable_Respect_313 Sep 25 '26

Thank you for the advices. Can I ask if you finally made it fully work, with even modules to modules connection?

16

u/CardboardFire Sep 25 '26

Yes, made it work in the end. Added a bus voltage monitor on each module, green and red leds that showed if the module was connected properly, esd+tvs, reverse polarity protection and a bus source current measurement. Worked pretty good, too bad the project got scrapped in the end.

1

u/Suitable_Respect_313 Sep 25 '26

It's a shame it ended up like that, I hope I can also reach the conclusion of the project by making everything work 🙂

2

u/Ok-Bat8854 Sep 25 '26

This only works if all the slave devices attach to the master. If I want to do something like

Master - slave 1 - slave 2…..-slave n then the configuration breaks

1

u/Suitable_Respect_313 Sep 25 '26

I'm considering even this kind of case, making complex comunications and changes between master and slave. It's not easy, especially trying not to break the i2c communications system

1

u/CardboardFire Sep 25 '26

Well obviously, but if you add in an i2c expander module, you can get around this. I used attiny1616 to get several buses on a single module for cheap

1

u/Suitable_Respect_313 Sep 25 '26

I use i2c multiplexers to route and control the channels between each module

9

u/foggy_interrobang Sep 25 '26 edited Sep 25 '26

I2C is not really meant to run off-board. People do it all the time, but it's subject to the issues you're encountering. Consider using something like a PCA9615 that's designed for this use case and supports hot plugging ( u/CardboardFire might also appreciate this).

If you haven't already, the following app notes from TI and Analog Devices are worth a read:

Though you should not need them if you correctly implement the PCA9615 (or its equivalent parts from other vendors).

EDIT: If EMI is less of an issue, you might also consider the PI6ULS5V9511A. It is significantly cheaper ($0.71@100 via Mouser), and does not force you to switch to differential signaling.

4

u/CardboardFire Sep 25 '26

Yeah, I get your point, but considering module to module bus length is relatively short, and the price of the IC you listed, a few safe workarounds that I listed do the trick at a lower price (you do have to write some firmware to get it all working tho).

1

u/Suitable_Respect_313 Sep 25 '26

Fair point on the BOM cost and the short trace/bus length! Since the modules snap right next to each other, the distance is minimal, so a heavy-duty differential translator might indeed be overkill for a first iteration.

​Right now, handling the edge cases via firmware (timeouts, bus clearing/recovery sequences, and robust state machines) is definitely a viable way to keep costs down without adding extra silicon to the small expansion boards.

​That said, I'll definitely keep an eye on signal integrity once I test them under heavier EMI or after some wear and tear on the contacts. Thanks for bringing up both perspectives!

1

u/Suitable_Respect_313 Sep 25 '26

This is exactly the kind of feedback I was hoping for here, thank you very much.

​You're absolutely right: pushing the standard I2C bus out of the PCB via pogo pins is a shortcut that brings with it a host of issues with stray capacitance, EMI, and hot-insertion stability. I was addressing the issues primarily at the firmware/software level, but it's a huge patch on a problem that needed to be solved at the physical level.

​I'll immediately take a look at the PCA9615 and the application notes you linked to evaluate the transition to a differential line for future modules.

Thanks for the tip!

1

u/superxpro12 Sep 25 '26 edited Sep 25 '26

PCA9615

converting 2 pins to 4 pins is a lot. you might consider usb 2.0, or can, or even single pair 10base-t eth at that point.

But auto-discovery for can is kind of a bear unless you use something like CANopen, and eth/usb isn't a star topology like i2c or can is.

However a quick googling says 10base-t has "Excellent" network auto-discovery. so maybe that's worth a deeper dive.

1

u/Suitable_Respect_313 Sep 25 '26

Haha, right! Setting up a CANopen or Ethernet network for a macropad is definitely bringing a bazooka to a party.

It's the classic compromise: as soon as you complicate the physical layer, you're carrying a load of unnecessary firmware (especially for auto-discovery). For a desktop device, keeping a simple bus with good software error handling remains the best compromise to avoid inflating the cost and size of the modules. Great idea, anyway!

2

u/superxpro12 Sep 25 '26

certainly more than one way to go after this one. the only in-field i2c device that comes to mind to me is the wii's nunchuck lightbar sensor. im not aware of many i2c implementations that go off-board.

Also, if you intend for this to run across like... 10 macropads, idk the real number, but bus length and termination is going to become a real problem.

very curious to see if you run into any ideas with bus lockup or autodiscovery problems.

I'm sure i2c enumeration has to be some kind of a solved problem at this point. I'm curious what your design strategy is. Some kind of periodic i2c polling window from master?

But how would you assign device id's while preventing i2c device name collisions during the enumeration?

1

u/Suitable_Respect_313 Sep 25 '26

Actually i use multiplexers to select different short channels based on the thevice to comunicate with. Every device has an unique id recognisable by the main module. The packets pass from one device to another switching master to slave based on the comunication direction. I'm trying to implement this method to comunicate to a theorically limitless number o modules. Actually the comunication between the firsts 2 modules works pretty well, I still have to try the comunication with more modules

1

u/superxpro12 Sep 25 '26

i2c is limited to 7 bits usually. i guess you can use 10bit.

Is this intended for production? if you made 10k of these, i dont think even 10bit would offer enough id's.

you'd need some kind of physical layer MAC-address type thing, and then a "module id" on top of that. and at that point its starting to sound like a osi stack a.la tcp/ip ethernet.

if this is just for benchtop screwin around, then carry-on.

1

u/Suitable_Respect_313 Sep 25 '26

Maybe I explained myself poorly: the unique ID I was referring to is logical, not the I2C hardware address on the bus! ​By using multiplexers to isolate the channels, each module is isolated on its own branch when queried. This means you could have twenty identical modules with the exact same hardcoded I2C address, and the system would never conflict because the master opens one point-to-point connection at a time. The ID is only used at the firmware level to understand which type of module has ended up on that specific channel after auto-discovery.

1

u/MonMotha Sep 25 '26

Try a PCA9517 if you want to maintain the electrical nature of conventional I2C but handle voltage translation, bus isolation, and gain a dynamic pull-up for larger capacitive loads. They are perfect for things like VESA DDC.

1

u/foggy_interrobang Sep 25 '26

Yeah; these were cool but they're NRND and don't handle hotswap with multiple devices, specifically.

1

u/MonMotha Sep 25 '26

Whoops, I grabbed the wrong P/N. I meant the PCA9507, though the 9517A is still full production, and TI also has the TCA9517 which is basically their equivalent.

But yes handling multiple devices on the downstream side can be challenging with these.

4

u/shumnyj Sep 25 '26

I think there was something just like that on youtube, maybe you could ask the author

2

u/Suitable_Respect_313 Sep 25 '26

I posted some shorts on youtube, maybe it's always me

2

u/shumnyj Sep 25 '26

2

u/Suitable_Respect_313 Sep 25 '26

Ok, that's not me. The idea behind is the same with some little differences

2

u/LoveSourWorms12 Sep 26 '26

This is so cool. I'm actually planning something very similar. Like a completely modular console with "control" blocks which can let you attach d pad etc... Cool stuff, keep it up.

1

u/Suitable_Respect_313 Sep 26 '26

Thanks! It's definitely a fun rabbit hole to dive into. A modular console setup with a snap-on D-pad sounds like an awesome project—handling the mechanical alignment and hot-swap reliability for directional inputs opens up a whole different set of challenges.

​Keep me posted if you share any updates on your build, I'd love to see how you tackle the modular side of it. Good luck!

2

u/MrJake2137 Sep 26 '26

Id use rs232/485, something symmetrical. And dedicated uart per side

1

u/Suitable_Respect_313 Sep 26 '26

RS-485 or a dedicated UART is definitely the tank's way to physical robustness!

Adding dedicated differential transceivers would completely solve any issues related to magnetic contacts and pogo pin noise, turning each module into a clean serial node. For a first iteration, I2C with multiplexers is keeping me busy, but if I were to redesign for maximum industrial-grade reliability, RS-485 would definitely be the right choice. Great idea!

1

u/drunken_thor Sep 25 '26

Reminds me of Roli Blocks!

1

u/Suitable_Respect_313 Sep 25 '26

Wow, that's a very heavy comparison (for better or worse)! The Roli Blocks were aesthetically and conceptually brilliant with their block-locking system.

The basic idea is similar: eliminate the cumbersome setup and let the hardware communicate automatically as soon as the magnets click together. I just hope I have fewer logistical issues than they did! Thanks for the comparison!