Using the BIOPAC MP160 in Python

TL;DR

Via Twitter, Dennis Hernaus (@hernaus_tweets) contacted me about my MPy150 library for BioPac’s MP150 system (read this older blog post for more info). After some fiddling, he managed to get his MP160 device to work in Python, and I figured it would be good to share his efforts here.

What is BIOPAC?

BIOPAC is a company that makes data acquisition systems that can be used for measuring brain waves via electroencephalography (EEG), heart rate via electrocardiography (ECG), grip strength through dynamometers, and other physiological data. The devices can be connected to computers via ethernet, and BIOPAC offers its own proprietary software to communicate with its devices.

In addition to their own graphical software, BIOPAC offers a software developers kit (SDK) that can be used through programming languages. This works via a DLL that can be called upon from Python, Matlab, or really any other language that offers a DLL-interface. In this post, I’ll introduce a Python wrapper that should allow you to use BIOPAC’s MP150, MP36R, and MP160 in experiments.

How do I use my BIOPAC in Python

When trying to use his MP160, Dennis learned three main things:

  1. It turns out that my MPy150 library worked with the MP160 after changing a single parameter within the source code. Score!
  2. The mpdev.dll version that I was using with the MP150 (2.1.0.4) is said to be incompatible with the MP160. Instead, version 2.2.1 should work.
  3. DO NOT RUN ACQKNOWLEDGE (BIOPAC’s acquisition software) in the background! It will create a conflict between Acquisition and your experiment; only one can interact with the BIOPAC device at the time.

Introducing MPyDev

While talking to Dennis, I decided it would be good to update my library for the MP150 to make it compatible with the MP160 (and more readily adoptable for other devices). Instead of updating the old code, I simply put up a new GitHub repo with a slightly updated version. This allows people to keep using the perfectly good MPy150 library for their MP150 devices, while also allowing others to work with the newer library regardless of what machine they’re using. The following features sum up MPyDev:

  • Communicate with MP150, MP160, and MP36R.
  • Choose how many channels to record from (1 to 16).
  • Ask the device for the latest sample. Useful if you want to present feedback during your experiments, for example by filling up a bar to represent a participant’s grip strength while they are squeezing a dynamometer.
  • Record data to a file in the background (while your experiment continues running), much like you would with eye-tracking or brain imaging.
  • Record data to a buffer in the background, in case you want to record data over a short period of time within an experiment. You can do this while also recording data to a file.

Installing MPyDev

If you want to use MPyDev in your Python experiments, follow these steps:

  1. Make sure you have Python installed. I highly recommend using the Anaconda package.
  2. Go to github.com/esdalmaijer/MPyDev
  3. Click on the big, green button labelled “Clone or download”.
  4. In the menu that popped up after last step, click “Download ZIP”.
  5. Unzip the archive you just downloaded.
  6. Copy the “mpydev.py” file into the folder that has your experiment in it. (You can also copy it to the “site-packages” folder of your Python installation, if you prefer. You will be able to import it in any experiment from there.)

Example script

This is a minimal example, using PyGame as the display library. You could also use PyGaze or PsychoPy.

7 Comments:

  1. Could I use MPyDev to send triggers to my BIOPAC device?

    • That’s not something currently implemented, I’m afraid. You can log messages to the log file (which are sometimes also referred to as “triggers”), but you cannot send a signal directly to the BIOPAC device other than telling it to start or stop recording.

  2. Hello Edwin,
    thank you for this detailed article.

    If I understand well, this has nothing to do with the NDT feature of AcqKnowledge, do you need a license of the HAPI to use your approach?

    Regards

  3. Hello Edwin,

    Thanks a lot for this article.
    It’s very useful.

    Best,
    Arnaud

  4. Hi,
    Thanks for this work. Would you consider it as a good approach to interface a biopac system with the lab streaming layer, since this capability is not available in Acqknowledge ?
    Thanks.

    Benoît

  5. Pingback: Real-time recording/analysis of physiological data from BIOPAC in Python – PETER GAMMA (Physiologist), MEDITATION RESEARCH INSTITUTE SWITZERLAND

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">