What is the most compatible analog acquisition device for Bonsai?

451 views
Skip to first unread message

Sarah P

unread,
Mar 30, 2020, 3:32:34 PM3/30/20
to Bonsai Users
Dear Goncalo,
Thanks for developing Bonsai! I just started coding with it, and it's been fun learning all the functions.

My question: I am trying to select the most compatible analog acquisition device for Bonsai. Do you have a recommendation for one that would seamlessly work with Bonsai? Here are some devices that we have in lab: National Instrument USB-6000, Labjack, Measurement Computing, and Arduino Uno. Do you recommend one or more of these? What are the pros and cons of using one or the other? If you recommend a completely different device, which would it be?

Thank you!
Best regards
Sarah

José Teixeira

unread,
Mar 31, 2020, 7:53:56 AM3/31/20
to Sarah P, Bonsai Users
Hi Sarah.

I'm not Gonçalo, but here in the lab we use the NI USB 6001 without any issues. I know that people also use Arduino, but I'm not sure which model.

Hope this helps!

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/2920f0c4-54a9-4989-a08f-9a74e1d560da%40googlegroups.com.


--
José Teixeira
MsC Student & Technician @ Mainen Lab,
Champalimaud Centre for the Unknown,
Lisbon, Portugal

Sarah P

unread,
Mar 31, 2020, 8:55:06 AM3/31/20
to José Teixeira, Bonsai Users
Thank you, Jose!
This is helpful information!

Best regards,
Sarah

Gonçalo Lopes

unread,
Apr 4, 2020, 3:21:30 PM4/4/20
to Sarah P, José Teixeira, Bonsai Users
Hi Sarah and welcome to the forums,

As José mentioned, NI-USB is perfectly compatible with Bonsai, and also most models of Arduino or Teensy that support the Firmata protocol. There are also other specialized DAQs for behavior such as the HARP family of devices: https://www.cf-hw.org/harp

Regarding pros/cons of each device it really comes down to what you need from it:

  - Arduinos/Teensy are usually the cheapest choice and are pretty flexible, including for sampling analog signals. If you get the Arduino Mega you can get up to 16 analog inputs and tons of digital I/O to toggle on/off. The Teensy on the other hand can be excellent for raw speed and low-latency. Because they are so cheap and versatile, they are usually a pretty solid choice for rapid prototyping or hacking around some electronics.

  - I personally find NI boards most useful in their PCI Express desktop mounted format, when you either have a bunch of pre-existing BNC compatible devices to interface with your system, or if you want to drive really high framerate synchronized inputs or outputs (e.g. for building a scanning two-photon microscope). Measurement computing boards could be used in some cases as a comparable alternative to this.

  - The HARP boards are slightly more specialized as they come built in with lots of convenient functionality for specific scenarios, so they often won't have as many inputs as Arduino or NI for now, but they have the awesome advantage that they can automatically synchronize their clocks to other HARP boards entirely by hardware by exchanging sync signals. This means that data will be timestamped and synchronized at the source across multiple devices without the need to post-hoc re-align timestamps in the data which is a huge plus.

This is just a really high-level comparison and depending on the scenario you are looking for, specific features of each board will either shine or get in the way of what you want to build, so feel free to ask if you have a specific goal in mind!

Hope this helps.

Sarah P

unread,
Apr 7, 2020, 9:28:45 AM4/7/20
to Bonsai Users

Hi Goncalo,
Thank you for your reply! I am trying to synchronize the recordings of 2 cameras recording the behaviour of a mouse and the mouse's X and Y positions while navigating a VR environment and imaging neuronal activity with a 2-photon microscope. Currently, the 2P data and X and Y positions are synchronized and recorded on one computer while the videos are being recorded on a separate computer (using Bonsai). At the moment, I start the video and then I separately start the imaging and position tracking, so the videos are not synchronized in time. I would like to be able to synchronously trigger everything with one button, to have the recordings time-sync-ed and also have all recordings synchronously terminate together.

I'd like to make it easy to post-hoc realign timestamps of all data (with a master clock), or have all data timestamps synchronized prior to post-hoc analysis (like with HARP). I'm actually working on this right now, and have a questions. I just ordered a NI-USB6001. Is there a way to achieve this goal with the NI-USB6001?

