Monday, April 14, 2014

Firmata, a legacy protocol demands more patches

 
 


During my development of Firmata for LPC812MiniKit, I found a serious issue. The current Firmata protocol only supports up to 16 channels of PWM/ADC

 

Cause

Since Firmata originates from the legacy MIDI protocol. It heritates many things from last century (too old). 


The MIDI devices have common features. For example, the musical keyboard has many keys and a few analog control, including volume, pitch. As a result, MIDI protocol defines up to 128 channels digital I/O and up to 16 channels analog I/O.  On the other hand, MIDI is kind of ASCII protocol. It reserved MSB as command, all 8bit value has to be split into two byte, one byte carries 7bit, the other carries 1 bit. That's stupid ever.

 

When Firmata was designed for Arduino, it follows MIDI. So we can believe the designer should have background of music. Here comes the bottleneck. Although in morden microcontrollers, analog channels are still limited against to digital pins.  Usually we can find 4/6/8 PWM/ADC on chip. But they can mapped to any digital pins. For example, D17 may share PWM0 in same pin. Of course we can defined analog pins in different domains, but an extra translation/abstraction layer may be very confused.


Solution 

In order to solve this issue, Firmata offers various solutions. The most simplest way is using SysEx command. 


My setup for testing is Firmata on LPC812 and pyFirmata running on Windows. I changed my code in both sides to met that changes. Basically I dropped the original analog message, replace with SysEx command for all analog write.


I haven't implemented and tested the analog read, since LPC812 has no ADC on board.

No comments: