Mathematica 9 is now available

Wolfram Library Archive

All Collections Articles Books Conference Proceedings
Courseware Demos MathSource Technical Notes
Title Downloads

Interfacing Hardware with Mathematica

Zhe Hu
Revision date

Created 20

Once you get to appreciate the beauty of a programming language like Mathematica, you want to do everything with it. That includes playing card game (Fitch's card trick), going to movie together (movie marathon), and even making you coffee in the morning or feeding your cat.

Yes, Mathematica can do the latter by interfacing with external hardware through the digital input/output ports of your computer, i.e. Mathematica can toggle the digital signal lines of your computer's serial port, parallel port and even the USB port. In essence Mathematica, like many native (or aboriginal) programming languages, can talk with the "low level" hardware components of your computer through which gives you the ability to control the external pieces of hardware in the real physical world.

This ability in most part is due to its inherent "Link" technology, especially the .NetLink coming with the latest version of Mathematica that allows you to call functions from the native MS-Windows dynamic link library (DLL). Many hardware components on your PC are controlled by device drivers under the operating system. And these device drivers sometimes expose their functionality (e.g. in SDK packages) through DLL functions in MS-Window. As long as Mathematica can access the functions in the DLL, it is granted the capability of controlling and communicating with the hardware directly.

In this notebook, I showed some demonstrations of Mathematica code talking with the serial port, parallel port and USB device of your PC. To fully reproduce these demos, you need some electronic parts, which lie in abundance in a regular electronics lab and some working knowledge of electronics to assemble them, since I won't give step by step instructions on building these circuits. Again as you read on, you may not be able to resist the temptation to grab a soldering iron and make the circuits yourself. I won't be responsible for your burning the fingers by grabbing the soldering iron at the wrong end, or even worse, sticking it into the wrong place, such as a friendly and innocent standby who offered to hold your circuit board while you were soldering, which is by the way the main reason why we are in short of undergraduate lab assistants in our lab now.

However even if you follow the "DON'T TRY THIS AT HOME" sign that I formally put up here, you can still appreciate the limitless possible tasks that Mathematica can perform as you keep on reading further. Actually one of the purposes of compiling this notebook is to convince my labmate who is an expert on using LabView software to control various pieces of instrument in our lab that Mathematica is no weaker in this respect. So let's start the journey with Mathematica in the hardware-land.

*Engineering > Electrical Engineering
*Mathematica Technology > Linking Technology > .NET/Link

serial port, parallel port, DLP-USB245M, RF-24G
Downloads Download Wolfram CDF Player

InHardwareLand.nb (3.2 MB) - Mathematica Notebook [for Mathematica 5.2]
InHardwareLand2.nb (443.6 KB) - Addendum showing how to control a USB oscilloscope [for Mathematica 5.2]
matrixEffect.gif (3.5 MB) - GIF image