Also, I looked at the timestamps for MouseMoveX and CameraCapture, using SkipUntil and MouseDown, to synchronize the start of MouseMoveX and CameraCapture. The time stamps show that sampling rate is not consistent between frames (for CameraCapture) and between data points (for MouseMoveX). The timestamps of CameraCapture and MouseMoveX also don't match up exactly. So, right now, I'm testing different approaches to synchronize the data post-hoc in MatLab. Do you have any suggestions on how to simplify the timestamp synchronization pre-hoc or post-hoc?

Thank you!
Best regards,
Sarah
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai...@googlegroups.com.


--
José Teixeira
MsC Student & Technician @ Mainen Lab,
Champalimaud Centre for the Unknown,
Lisbon, Portugal

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai...@googlegroups.com.

Gonçalo Lopes

unread,
Apr 8, 2020, 9:01:10 PM4/8/20
to Sarah P, Bonsai Users
Hi Sarah,

The NI-USB6001 looks very capable, so it should actually be fine for most synchronization needs. My default preference (when possible) is always to synchronize everything on the fastest sampling clock (e.g. the NI-USB6001) and find a way to sample all high-precision events as TTL signals.

Also this means usually you would start the fastest sampling card first, and then everything else, and then do the reverse order so that you shut off the fastest sampling card first. This is to ensure that your fastest time series captured all the data from the experiment.

Just as a clarification, how are you measuring the X and Y positions? Is this through an encoder on the VR setup? Is this being sampled using the NI board? What camera are you using for the behavior? Is it a simple webcam, or is it an industrial camera like PointGrey or Basler? If the latter, you might be able to send individual frame-triggers to the NI-DAQ so you have an actual hardware recording of exposures logged directly on the NI board (or the other way around, drive the camera using a regular pulse train from the NI board).

For more synchronization options, this question might be useful:

Regarding the timestamps not being consistent, if the video is coming from a webcam, it could be that auto-exposure is set to automatic, which will create variability in the timing as the period between exposures is adjusting to light conditions every frame. If this is the case, it's best to disable it altogether.

Otherwise, how variable is variable? Some variability is to be expected from just variable OS timing.
Hope this helps.

To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/d0145fea-6a35-4934-b4c7-156f3797a843%40googlegroups.com.

Sarah P

unread,
Apr 21, 2020, 10:54:06 AM4/21/20
to Bonsai Users
Hi Jose,
I purchased a NI USB 6001 to use with my Bonsai code. Which node do you use to receive inputs from the NI USB 6001?

Thank you!
Sarah

On Tuesday, March 31, 2020 at 7:53:56 AM UTC-4, José Teixeira wrote:
Hi Sarah.

I'm not Gonçalo, but here in the lab we use the NI USB 6001 without any issues. I know that people also use Arduino, but I'm not sure which model.

Hope this helps!

On Mon, Mar 30, 2020 at 8:32 PM Sarah P <sarah...@gmail.com> wrote:
Dear Goncalo,
Thanks for developing Bonsai! I just started coding with it, and it's been fun learning all the functions.

My question: I am trying to select the most compatible analog acquisition device for Bonsai. Do you have a recommendation for one that would seamlessly work with Bonsai? Here are some devices that we have in lab: National Instrument USB-6000, Labjack, Measurement Computing, and Arduino Uno. Do you recommend one or more of these? What are the pros and cons of using one or the other? If you recommend a completely different device, which would it be?

Thank you!
Best regards
Sarah

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai...@googlegroups.com.

Gonçalo Lopes

unread,
Apr 21, 2020, 5:16:54 PM4/21/20
to Sarah P, Bonsai Users
Hi Sarah,

The nodes from the DAQmx package should work for this, but make sure the .NET support is installed with the drivers as discussed here (I think they come now by default):

Hope this helps.

To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/f1fffe53-ae81-4676-8120-817e3c4b3414%40googlegroups.com.

Sarah P

unread,
May 15, 2020, 3:02:40 PM5/15/20
to Gonçalo Lopes, Bonsai Users
Hi Goncalo,
I would like to explain my system here. It will be a good reference to point to whenever I ask my questions.

My experiment currently records from mice using a 2-photon microscope (~9.8 Hz sampling rate), an EEG amplifier output from an AC-amplifier (-10 to 10 V, 1-2kHz), 2 USB webcams (25-30Hz), 1 video eye tracking camera with a coaxial video output (unsure of sampling rate), and the X and Y running position of the mice on a treadmill detected using a sensor much like a computer mouse sensor (200Hz-1KHz). To these data sets, we eventually want to include TTLs of a laser for optogenetics and other sensory stimuli (i.e., smell, motors, etc).

