pyNAD – controlling audio amplifiers from Python
Thursday, December 31st, 2009I recently had the opportunity to play with one of NAD’s new amplifiers that come with a serial port. With an inexpensive USB to serial adapter, it’s easy to imagine how it might be controlled from a media PC. Fortunately, NAD have released the specifications of the protocol to the general public (unencumbered as far as I can tell), so it was a simple task to write some Python code so control the amplifier.
The attached Python script is pretty rough and ready, but is capable of turning the amplifier on and off, and changing the volume up and down. The script has been written for Ubuntu Linux but should work on any distribution with Python and pySerial installed, and should probably work on Windows also. Usage of the script is fairly straightforward, ie
- pynad.py {command}
where command is one of
- vol- or vol+ : decrease or increase volume
- on or off : turn amplifier on or off
- offConditionally : turn amplifier off if it is set to input 5 (Auxiliary)
- onAndSetAux : if the amplifier is turned off, turn it on and set it to Aux input (if it is already on, the input is not changed)
The final two commands are useful for running at shutdown / startup to provide a fairly intuitive control of the amplifier without interfering with any potential non-media PC uses (such as if someone was listening to a CD at the time when the media PC is shutdown).
The attached zip file contains the necessary Python code and an example upstart script for Ubuntu Karmic. In addition, you may need to customise the pynad.conf file to change the serial port used (/dev/ttyUSB0 is probably suitable for most people). Windows users will need to change this to COM5 or similar. The pynad.conf file is looked for in ~/.pynad.conf or /etc/pynad.conf .