Using the BIOPAC MP150 in Python

BIOPAC Systems Inc. is a company that produces machines that can test several physiological processes. These include electroencephalography (EEG), electrooculography (EOG), electromyography (EMG), respiratory function, temperature, and heart rate. In addition, they can be used to test grip force!

One of BIOPAC’s machines is the MP150. After buying this expensive piece of equipment, you can buy add-on modules to test some of the functions listed above. These modules can be clicked into the MP150, which can then transmit data collected from the module to a computer. BIOPAC offers some software to read out the signal that the MP150 transmits, but you can also program custom scripts to do cool stuff with the MP150’s data.

This post will teach you how to write those cool scripts in Python. The demonstrations will rely on the PyGaze toolbox, but communications with the MP150 do not rely on this. So you could use your own favourite experiment package (PyGame or PsychoPy, for example). This example will focus on a dynamometer, which is a module that can measure grip force. It provides a handle that participants can squeeze, which earned it the nickname ‘squeezie’ in our lab. However, as far as I can tell, the presented software should work with any other module too.


Dynamometers were used in Chong et al.’s study on decision making in Parkinson’s patients.

The above image is from Chong et al. (2015), a study that used dynamometers on healthy people, and on Parkinson’s disease patients on and off their medication. They used squeezing the dynamometer as a manipulation of physical effort. They demonstrate that Parkinson’s patients were less willing to invest effort if they could obtain a low reward for it. On dopaminergic medication, patients were willing to invest even more effort than healthy participants when the rewards were high.


BIOPAC provides a DLL (a dynamic-link library) that can be used to communicate with the MP150 on Windows (sorry, not other operating systems supported). It’s called mpdev.dll, and you should have gotten it with your system. If not, no worries: you can download it from my GitHub page, along with the other code presented on this page (see the Downloads section below).

Setting up

The first thing to do, is to import the libraries that you need. For this guide, I will assume that you have PyGaze installed. Create a new folder, and within that folder two new scripts. Call the first, and the second Then, download the MPy150 zip archive from GitHub. Unzip it, and copy and mpdev.dll to the folder that contains and

Now that you have the file structure correct, it’s time to start doing some programming. Open, and define the display type (the underlying package that PyGaze uses for visuals) and the display size (your monitor’s resolution):

Now open, and import the classes that you are going to use (these will automatically find and import your file):

The final step is to initialise a few instances: MPy150 to collect data from the MP150, a Screen for drawing text on, and the Display for showing your Screen:

Getting Samples

If you want to make what is shown of the Screen depend on the input of your MP150, for example if you want to visualise grip force or EEG signal, you will need to actively obtain samples from the MP150. A sample is a single data point, that can contain information on up to sixteen channels (one channel per module). MPy150 is currently configured to only report the first three, but you can easily change this in the source code. (Change the 0s to 1s in line 125.)

To get a sample from the MP150, you can use the sample method. In this example, you will get samples from the MP150 and display their values on the computer monitor. This means you will have to continuously get new samples, and update the display. The easiest way of implementing this in code, is by using a while loop. You can make such a loop go on forever, or until you press a key. The idea here is to make it run until you press Escape. The code looks like this:

This while loop will run until you press Escape. It will show the sample’s value in white letters (on the centre of the Screen, the default text position). And it will update the background to be brighter red if you squeeze the MP150’s dynamometer harder.

Closing Down

After using the MPy150 instance, you need to close it to shut down the connection with the MP150. You also need to close the Display, which will close down the experiment. The following code will do this:

And that’s it! Your whole experiment finished! For another example, that shows you how to record from the MP150 to a log file, see this MPy150 test script on my GitHub.


The MPy150 class is completely free and open source. It is hosted on my GitHub page, from where you can also download it. The download is an archive that includes and mpdev.dll. To use them, unzip the archive and place the files in your PyGaze directory, or in the same directory as your script.

After placing and mpdev.dll in your PyGaze directory, you can import MPy150 with the following code:

If you placed and mpdev.dll in the directory of your script, include the following:


  1. What units are the samples? I assume kg?

    • That’s a very good question! I’m afraid it’s not kilograms, but more-or-less arbitrary units (I think it’s the voltage output from the module). You’ll have to calibrate your system to know what output values correspond to what pressure, for example by placing a known weight on the handle and reading out the difference in the BIOPAC’s output.

  2. It doesn’t seem to work for channels 4-16. I changed the 0s to 1s in the channel list, but there seems to be other places that it is hardcoded to get only 3 samples

  3. I’m a newbie here. How does the code changes if used in Psychopy?

  4. Pingback: Using the BIOPAC MP160 in Python – PyGaze

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

  6. Pingback: Using the BioPac MP150 in Python – Quantitative Exploration of Development (Q.E.D.)

  7. I try to change the sampling rate but the number of samples I get doesnt fit.
    arr = mp.get_buffer()
    The array should be about 5000 samples and its only 191

Leave a Reply to Edwin Dalmaijer Cancel 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="">