Encoding treadmill speed sensor

Hi Chris,

I am a PhD student at the University of Fribourg in Schmid Lab. We are currently setting up a mouse experiment using virtual reality. Our goal is to control the visual flow of the stimulus through a custom-made speed sensor connected to both the treadmill and the computer via USB. The circuit employs a PIC16F1939 microcontroller and the USB interface is a FTDI chip. The USB connection is through a VCM Port having following parameters: 9600bps, 8 data bits, no parity, 1 stop bit (9600 8-N-1).

We have a couple of specific questions:

  1. We would like to understand how to encode the output information signal from our custom speed sensor in a format that MWorks can interpret as a speed value. Do you have any recommendations for serial reader software (e.g. CoolTerm) or any other way to achieve this?
  2. To connect the device, would you suggest using a digital signal recorded via USB, or do you think an analog output (e.g., through a National Instruments Card) would be more suitable for our setup?

Thank you in advance. Best,

Marta Falkowska

Hi Marta,

If the FTDI chip is configured as a virtual COM port, macOS should recognize it as a serial device when it’s connected via USB. The question then is how to communicate with the device (via serial I/O) within MWorks.

The quickest solution would be to use Python actions and pySerial to receive data from the device. Basically, your Python code would periodically read input data from the serial connection, convert it to a speed value, and then use the setvar function to assign the speed to an MWorks variable, so that the value can be used in the experiment.

Another option is for me to develop a custom MWorks plugin to do the same job. There are already several MWorks plugins that communicate with I/O devices via serial port (e.g. Firmata, ISCAN, NE-500), and presumably this one would work in a very similar fashion. This would take more time to implement than the Python approach, but it might be preferable as a long-term solution.

Cheers,
Chris

Hi, thanks a lot for an answer. How long do you think it would approximately take to develop a plugin like this? In the meanwhile we can start implementing the Python approach, but the experiments will not start too soon anyway.
Best,
Marta

Hi Marta,

Once I have all the specifications, it will probably take me a few days to a week to complete the initial version of the plugin. Since I won’t have access to the actual hardware, it will require some testing on your end. When do you think you’d be able to start testing it, and when do you plan to begin the actual experiments?

To start developing the plugin, I’ll need the details of the communication protocol used by the device. You’ve already told me the serial connection parameters, which is very helpful. I also need to know how to interpret the data being transmitted over the serial connection. Is the communication one way (device to PC) only, or are there commands that you want to send from the PC to the device?

Thanks,
Chris

Hi Chris, that is great news.
We plan to start the experiments no sooner than in a couple of weeks, but the device is ready to be tested, and I can do it at any time. For our task, I don’t see the need to transmit any information from the computer to the device. I am attaching the manual; I hope you can find more useful information there.
Rotary manual.pdf (446.0 KB)

Thank you! Best,
Marta

Hi Marta,

Thanks for sharing the manual. I think that gives me all the information I need.

I should be able to get an initial version of the plugin in to the MWorks nightly build within the next few weeks. Any suggestions for what to call the device? I’m thinking maybe “Rotary Speed Sensor”, but perhaps you have better ideas.

Cheers,
Chris

Hello Chris,
“Rotary Speed Sensor” is fine. Thank you, let me know if you have any questions!

Best,
Marta

Hi Marta,

The initial version of the rotary speed sensor plugin is now in the nightly build. I’ve attached a small example experiment that demonstrates how to use it. There’s also some documentation.

The plugin just takes the raw direction and RPM values reported by the device and assigns them to the variables specified by the experiment. I’ve tested it with an Arduino board that I programmed to send data in the same format as the sensor, but obviously I haven’t tried it with the real thing.

When you have a chance, please try it out, and let me know if you have any questions or run in to any problems.

Cheers,
Chris

rotary_speed_sensor_demo.mwel (233 Bytes)

Hi Chris,

I tested it today with drifting gratings and at first glance it works great. If I encounter any problem I will get back to you.

Thanks a lot!
Best,
Marta