Welcome! Log In Create A New Profile

Advanced

Controlling an Arduino-based olfactometer via serial communication in MonkeyLogic

Posted by jschlotthauer 
Controlling an Arduino-based olfactometer via serial communication in MonkeyLogic
November 07, 2025 11:09AM
During my task, I need to control an olfactometer whose communication with the host computer is serial and Arduino-based.
I know that MATLAB provides specific functions for serial communication (e.g., serialport, writeline, etc.), but I’m not sure how to properly implement them (or whether I should) in a MonkeyLogic task.

As far as I understand, there might be two possible approaches:

1. Script-based approach
Write the experiment as usual using MonkeyLogic functions, but integrate MATLAB serial communication commands whenever I need to send a command to the olfactometer. For example, by calling writeline within the timing file at the appropriate event times (together with the olfactometer commands?).

2. Using the MonkeyLogic GUI
I noticed there are some “Other Device Settings” and “Reward” options in the ML interface. However, I assume those are not appropriate for this case, since I don’t want to overwrite the Arduino’s firmware or use the olfactometer as a standard reward device. Please correct me if I’m misunderstanding this.

I’m new to both MATLAB and MonkeyLogic, so I’d really appreciate any guidance on how to set this up correctly.
At the moment, I don’t have access to the olfactometer yet, but I’d like to understand how to handle the communication in advance so I can be ready to test it once it arrives.

Any advice, examples, or general guidelines would be greatly appreciated!
Re: Controlling an Arduino-based olfactometer via serial communication in MonkeyLogic
November 07, 2025 05:41PM
If your olfactometer is a commercial product, the manufacturer probably has the instructions/tools (or even MATLAB scripts) to control it. You should talk with them first.

For serial devices, NIMH ML does not collect data automatically in the background. You should handle everything yourself, from initializing the olfactometer to reading and saving samples, by writing some code in the alert function or timing script.

Since the foreground process of NIMH ML has to run the task, you won't be able to read the meter at regular intervals. However, it is okay to check the meter from time to time during trials. As you said in your script-based approach, you just need to program the routine in the ML timing script.

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.