MDB/ICP Vending Machine Interface from Scratch with Raspberry Pi

Adequate Infosoft has created a custom MDB/ICP vending machine interface solution based on the concept of SparkVend, a freely available hackerspace project dedicated to vending machines' direct communication.

This system engineering solution is based on opto-isolation hardware, 9-bit serial communication, Teensy firmware and integration with Raspberry Pi via I2C. This case study emphasizes Adequate Infosoft's skills in creating embedded solutions, custom PC boards, industrial protocols integration and firmware engineering.

Project Origins: A Hackerspace Vending Machine Problem

SparkVend began not as a commercial product but as a practical solution to a problem faced by SparkCC, an Australian hackerspace with a collection of vending machines.

At least one of those machines implements the MDB/ICP (Multi-Drop Bus / Internal Communication Protocol) standard, the dominant serial bus used in the vending industry to connect a Vending Machine Controller (VMC) to peripherals such as coin mechanisms, bill acceptors, and cashless payment devices.

There existed in the hackerspace the idea of making use of the device by potentially using it to dispense electronic parts for the members' projects; however, the management of money via this process was impossible unless control over the interface was gained. Instead of buying a pre-built MDB module, the author of the project decided to construct his own interface as a way of gaining experience in doing all three parts of the process: hardware, firmware and protocols.

As a result, the repository "eltariel/sparkvend" created by the author is quite simple: "a collection of bits that allows a device to communicate with a vending machine that implements the MDB/ICP standard". This is not an actual product, but a reference implementation which illustrates how the most difficult aspect of MDB integration is solved, namely the interface itself.

SparkVend vending machine mobile app concept

System Architecture: Two-Tier Separation of Concerns

The primary architectural choice made by SparkVend is one of a two-tier separation. A Teensy 3.x MCU runs the real-time MDB/ICP protocol and acts as MDB Cashless Device 1 at address 0x10 (the default address of a cashless payment device connected to an MDB bus).

A Raspberry Pi is the host computer and connects to the Teensy via the I²C interface introduced in a more recent commit. The purpose of such separation is that the Teensy takes care of all the bit timing, polling, and state-machine concerns of the MDB protocol, whereas the Raspberry Pi offers the computational resources necessary for the application level.

The architecture reflects a pragmatic philosophy. The author notes that many microcontrollers support the 9-bit UART required by MDB, but they wanted to "hook the vending machine to more powerful systems so we don't have to deal with low-level considerations when we eventually build something way more complex than it needs to be". The Teensy therefore acts as a protocol offload engine, presenting a cleaner interface to the host.

SparkVend MDB vending control interface concept

The 9-Bit UART Challenge

The defining technical obstacle in MDB implementation is the 9-bit serial format. MDB uses a ninth bit as a mode bit to distinguish command bytes from data bytes, and standard UART peripherals on most microcontrollers are configured for 8 data bits. The SparkVend author identifies this directly: "finding a UART that supports 9-bit communications is a little less straightforward". The Teensy 3.x was selected partly because it has spare units available in the author's "gadget bin," but also because its UART hardware can be configured for 9-bit operation, avoiding the need for bit-banging or external UART bridge chips.

On the electrical side, MDB is an opto-isolated multidrop serial bus. SparkVend's hardware includes opto-isolation to protect the Teensy from the noisy, often poorly grounded MDB bus and to break ground loops between the vending machine and the host system. The author describes the opto-isolated bus as "not a big deal on its own," but the combination of isolation and 9-bit timing is what makes MDB integration non-trivial.

Hardware Design: A Through-Hole Pi HAT

The /hardware directory contains KiCad v5 schematics and PCB layouts for a board that connects the Teensy, the MDB interface, and the Raspberry Pi. The design is deliberately mostly through-hole, a decision the author attributes to soldering ability rather than performance requirements: "PCB design is mostly through-hole because I can just about manage to solder well enough for that". This makes the board accessible to hobbyists and small-scale fabricators, though it limits miniaturization.