The X and Y mouse running position is an analog voltage signal ranging from 0 - 10 V, which we will capture using analog input channels of the NI-USB6001 at a sampling rate of 200Hz ~1kHz.

The EEG signal is also an analog voltage signal, which we will capture using an analog input channel of the NI-USB6001.

For all video recording devices, we are using (https://www.bhphotovideo.com/c/product/1131691-REG/inogeni_vga2usb3_usb_3_0_vga_video.html/specs) , the specification info says the frame rate is upto 60Hz, but I think it depends on the original video signal.  We treat this device as if it is a webcam. In addition to this device, we use a video signal combiner that accepts upto 4 video coaxial signals and compose a single video coaxial signal. The reasons why we used these options was 1. we want to monitor a video signal from the eye tracking system that is a coaxial video output, and 2. we were panning a simple system without a PCI board, and 3. by using a video combiner, we can add 3 additional cameras for environmental views.

With Bonsai, we want to synchronously trigger the recording to start and stop simultaneously. I would also use Bonsai's CombineLatest and Zip to sync the multiple camera frames and create a single montage video of all 3 cameras (2 USB webcams + 1 coaxial output eye tracking camera) along with the timestamps for each frame. We would also send the EEG signal and the mouse's X and Y running position and the eye tracking signal (i.e., pupil diameter) to the NI-USB6001 detected by an AnalogInput node of Bonsai. I am thinking that by using Zip and MatrixWriter in Bonsai, we can synchronize all these signals into one binary data set along with a column of respective timestamps. The timestamps are crucial because eventually, everything would have to be sync-ed with the 2-photon imaging data, which runs at the lowest sampling rate of 9.8Hz.

One concern we have is whether there would be a cumulative memory effect over a 30~40 min recording. Do you know how well Bonsai performs for 30-40 min recordings with this kind of system? As long as the recording is consistent over a 30-40 min session with a consistent jitter, we should be fine. If the recording slows down or skips frames more towards the end of the 30 min session, that would be a problem.

Thank you!
Best regards,
Sarah

Gonçalo Lopes

unread,
May 16, 2020, 9:53:26 AM5/16/20
to Sarah P, Bonsai Users
Hi Sarah,

Thanks for explaining your setup, this does help a lot in understanding all your other questions. Just quickly for now re. the question about memory, as long as you are not buffering any data in memory, there should be no reason why the system should have any problem with this, and arbitrarily long recordings should be quite doable.

The only issue is really making sure you are not inadvertently buffering data in time. For example, if you use Zip to line up two data streams that are not guaranteed to match 1-1 in time, then Zip will store data from the fastest stream to match it against data from the slowest stream. This can cause memory to accumulate, which is why in these cases CombineLatest is preferable because it only stores at most the latest value and also triggers the output immediately, so doesn't introduce latency in the temporal correlation.

Some preliminary remarks on the rest of the setup. In this case it looks like most of your fast signals are converging on the NI-USB board, which I guess you are hoping to use as a reference clock. It would make sense in that case to sample all these signals together (EEG, X/Y position, TTLs, etc) in the NI board so you don't have to worry about their synchronization. I agree doing a CombineLatest on the video seems the easiest, possibly using Sample afterwards with one of the fastest cameras as a master so you have a single clock for the video as well. I would benchmark whether you really need to log individual camera timestamps as well, or whether you could get away with just timestamping the output of CombineLatest. The reason is that the 2P is quite slow so the slight deterministic delay might be negligible (depending on your question), and in that case it would greatly simplify the system as you would treat everything as a single camera source. If that worked the whole system would be reduced to synchronizing one camera (carrying all videos) w/ one DAQ (carrying all analog signals).

Hope this helps, it does sound like an ambitious setup, looking forward to hear about it in action.

Sarah P

unread,
May 18, 2020, 2:04:05 PM5/18/20
to Bonsai Users
Hi Goncalo,
I totally agree with your suggestions on combining all the videos together as one stream with one timestamp, and sampling all the analog signals together (i.e., EEG, X/Y position, TTLs, etc) as one data stream.

I also agree that using CombineLatest would be best in my situation!

Thank you for your input!

Best,
Sarah
Reply all
Reply to author
Forward
0 new messages