TITLE: Building a SpikeGLX Rig with camera: Chronic recoverable Neuropixels in mice
AUTHORS: Emily A Aery Jones

[DESCRIPTION]
This protocol collection explains how to build a low-cost, lightweight system to implant Neuropixels 1.0 probes into mice, record during freely moving behavior, then recover the probe for future use. This protocol first describes how to build a Neuropixels recording system using a National Instruments acquisition system and SpikeGLX software, from parts acquisition through your first recording. It also describes how to integrate a camera, including code and wiring to record and synchronize video frames.

[BEFORE_START]
Set aside a few days to learn how the Neuropixels and SpikeGLX systems work
Read the latest Neuropixels manual: https://www.neuropixels.org/support
Join the Neuropixels community Slack to ask for help: https://neuropixelsgroup.slack.com/join/shared_invite/zt-3z0jaogn-iHLPIWBD8XC13JeTMPgglQ#/shared-invite/email
Watch the latest Neuropixels course online: https://github.com/cortex-lab/neuropixels/wiki
Read the SpikeGLX manual: https://github.com/billkarsh/SpikeGLX/blob/master/Markdown/UserManual.md

Select a machine vision camera configuration:
You will need a camera that you can manually wire to send synchronizing pulses to the NIDAQ system in order to synchronize video frames with neural data later.
You will need a camera, lens, power supply, mount, I/O cable with bare ends, data cable, tripod mount, and computer.
Supplier: Allied Vision cameras work with NIDAQ systems. This protocol explains how to wire an Allied Vision camera for this purpose.
Camera: Get a high enough resolution & frame rate for your project. Some cameras can adjust their settings so you can capture lower resolution at higher frame rates and vice versa. C(S)-mount refers to the lens attachment. C-mount cameras can take C or CS lenses, but CS-mount cameras can only take CS lenses.
Lens: The greater the focal length, the greater the zoom. Use this tool (https://www.baslerweb.com/en/products/tools/lens-selector) to estimate lens size based on camera to object distance and the size of the field. E.g. open field camera might use a 6mm lens, while a pupil camera might use a 24mm lens.
Power supply: whatever the camera needs. You may be able to power the camera through the data cable.
I/O cable with bare ends: This sends signals to the camera to start/stop capturing and receives signals of frame times.
Data cable: GigE (Cat6 cable) & USB are the most common. GigE is generally better over distances >5m.
Mounting: Attach to 80/20 by screwing into a tripod mount.
Computer: If you don't need real-time control, then just get a tower with enough SSD space to store your videos. If using GigE, make sure you get one that has PCIe cards to fit the Intel network adapter, and also get a PCIe Desktop Adapter.

[GUIDELINES]
The acquisition set up portion of this protocol is intended to be an unofficial, streamlined version of the official documentation, but not a replacement for it.

[STEPS]
SECTION: Set up acquisition hardware
1. Load the PCIe module into your computer
SECTION: Set up acquisition hardware
2. Load the PXIe modules and the IMEC module into the NIDAQ chassis
SECTION: Set up acquisition hardware
3. Connect the PXIe modules to the BNC breakout board and the computer. Connect the IMEC SMA to the BNC board (analog slot 0). Cover remaining unused BNC slots with BNC terminators to prevent TTLs from leaking across channels.
SECTION: Set up acquisition hardware
4. Plug in a probe, connected to a headstage, connected to a cable, into a port on the IMEC module.
  
SECTION: Set up acquisition hardware
5. Boot the chassis, then the computer.
 

SECTION: Set computer settings
6. Get your machine connected to the internet and install any institute-specific software.

SECTION: Set computer settings
7. Run any Windows updates. These can break things sometimes. If Windows updates that occur after the NIDAQ set up break your SpikeGLX, you can roll them back like this: https://www.howtogeek.com/235474/how-to-roll-back-builds-and-uninstall-updates-on-windows-10/
SECTION: Set computer settings
8. Change your power settings so your computer doesn't sleep: https://github.com/billkarsh/SpikeGLX/blob/master/Markdown/UserManual.md#screen-saver-and-power-settings
SECTION: Install National Instruments drivers
9. Install PXI Platform services: https://www.ni.com/en-us/support/downloads/drivers/download.pxi-platform-services.html
SECTION: Install National Instruments drivers
10. Install DAQmx: http://www.ni.com/en-us/support/downloads/drivers.html
SECTION: Install National Instruments drivers
11. Run NI MAX.
  

SECTION: Install Enclustra drivers
12. Download the Enclustra drivers: https://billkarsh.github.io/SpikeGLX/Support/Enclustra_Win10.zip. Unzip them anywhere.
SECTION: Install Enclustra drivers
13. Open Device Manager. Under "Other Devices", right-click the PXI device and select "Update". Select browse from my computer and select the folder where you unzipped the Enclustra drivers.
SECTION: Install Enclustra drivers
14. The PXI device should now appear under "Enclustra" in the Device Manager.
SECTION: Install SpikeGLX
15. Create the directory C:/SpikeGLX
SECTION: Install SpikeGLX
16. Download the latest release: https://billkarsh.github.io/SpikeGLX/#latest-application-downloads. Unzip and place the the whole thing, still inside the release folder, into your new SpikeGLX folder.
SECTION: Install SpikeGLX
17. Copy all the Calibration files that you received via email when you purchased the probes into the Calibration folder in SpikeGLX. Note that some of them have typos from when IMEC sent them. The correct format is [probe #]/[probe #][ADCCalibration or gainCalValues]. I.e. each probe should have its own directory named after it, with 2 files inside with the probe number once, underscore, and the file type.
 

SECTION: Update firmware
18. Launch SpikeGLX. Go to Tools/Update Imec Firmware.
SECTION: Update firmware
19. Select the slot your IMEC module is in.
SECTION: Update firmware
20. Check the box and select the file(s) for a BS and a BSC update. The files for this version of SpikeGLX are in the folder named Firmware that is included in your SpikeGLX release. Click Update.
SECTION: Update firmware
21. Power cycle by shutting down the computer, then the NIDAQ, and waiting for a few seconds before rebooting.
SECTION: Test the probe and headstage
22. Launch Spike GLX. Tools/BIST Test or Tools/HST Test.
SECTION: Test the probe and headstage
23. Select the slot your IMEC module is in, the port your headstage is in, and dock 1.
SECTION: Test the probe and headstage
24. For HST, plug in the headstage test device. Note as of April 2021, this isn't working in the newest IMEC updates.
SECTION: First acquisition
25. Launch SpikeGLX. File/New Acquisition.
SECTION: First acquisition
26. Check the boxes for enable IMEC and enable NIDAQ.
SECTION: First acquisition
27. Select the slot your module is in and click Add. Then uncheck the boxes except for the row with the port your headstage is plugged into and dock 1 (dock 2 is for 2.0 probes). Click detect.
SECTION: Calibrate the headstage clock
29. Calculate the true sample rate and determine how the headstage and computer clocks map. Do this for every new headstage. First, launch SpikeGLX and detect the headstage, as described above.
SECTION: Calibrate the headstage clock
30. In the "NI Setup" tab, specify 0:7 analog (XA) and 0:7 digital (XD).
SECTION: Calibrate the headstage clock
31. Go to the Sync tab of the Configuration to set up the sync pulse.
Select “Imec slot x" under Square Wave Source, where x is the slot of the Imec card in the PXIe chassis. This produces a 1 Hz square wave with 50% duty cycle. The sync output will be visible on the last channel of the "imec0 probe", SY0, bit #6.
Input channel should be Analog 0.
Measured period should read “1.00000…” and Threshold should read “1.100."
Check “Use next run for calibration".
Set calibration time: 20 min minimum, 40 min is ideal.
SECTION: Calibrate the headstage clock
32. Click Run to do a Calibration run.
SECTION: Calibrate the headstage clock
33. When Calibration run is done recording, should get a popup dialog with the measured sample rate. Check “Yes” to apply the new sample rates.
SECTION: Calibrate the headstage clock
34. The Calibration file is now in C:/SpikeGLX/Release_<#>/SpikeGLX/_Calibration. You will have:
1 file for _imec, with 1 entry per headstage in the file - if you’ve calibrated with that headstage, you’re calibrated with any probe attached to it.
1 file for _nidaq
SECTION: First acquisition
28. From here, follow the SpikeGLX user manual. Briefly: set your probe configuration (e.g. which reference to use, which block of channels to record): https://github.com/billkarsh/SpikeGLX/blob/master/Markdown/UserManual.md#im-setup----configuring-imec-probes in the "IM Setup" tab and the name of your file in the "Save" tab. Click "Run" to start streaming, and "Enable recording" to start recording to a file.
SECTION: Calibrate the headstage clock
35. During subsequent acquisitions, SpikeGLX should automatically use your most recent Calibration files. You can also choose them manually in the Sync tab. In the Sync tab, make sure "Use next run for calibration" is unchecked and keep the sync pulse enabled to use the calibrated clock.


 

SECTION: Set up the camera
36. Plug the I/O cable and the data cable into the camera. Screw tripod adapter onto base, then attach the adapter to an 80/20 L-bracket mounted on 80/20 frame or to Thorlabs components mounted on an air table, depending on your setup.
    

SECTION: Wire I/O cable to send TTL pulses from camera to SpikeGLX
38. To synchronize your video data with your neural data, you'll need to send TTL pulses from the camera to the BNC breakout board. To do so, you'll need to wire the Hirose cable to an external power and to the BNC board. First, look up the correct pinout for your Hirose I/O cable: https://cdn.alliedvision.com/fileadmin/content/documents/products/accessories/cable/datasheet/Acc_Cable_DataSheet_K7600xxx_AVT_IOcable_V4.1.1_en.pdf
SECTION: Set up the camera
37. Set up the camera acquisition computer and acquisition software as described by your camera's manufacturer. This should be a separate computer from the SpikeGLX acquisition computer. For Allied Vision cameras connecting via GigE cables, you can follow hardware instructions here: https://github.com/emilyasterjones/X_maze#gige-vimba-camera-acquisition-instructions
SECTION: Wire I/O cable to send TTL pulses from camera to SpikeGLX
39. Wire thusly, to a breadboard first while you troubleshoot, then solder and protect with heatshrink tubing. Use the block diagrams starting on page 136 of this document as a guide: https://cdn.alliedvision.com/fileadmin/content/documents/products/cameras/Mako/techman/Mako_TechMan_en.pdf
output power & camera power => power
camera ground & BNC ground => ground
camera output & BNC input => resistor => ground
  
 


SECTION: Wire I/O cable to send TTL pulses from camera to SpikeGLX
40. Set camera settings thusly:
    

SECTION: Wire I/O cable to send TTL pulses from camera to SpikeGLX
41. Run SpikeGLX, then hit Run on Vimba Viewer. If it worked, you should see an upward pulse for the duration of the exposure.
  
 


SECTION: Acquire video
42. Neither SpikeGLX nor Allied Vision have accompanying video acquisition software (Allied Vision's Vimba Viewer allows streaming but not recording of video). To acquire video, use a script to connect to the camera, define its acquisition settings including those for sending TTL pulses, acquire each frame and save it.

One simple option is to install the following: https://github.com/emilyasterjones/X_maze#gige-vimba-camera-acquisition-instructions and then run this script: https://github.com/emilyasterjones/X_maze/tree/main/Capture/Camera.  Several camera config files are included; you can create your own by opening Vimba Viewer, searching for and setting relevant variables, then saving this configuration to a file. in particular, adjust the frame rate, gain, and exposure time to suit your project.