The hardware is organised as a Pi HAT-style board, with the Teensy and MDB front-end circuitry integrated alongside the Raspberry Pi connector. Separate schematics exist for the host interface (host_interface.sch) and the MDB interface (mdb_interface.sch), reflecting the architectural split between the real-time MDB side and the host-side I²C connection. The repository includes custom KiCad footprint libraries (sparkvend.pretty, pi-hat.pretty) and symbol libraries, making the design reproducible without depending on external library sources.

Firmware Architecture: MDB Cashless Device on PlatformIO

The Teensy firmware is structured as a PlatformIO project using Teensyduino, the Teensy-compatible Arduino core. The author's rationale is candid: PlatformIO was chosen "because the Arduino IDE is… weird". The project follows a conventional embedded layout with src/, include/, lib/, and test/ directories, plus a platformio.ini configuration and a Makefile. The use of PlatformIO brings dependency management, build reproducibility, and a testable structure that the Arduino IDE does not provide by default.

Functionally, the firmware implements the MDB cashless device role: it responds to VMC polls, manages the session lifecycle (inactive, disabled, enabled, idle, and vend states), grants credit when instructed by the host, and reports vend results back to the VMC. The I²C interface added in August 2019 exposes the host-side control plane, allowing the Raspberry Pi to issue credit commands and read status without touching the MDB timing directly. The firmware also includes unit tests under /teensy/test, indicating an intent to validate protocol logic independently of the hardware.

SparkVend vending machine monitoring dashboard concept

Repository Structure and Development Workflow

This repository contains three major sections: global project files, /hardware, and /teensy. The repository includes a .gitattributes file and a specific extra.gitconfig file which allows to improve handling of KiCad files by making them Git-aware via filters for normalization of schematics and PCBs.

It is a tiny but indicative thing: the author understood that he would need to track hardware revisions along with the firmware, thus prepared the repository accordingly. There is a .travis.yml file in teensy directory, which indicates an intention to use CI for firmware development.

The commit history shows a short but focused development arc: initial code in early August 2019, PCB and licensing in mid-August, and the I²C interface later that month. The project has not been updated since 2019, which is consistent with its role as a completed exploratory build rather than an actively maintained platform.

Limitations and Significance

SparkVend's limitations are openly acknowledged. The README describes the host system as "(going to be) a Raspberry Pi," indicating that at the time of writing the host-side integration was still aspirational.

The hardware is through-hole and not optimised for production. The project does not implement cashless payment processing, telemetry, or cloud connectivity; it provides only the MDB interface and a basic host control path.

The importance of this work stems from what it illustrates. SparkVend illustrates that the hardest part of the MDB interface the opto-isolated 9-bit bus and real-time polling state machine can be cleanly extracted into its own microcontroller and interfaced with the host via a simple I2C connection.

For those starting to learn about MDB, the project offers a tangible point of departure KiCad schematics for the isolating and level shifting front end, PlatformIO code implementing the cashless device functionality, and the reasoning behind the separation architecture. It serves as an example of protocol offloading as a design paradigm, and of a hackerspace problem driving an entire stack of embedded learning.

Project Repository: github.com/eltariel/sparkvend

SparkVend mobile application UI concept
Abhinav Akula
DevOps Engineer and 3× Microsoft Azure Certified professional specializing in Azure cloud solutions, migration, deployment automation, and multi-cloud environments. He holds Microsoft certifications as an Azure Developer Associate and Azure Solutions Architect Expert, with expertise in building scalable, secure, and reliable cloud infrastructure.

What Our Clients Say About Us

Client satisfaction is our ultimate goal. Here are some kind words of our precious clients they have used to express their satisfaction with our service.

Leadership That Leads Worldwide

With a physical presence in over 15 countries and a global footprint spanning 25+ countries, we are ready to serve you anywhere. Location, language, or culture is never a barrier, because our global team can work with you in your language. Our strong international team ensures seamless collaboration across borders We have a strong tech team, highly recognized in their domains, with extensive technical expertise.