Canta-Cart

Low-cost card-sized musical instrument with touch keys

A stack of card-sized electronic devices.
Table of Contents

Canta-Cart is a touch-operated musical instrument/synthesiser that takes the dimensions of a standard ID-1 card (85.6 × 53.98 mm). A portable little tune-maker in the pocket, it is easy for anyone to get hands on, yet versatile enough for the more aspiring of minds. It is plug-and-play — a USB-C power supply will take its sounds anywhere. The BOM adds up to a cost of CN¥5 / US$0.7.

Music for demonstration:

  • Merry-Go-Round of Life — music from the film Howl’s Moving Castle; composed by Joe Hisaishi.
  • A Short Hike — melodic theme of the video game; composed by Mark Sparling.
  • Pigeons and a Boy (ハトと少年) — music from the film Laputa: Castle in the Sky; composed by Joe Hisaishi.
Merry-Go-Round of Life🎞Merry-Go-Round.mp4(2.1 MiB, 00:39, 960x540)
A Short Hike🎞A-Short-Hike.mp4(1.3 MiB, 00:39, 640x450)
Pigeons and a Boy🎞Pigeons.mp4(620 KiB, 00:09, 540x360)

Apart from the actual device, the instrument can also be played right in the browser.

The following content is the same as the project details on Hackaday🪐.

🎛️ Controls

On the card are 12 touch keys (10 for sounds, 2 for transposition). The sounding keys correspond to the pitches in a diatonic major scale, spanning a tenth interval.

An illustration of the layout of the keys and how they map to pitches or musical notes.

The transpose buttons open up to a variety of ways to extend this. They work as follows:

  • Press once: move along the scale.
  • Hold and play a note: accidentals.
  • Press one while holding the other: key change.
Diagrams of transpose buttons being operated.

The rationale is that most melodies (in music cultures compatible with the Western tonal theory) span a pitch range of around a tenth, at least over short periods, due to the register of the human voice and how musical instruments and compositions tend to imitate and invoke it. Thus, ten keys are mostly sufficient for a player to reproduce most melodies. The transpose buttons open a way to pitches beyond the ten-note major scale in cases where they are needed, covering the remaining cases as well as providing abundant chances for harmonies, musical textures, etc., through which delicate musical expression becomes more than possible.

⚙️ Inner Workings

(Please refer to the firmware source🪐 for all details.)

Capacitive Sensing

Touch sensing is achieved by utilising the step response of an RC network.

The circuit consists of a large resistor (~1 MΩ) in series with the sensing electrode. The latter can be treated as a capacitor to the circuit’s ground (not necessarily earth; a battery negative reference works just fine), whose value increases as human body parts approach it. A driving pin feeds the network with a step signal (namely, drives it high) and monitors the voltage change across the resistor, waiting for the sensing pin to go “logical high”. As the step response of this network is an exponential function (the derivation of which is explained in any basic electronics textbook), for the voltage at the sensing point to rise above the logical high threshold VIH=kVCCV_\mathrm{IH} = k \cdot V_\mathrm{CC} (with a typical value of k=0.7k = 0.7), the time taken is ln(1k)RC-\ln (1 - k) \cdot RC which is linearly dependent on the sensed capacitance CC. By repeatedly sampling GPIO pins, the capacitance values at all electrodes can be straightforwardly deduced.

Diagram of a sensing circuit.

Run a simulation of the circuit here🪐.

Audio Synthesis

The synthesiser is a basic triangle wavetable synth combined with an attack/release envelope. All calculations are carried out with 32-bit integers, minimising the time spent in synthesis and reducing overall latency to under 1 ms.

Audio Output

Audio is sent to a DAC through a digital bus comprising three signals: word select (WS), bit clock (BCK), and serial data (DATA). The DAC IC in the circuit expects the LSBJ format, which closely resembles the standard I²S. Our microcontroller does not have a ready-to-go peripheral for such formats, but it is possible to work within the limitation: BCK and DATA can be covered by an SPI output, and WS can be supplied by a carefully synchronised PWM timer channel. The DMA provides a half-complete interrupt, easing the implementation of a double buffer.

Why do these strange limitations arise? To squeeze out every penny/cent, of course! Which leads us to…

🔥 The Muntz Wildcard

Cost-effectiveness was an overarching consideration in the design. This gave rise to a few absurdities in the implementation, but as things were pieced together, they amounted to a knockdown BOM cost of US$0.6 per unit. As quite a few PCB houses now provide free prototyping services for boards of this size, this is the final manufacturing cost of the device. (Components can all be manually soldered with a hot air gun or an iron; I’m by no means a seasoned maker as electronics is only my side research as a design-focused student, but I did it all simply with solder paste and a hot air gun, without a paste stencil, a magnifying glass, or solder flux. YMMV, though.)

The microcontroller is at the heart of the device and often a major contributor to the BOM cost. For this design, I looked at PY32, an Arm Cortex-M microcontroller series by the semiconductor company Puya. The entry product line, PY32F002/3, features an impressively low cost of down to US$0.1 per unit. The PY32F003 model runs at 32 MHz and has timers, SPI, and DMA in its peripherals, closely fitting our use case of continuous digital audio output. The audio DAC and amplifier ICs are also low-cost models, but are more than sufficient for our application.

Being China-based, I obtained a combined cost of CN¥4/US$0.6 per unit (at quantities of 1+) ordering components from a large reseller on Taobao. Renowned online distributors may have a slightly higher price at lower quantities, but the figures do not differ by much, capping at around the aforementioned US$0.7.

Music is never a meritocracy. Musical dreamers of the world, unite!

✨ Business…?

Business cards are never complete without getting personal. I have already been giving away these to friends around. On the back side are printed my personal website and a signature in the form of an icon. The graphic obscurely spells a musical phrase that I dub “the sweetfish motif”. I’m willing to send a card to whoever correctly decodes it first. If you do, please message me (^ -)☆

Assembled devices with graphics printed on the back side facing up.

I spelt it wrong, this was revision 1

permalink | by Ayu