Difference between revisions of "Wire-free Miniscope"

From UCLA Miniscope
Jump to: navigation, search
(Generally information, notes, and troubleshooting)
(Major new Miniscope components that need to be ordered)
 
(54 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 +
 +
 
== Overview ==
 
== Overview ==
 +
 
The wire-free Miniscope is a battery powered, data logging Miniscope that is fully untethered from external DAQ and power hardware. This system is a modification to the current wired Miniscope system (version 3.2) and shares all the same components except for the focus slider, CMOS PCB, and DAQ PCB. Below covers everything needed to get up and running with the wire-free Miniscope system.
 
The wire-free Miniscope is a battery powered, data logging Miniscope that is fully untethered from external DAQ and power hardware. This system is a modification to the current wired Miniscope system (version 3.2) and shares all the same components except for the focus slider, CMOS PCB, and DAQ PCB. Below covers everything needed to get up and running with the wire-free Miniscope system.
 +
[[File:wire-free-header.png|center|600px|Wire-Free Miniscope Project.]]
 +
<br clear=all>
  
 +
 +
=== General information, notes, and troubleshooting ===
 
[[File:Wire-free.PNG|thumb|right|600px|Wire-free schematic and PCB.]]
 
[[File:Wire-free.PNG|thumb|right|600px|Wire-free schematic and PCB.]]
  
=== Generally information, notes, and troubleshooting ===
+
* '''All design files, source code, firmware, and software can be found [https://github.com/daharoni/wire-free-miniscope here].'''
* All design files, source code, firmware, and software can be found[https://github.com/Aharoni-Lab/Documentation-Internal/tree/master/Projects/Wire-Free-Miniscope here].
+
* The wire-free Miniscope optics are very similar to the v3 Miniscope. You can use the same Miniscope body, cover, baseplates, and magnets. The two systems are completely interchangeable on the animal.
* The wire-free Miniscope's gain, excitation LED power, and recording length is configured on power-up once an sdCard is detected by the on board microcontroller. The microcontroller checks specific memory locations in the sdCard to load the configuration. Configurations are initially uploaded onto the sdCard using our MiniscopeSDCardReader software.
+
* The wire-free Miniscope's gain, excitation LED power, and recording length is configured on power-up once an microSD card is detected by the on board microcontroller. The microcontroller checks specific memory locations in the microSD card to load the configuration. Configurations are initially uploaded onto the microSD card using our MiniscopeSDCardReader software.
* Once the wire-free Miniscope has been powered up and an sdCard has been detected, the Miniscope waits 5 seconds then begins recording at 20FPS. At the start of recording the red status LED on the wire-free PCB will light up. Once recording has finished the red status LED will turn off. You can use the on and off timing of this LED to synchronize wire-free Minsicope recordings with an external behavioral camera.
+
* Once the wire-free Miniscope has been powered up and a microSD card has been detected, the Miniscope waits 5 seconds then begins recording at 20FPS. At the start of recording the red status LED on the wire-free PCB will light up. Once recording has finished the red status LED will turn off. You can use the on and off timing of this LED to synchronize wire-free Minsicope recordings with an external behavioral camera.
* The last 12 pixels values of each frame recorded to the sdCard are over written with a footer that contains four 32bit values. The second to last 32bit value contains the time stamp of that frame. This timestamp is in milliseconds and relative to the start of recording. We have validated that this timestamp is extremely stable across 25 minute recordings. Below is an example code snippet of how you can reconstruct the timestamp for a give frame 'frame' in MATLAB:
+
* The last 12 pixels values of each frame recorded to the microSD card are over written with a footer that contains four 32bit values. The second to last 32bit value contains the time stamp of that frame. This timestamp is in milliseconds and relative to the start of recording. We have validated that this timestamp is extremely stable across 25 minute recordings. Below is an example code snippet of how you can reconstruct the timestamp for a give frame 'frame' in MATLAB:
  
<code>footer = (frame(end,(end-7):end)); <br> ms.time(frameNum) = footer(1) + ...  <br> bitshift(footer(2),8) + ...  <br> bitshift(footer(3),16) + ...  <br> bitshift(footer(4),24);  </code>
+
<code>footer = (frame(end,(end-7):end)); timestamp = footer(1) + bitshift(footer(2),8) + bitshift(footer(3),16) + bitshift(footer(4),24);  </code>
  
 
* The wire-free system will run on any single cell lipo battery (and more generally, with anything supplying between 4.2V and 3.4V that is capable of supplying ~80mA).  With a 45mAh single cell lipo battery you can expect to get slightly over 20 minutes of recording.  
 
* The wire-free system will run on any single cell lipo battery (and more generally, with anything supplying between 4.2V and 3.4V that is capable of supplying ~80mA).  With a 45mAh single cell lipo battery you can expect to get slightly over 20 minutes of recording.  
Line 19: Line 26:
 
== Tutorial on setting up a new wire-free Miniscope ==
 
== Tutorial on setting up a new wire-free Miniscope ==
 
=== 1) First we need to make sure we have all the components and software to get things up and running. ===
 
=== 1) First we need to make sure we have all the components and software to get things up and running. ===
==== New components that need to be made ====
+
The Open Ephys Production Site (OEPS) is now stocking and has available to order all the components needed to convert a wired Miniscope into a Wire-Free Miniscope. They carry the individual components listed below as well as a fully programmed and tested Wire-Free Miniscope Modification Kit. '''For more information and to get a quote or submit an order, visit their [https://open-ephys.org/miniscope-v3-wirefree Wire-Free Miniscope Web Store].''' You can also follow the information below to order components through other venders.
 +
==== Major new Miniscope components that need to be ordered ====
 +
The wire-free Miniscope uses all the same hardware and optics as the standard v3 Miniscope except for the focus slider and CMOS PCB. It also doesn't use the Miniscope DAQ PCB.
 +
* '''Wire-free Miniscope Focus Slider''': You can get the wire-free focus slider machined by Shylo Stiteler <shylostiteler@gmail.com>, [https://open-ephys.org/miniscope-v3-wirefree/wire-free-v3-focus-slider ordered through OEPS] or elsewhere. The design file and dimensions are in the "wire-free focus slider" folder in our github repository.
 +
[[File:MS_FocusSlidervWireless.png|thumb|right|300px|Wire-free focus slider.]]
 +
When assembling the Miniscope, if the resistors on the PCB prevents the focus slider from fitting in snugly, you can use a scalpel to indent the top of the focus slider.
 +
[[File:FS_mod.png|thumb|right|300px|Rendering of cut out of focus slider to avoid hitting resistors on PCB.]]
 +
<br clear=all>
 +
* '''Wire-free Miniscope CMOS PCB''': You will also need the wire-free CMOS PCB. '''''You can order this PCB programmed and tested along with all the supporting equipment (batteries, connectors, chargers, SD Cards) from [https://open-ephys.org/miniscope-v3-wirefree OEPS's Wire-Free page].''''' Of course you can also get this PCB made at your preferred PCB fab/assembly house as well. You can find the fabrication and assembly files in the "wire-free CMOS PCB" folder.
 +
[[File:wire-free-PCB.png|thumb|right|300px|Wire-free PCB.]]
 +
<br clear=all>
 +
 
 +
==== Additional components that may need to be ordered ====
 +
The list below outlines the additional hardware and tools you need when setting up your own wire-free Miniscope. If you purchase a wire-free Miniscope system from Filipe Carvalho <filipe@open-ephys.org> you won't need the Atmel ICE as the PCB will already come programmed. Also, he can supply SDcards, batteries that are already wired up with the correct connectors, and an open-source lipo charging array with appropriate charge current.
  
* Wire-free Miniscope Focus Slider: The wire-free Miniscope using all the same hardware and optics as the standard v3 Miniscope except for the focus slider and CMOS PCB. It also doesn't use the Miniscope DAQ PCB. You can get the wire-free focus slider machined by Shylo or else where and the design file and dimensions are in the "wire-free focus slider" folder. When assembling the Miniscope, if the resistors on the PCB prevents the focus slider from fitting in snugly, you could use a scapel to indent the top of the focus slider.
+
If you are having the wire-free PCB produced somewhere else you will need the following:
* Wire-free Miniscope CMOS PCB: You will also need the wire-free CMOS PCB. You can find the fabrication and assembly files in the "wire-free CMOS PCB" folder.
 
==== Components that need to be bought ====
 
 
* [https://www.digikey.com/products/en?mpart=ATATMEL-ICE&v=150 Atmel ICE] for programming the wire-free PCB
 
* [https://www.digikey.com/products/en?mpart=ATATMEL-ICE&v=150 Atmel ICE] for programming the wire-free PCB
 
* Micro SD cards. We like to use [https://www.amazon.com/Sandisk-Extreme-MicroSDHC-UHS-I-SDSDQXL-032G-A46A/dp/B00G5R75AU/ref=sr_1_13?s=electronics&ie=UTF8&qid=1543963603&sr=1-13&keywords=sandisk+micro+sd+card+extreme these microSD cards]. The SanDisk microSD extreme cards seem to perform best.
 
* Micro SD cards. We like to use [https://www.amazon.com/Sandisk-Extreme-MicroSDHC-UHS-I-SDSDQXL-032G-A46A/dp/B00G5R75AU/ref=sr_1_13?s=electronics&ie=UTF8&qid=1543963603&sr=1-13&keywords=sandisk+micro+sd+card+extreme these microSD cards]. The SanDisk microSD extreme cards seem to perform best.
* [https://www.powerstream.com/ultra-light.htm Small Lipo battery]. The 45mAH batteries seemed to work best and give us about 20 minutes of recording time. You may also want to purchase some batteries to test from wyon,https://www.wyon.ch/en/home.html. We are in the process of testing their W101 and W102 batteries. These might cut out another 0.5 grams if they work well.
+
* [https://www.powerstream.com/ultra-light.htm Small Lipo battery]. These 45mAH batteries from Powerstream are cheap, easy and work well.  They reliably give just over 20 minutes of recording time. We have also used batteries from [https://www.wyon.ch/en/home.html Wyon]. These batteries are significantly lighter and give longer recording times, but are more expensive and in the past we have had to wait several months to get them. We have had success with their W102 batteries, and are still looking to test their W101 batteries (a bit smaller and lighter).
 
* Mill-Max 50mil male and female headers. You can get these from digikey.com and they are used to connect the lipo battery and programmer to the CMOS PCB.
 
* Mill-Max 50mil male and female headers. You can get these from digikey.com and they are used to connect the lipo battery and programmer to the CMOS PCB.
* [https://www.sparkfun.com/products/10217 Lipo battery charger]. Most single cell lipo chargers will work. You will need to modify many standard lipo chargers to limit their charging current to what your battery can handle. This is generally done by swapping on a surface mount resistor on the charger PCB.
+
* [https://www.sparkfun.com/products/10217 Lipo battery charger]. Most single cell lipo chargers will work. You will need to modify many standard lipo chargers to limit their charging current to what your battery can handle. This is generally done by swapping on a surface mount resistor on the charger PCB (see below).
 
* [https://www.digikey.com/product-detail/en/yageo/RC0603FR-0749K9L/311-49.9KHRCT-ND/730212 50K Resistor]. ~50kOhm 0603 resistors to modify the battery charger.
 
* [https://www.digikey.com/product-detail/en/yageo/RC0603FR-0749K9L/311-49.9KHRCT-ND/730212 50K Resistor]. ~50kOhm 0603 resistors to modify the battery charger.
 
* [https://www.amazon.com/Tekpower-TP3016M-Portable-Handheld-Variable/dp/B015OA1J82 Power source]. This could be helpful when we are programming and testing the PCB.
 
* [https://www.amazon.com/Tekpower-TP3016M-Portable-Handheld-Variable/dp/B015OA1J82 Power source]. This could be helpful when we are programming and testing the PCB.
 +
* [https://www.amazon.com/AmazonBasics-Male-Micro-Cable-Black/dp/B072J1BSV6/ref=sr_1_1_sspa?crid=19OWZCA50WRE7&keywords=micro+usb+amazon+basics&qid=1555957481&s=gateway&sprefix=micro+usb+amazon+%2Caps%2C337&sr=8-1-spons&psc=1 USB cable]. Micro USB cables to go with the lipo chargers.
  
 
==== Software to download ====
 
==== Software to download ====
Line 59: Line 78:
 
<br clear=all>
 
<br clear=all>
  
* Make sure to never short the 2 metal strips of the lipo battery. If you do, it could damage the battery perminately.
+
* Make sure to never short the 2 metal strips of the lipo battery. If you do, it could damage the battery permanently.
 
* Use a multimeter to test which metal strip is the + and which is the - (GND).
 
* Use a multimeter to test which metal strip is the + and which is the - (GND).
 
* When soldering wires to the lipo, try to minimize the amount of heat traveling to the lipo battery.
 
* When soldering wires to the lipo, try to minimize the amount of heat traveling to the lipo battery.
Line 66: Line 85:
 
==== Connectorizing the Atmel ICE programmer ====
 
==== Connectorizing the Atmel ICE programmer ====
 
* In order to program the microcontroller on the CMOS PCB, we first need to wire-up and connectorize a 4pin Mill-Max header to the 4 programming pins of the Atmel ICE programmer. These are GND, VTG, SWDIO, and SWDCLK. Below shows which pins/wires of the Atmel ICE have which function. The Atmel ICE has 2 different 5x2 pin ports. One is labeled AVR and one is labeled SAM. Either will work but depending on which one you are using it will change which column you refer to in the below chart.
 
* In order to program the microcontroller on the CMOS PCB, we first need to wire-up and connectorize a 4pin Mill-Max header to the 4 programming pins of the Atmel ICE programmer. These are GND, VTG, SWDIO, and SWDCLK. Below shows which pins/wires of the Atmel ICE have which function. The Atmel ICE has 2 different 5x2 pin ports. One is labeled AVR and one is labeled SAM. Either will work but depending on which one you are using it will change which column you refer to in the below chart.
![Atmel ICE SWD pinout](img/atmel-ice-swd-pinout.PNG)
+
 
 +
[[File:atmel-ice-swd-pinout.png|thumb|right|600px|Chart]]
 +
<br clear=all>
 +
 
 
* Connect the Atmel ICE to the programming header of the CMOS PCB.
 
* Connect the Atmel ICE to the programming header of the CMOS PCB.
 
* Power up the CMOS PCB through the lipo connector (2pin Mill-Max head with Lipo+ and GND). You can hook up a charged lipo battery but we suggest using a power supply between 3.5V and 4.2V here. This way you don't have to worry about a battery running out of charge during programming and testing. You can cap the maximum current output of the power source at 0.150A just to be safe. The power source should measure a current of about 0.03A when 3.8V is supplied to the PCB.
 
* Power up the CMOS PCB through the lipo connector (2pin Mill-Max head with Lipo+ and GND). You can hook up a charged lipo battery but we suggest using a power supply between 3.5V and 4.2V here. This way you don't have to worry about a battery running out of charge during programming and testing. You can cap the maximum current output of the power source at 0.150A just to be safe. The power source should measure a current of about 0.03A when 3.8V is supplied to the PCB.
Line 106: Line 128:
 
* Select 'Tools' then select 'Open Disk' from the drop down menu
 
* Select 'Tools' then select 'Open Disk' from the drop down menu
 
* Uncheck the 'Open as Readonly' option in the bottom left of the window, select the SD card from the list of disks, and then click 'OK'. If the disk is not showing up, restarting the computer might help.
 
* Uncheck the 'Open as Readonly' option in the bottom left of the window, select the SD card from the list of disks, and then click 'OK'. If the disk is not showing up, restarting the computer might help.
![HxD selecting sd card](img/HxD1.PNG)
 
  
 +
[[File:HxD1.PNG|thumb|right|600px|HxD.]]
 +
<br clear=all>
  
 
* '''We will now be writing directly to memory blocks of the drive. Make sure you have selected the SD Card and not another drive'''
 
* '''We will now be writing directly to memory blocks of the drive. Make sure you have selected the SD Card and not another drive'''
Line 128: Line 151:
  
 
=== 6) Modifying the Lipo charger ===
 
=== 6) Modifying the Lipo charger ===
In general any single cell lipo charger will work for charging the batteries used for the wire-free Miniscope but you have to make sure that the max current the charge can output is limited to around 20mA. The Sparkfun Lipo charger listed at the top of this tutorial is capped at 500mA by default so we will need to modify the charger to limit the current to ~20mA. The way we do this is by replacing the SMD resistor circled in blue below with a ~50kOhm 0603 resistor. If you don't have a ~50kohn resistor on hand you can [https://www.digikey.com/product-detail/en/yageo/RC0603FR-0749K9L/311-49.9KHRCT-ND/730212 order one from digikey].
+
In general any single cell lipo charger will work for charging the batteries used for the wire-free Miniscope but you have to make sure that the max current the charge can output is limited to around 20mA. The Sparkfun Lipo charger listed at the top of this tutorial is capped at 500mA by default so we will need to modify the charger to limit the current to ~20mA. The way we do this is by replacing the SMD resistor circled in blue below with a ~50kOhm 0603 resistor. If you don't have a ~50kohn resistor on hand you can [https://www.digikey.com/product-detail/en/yageo/RC0603FR-0749K9L/311-49.9KHRCT-ND/730212 order one from digikey]. If the solder around the resistor is hard to remove, it might help to add a little bit of new solder.
  
 
[[File:SparkfunChargerMod.png|thumb|right|600px|Sparkfun modified charger.]]
 
[[File:SparkfunChargerMod.png|thumb|right|600px|Sparkfun modified charger.]]
Line 134: Line 157:
  
 
You will also need to modify or swap out the lipo connector on the right of the board with connector that can mate to the connector you put on your lipo batteries.
 
You will also need to modify or swap out the lipo connector on the right of the board with connector that can mate to the connector you put on your lipo batteries.
 +
 +
== How to record with the wire-free Miniscope system ==
 +
After following the wire-free Miniscope tutorial above you should now be ready to record using the system. Imaging using the wire-free Miniscope has a few extra steps compared to the wired Miniscope but you set up a workflow for recording the system is often times easier to use than the wired one.
 +
 +
=== Steps for imaging in an untethered animal ===
 +
# Use a wired Miniscope to get a ballpark idea of focal depth and excitation power needed for a specific animal.
 +
# Set the focal height of the wire-free Miniscope as close as possible to the wired Miniscope you used in step 1.
 +
# Using the MiniscopeSDCardReader software, set the Gain, LED Power, and recording length. We suggest using a ~5 second recording length when first figuring out these settings. This will allow you to quickly image and then check the recording.
 +
[[File:MiniscopeSDCardReader2.png|thumb|right|600px|Settings.]]
 +
<br clear=all>
 +
# Now that you have the focal depth set as well as the gain and LED power figured out, you are ready for your experiment. Mount the wire-free Miniscope on the baseplate on the animal's head.
 +
# Place a microSD card in the SD card mount on the wire-free Miniscope PCB.
 +
# Plug in a '''fully charged''' single cell lipo.
 +
# The wire-free Miniscope will now power up and detect the SD card. You can also power up the Miniscope before mounting the SD card but we have found this to be slightly less stable than the other way around. '''The Miniscope will wait exactly 5 seconds''' before turning on its red status LED and beginning recording.
 +
# The Miniscope will now record for the recording length you previously set through the MiniscopeSDCardReader software. Once the recording has finished the red status LED will turn off. Unplug the lipo battery then remove the SD card.
 +
# Imaging data is stored in a raw format on the SD card. There are no files or folder structures on the SD card. The recording begins in memory block 1024 and will continue until the end of the recording is reached.
 +
 +
=== Steps for transferring a recording from an SD Card to a computer ===
 +
Now that you have a wire-free Miniscope stored on an SD Card, we need to transfer it to a computer. As mentioned above, the wire-free Miniscope records raw pixel byte values directly to memory blocks in the SD Card. This means that when the card is mounted in a computer, the computer will think that the card needs to be reformatted. This is due to the SD Card not having a file system on it. '''Always ignore the recommendation of your computer to reformat the SD Card as well as if it says the SD Card is corrupted.'''
 +
# Mount the SD Card in your computer. If you computer doesn't have a built in SD Card mount, you can use an external USB SD Card mount.
 +
# Open the MiniscopeSDCardReader software in with Administrator privileges. You will need this since we will be directly reading/writing memory blocks.
 +
## The "Drive" is the name of the SD Card. This defaults to "PhysicalDrive1" but you should double check you are using the correct name of the SD Card drive.
 +
## The "Starting Sector" is the memory block where the beginning of the Miniscope recording is located. This should not need to ever be changed from "1024".
 +
## '''Note''': Whenever this software attempts to access data on the SD Card, it first checks to make sure the correct 128bit "WRITE KEY" is stored in memory block 1023. This WRITE KEY was placed there by you if you followed the tutorial above. The goal of this WRITE KEY is it makes it extremely unlikely that you end up accessing or modifying any other drive on your computer since the chances of another drive having the 128bit WRITE KEY located at memory block 1023 is highly unlikely. When you do try accessing data on the SD Card, the text box at the bottom of the GUI will tell you if it found the correct WRITE KEY or if it found the wrong one and stopped the requested action.
 +
# Now you can use the "Read/Save Data" portion of the software to do exactly that... read and/or save the wire-free Miniscope data.
 +
## First enter in the length of the recording you want to extract from the SD Card. This says "Number of Seconds" but I think it is actually "Number of Frames" (''I will get around to fixing this sometime soon...''). The wire-free Miniscope records at 20FPS so you should usually just set this number a bit longer than the expected recording to make sure you grab all the data.
 +
## If you click "Read" the software will open up a window that will play the wire-free Miniscope recording. On some computers using some versions of OpenCV, this option for some reason doesn't actually update the window and it just shows black the whole time. We recommend to use "Save" in all cases if this happens to you.
 +
## If you click "Save" the software will display the video as it extracts it from the SD Card and writes it to the computer's drive. It will save a copy of the wire-free recording in the "data" folder located where ever your MiniscopeSDCardReader software is located. We generally recommend you using the "Save" option over the "Read" option since the read option can be buggy on some computers.
 +
# Check to make sure the data is now saved as an uncompressed .avi file on your computer.
 +
# Once you have your data transferred to your computer we highly recommend clearing the SD Card before beginning a new recording:
 +
## You can do this using the "Clear SD Card" section of the software. Here you can define the number of frames to clear from the SD card and then clear/delete them.
 +
## Set the number of frames to clear first. We suggest entering a number that is larger than the expected length of recording currently on the SD Card.
 +
## Click "Delete" and the software will set all bytes in these memory block in the SD Card to 0.
 +
## '''Note''': It will not delete the settings located in memory block 1023. This means you can now reuse this SD Card without reprogramming the gain, LED power, and recording length.
 +
# '''Note''': Each frame is timestamped and the timestamp is embedded within each frame. You can extract the timestamp by generating a 32bit integer from the last 8th, 7th, 6th, and 5th pixels in each frame. In MATLAB it would look something like this for a given frame:
 +
 +
<code>footer = (frame(end,(end-7):end)); timestamp = footer(1) + bitshift(footer(2),8) + bitshift(footer(3),16) + bitshift(footer(4),24);  </code>
 +
 +
You're Done!

Latest revision as of 11:42, 28 January 2020


Overview

The wire-free Miniscope is a battery powered, data logging Miniscope that is fully untethered from external DAQ and power hardware. This system is a modification to the current wired Miniscope system (version 3.2) and shares all the same components except for the focus slider, CMOS PCB, and DAQ PCB. Below covers everything needed to get up and running with the wire-free Miniscope system.

Wire-Free Miniscope Project.



General information, notes, and troubleshooting

Wire-free schematic and PCB.
  • All design files, source code, firmware, and software can be found here.
  • The wire-free Miniscope optics are very similar to the v3 Miniscope. You can use the same Miniscope body, cover, baseplates, and magnets. The two systems are completely interchangeable on the animal.
  • The wire-free Miniscope's gain, excitation LED power, and recording length is configured on power-up once an microSD card is detected by the on board microcontroller. The microcontroller checks specific memory locations in the microSD card to load the configuration. Configurations are initially uploaded onto the microSD card using our MiniscopeSDCardReader software.
  • Once the wire-free Miniscope has been powered up and a microSD card has been detected, the Miniscope waits 5 seconds then begins recording at 20FPS. At the start of recording the red status LED on the wire-free PCB will light up. Once recording has finished the red status LED will turn off. You can use the on and off timing of this LED to synchronize wire-free Minsicope recordings with an external behavioral camera.
  • The last 12 pixels values of each frame recorded to the microSD card are over written with a footer that contains four 32bit values. The second to last 32bit value contains the time stamp of that frame. This timestamp is in milliseconds and relative to the start of recording. We have validated that this timestamp is extremely stable across 25 minute recordings. Below is an example code snippet of how you can reconstruct the timestamp for a give frame 'frame' in MATLAB:

footer = (frame(end,(end-7):end)); timestamp = footer(1) + bitshift(footer(2),8) + bitshift(footer(3),16) + bitshift(footer(4),24);

  • The wire-free system will run on any single cell lipo battery (and more generally, with anything supplying between 4.2V and 3.4V that is capable of supplying ~80mA). With a 45mAh single cell lipo battery you can expect to get slightly over 20 minutes of recording.
  • The suggested workflow is to first image the animals with a wired Miniscope to get an estimate of focal depth, gain, and excitation LED power. Set these parameters on the wire-free Miniscope and then do short recordings, checking the resulting video each time, while adjusting the parameters until you have achieved good imaging. In our experience, once you find the optimal parameters you should be able to keep those same parameters across weeks.


Tutorial on setting up a new wire-free Miniscope

1) First we need to make sure we have all the components and software to get things up and running.

The Open Ephys Production Site (OEPS) is now stocking and has available to order all the components needed to convert a wired Miniscope into a Wire-Free Miniscope. They carry the individual components listed below as well as a fully programmed and tested Wire-Free Miniscope Modification Kit. For more information and to get a quote or submit an order, visit their Wire-Free Miniscope Web Store. You can also follow the information below to order components through other venders.

Major new Miniscope components that need to be ordered

The wire-free Miniscope uses all the same hardware and optics as the standard v3 Miniscope except for the focus slider and CMOS PCB. It also doesn't use the Miniscope DAQ PCB.

  • Wire-free Miniscope Focus Slider: You can get the wire-free focus slider machined by Shylo Stiteler <shylostiteler@gmail.com>, ordered through OEPS or elsewhere. The design file and dimensions are in the "wire-free focus slider" folder in our github repository.
Wire-free focus slider.

When assembling the Miniscope, if the resistors on the PCB prevents the focus slider from fitting in snugly, you can use a scalpel to indent the top of the focus slider.

Rendering of cut out of focus slider to avoid hitting resistors on PCB.


  • Wire-free Miniscope CMOS PCB: You will also need the wire-free CMOS PCB. You can order this PCB programmed and tested along with all the supporting equipment (batteries, connectors, chargers, SD Cards) from OEPS's Wire-Free page. Of course you can also get this PCB made at your preferred PCB fab/assembly house as well. You can find the fabrication and assembly files in the "wire-free CMOS PCB" folder.
Wire-free PCB.


Additional components that may need to be ordered

The list below outlines the additional hardware and tools you need when setting up your own wire-free Miniscope. If you purchase a wire-free Miniscope system from Filipe Carvalho <filipe@open-ephys.org> you won't need the Atmel ICE as the PCB will already come programmed. Also, he can supply SDcards, batteries that are already wired up with the correct connectors, and an open-source lipo charging array with appropriate charge current.

If you are having the wire-free PCB produced somewhere else you will need the following:

  • Atmel ICE for programming the wire-free PCB
  • Micro SD cards. We like to use these microSD cards. The SanDisk microSD extreme cards seem to perform best.
  • Small Lipo battery. These 45mAH batteries from Powerstream are cheap, easy and work well. They reliably give just over 20 minutes of recording time. We have also used batteries from Wyon. These batteries are significantly lighter and give longer recording times, but are more expensive and in the past we have had to wait several months to get them. We have had success with their W102 batteries, and are still looking to test their W101 batteries (a bit smaller and lighter).
  • Mill-Max 50mil male and female headers. You can get these from digikey.com and they are used to connect the lipo battery and programmer to the CMOS PCB.
  • Lipo battery charger. Most single cell lipo chargers will work. You will need to modify many standard lipo chargers to limit their charging current to what your battery can handle. This is generally done by swapping on a surface mount resistor on the charger PCB (see below).
  • 50K Resistor. ~50kOhm 0603 resistors to modify the battery charger.
  • Power source. This could be helpful when we are programming and testing the PCB.
  • USB cable. Micro USB cables to go with the lipo chargers.

Software to download

  • Download HxD. This software will allow you to directly edit memory blocks of an SD card which will be needed to initially setup an SD card for wire-free Miniscope recording. NOTE: This software will allow you to modify any byte of data on any drive connected to your computer so observe particular caution when using it.
  • Download Atmel Studio. This will be used to program the microcontroller firmware onto the CMOS PCB.
  • Download the wire-free Miniscope software found in the "wire-free Miniscope software" folder. This software will allow you to read and save wire-free Miniscope data from an SD card as well as allow you to program recording parameters (exposure, gain, recording length) to the SD card which the Miniscope will read.

2) Now we need to get the wire-free CMOS PCB ready to be programmed with the wire-free Miniscope firmware.

Soldering the programming header

  • First solder a 4 pin Mill-Max 50mil pitch header to the 4 pad programming interface on the wire-free CMOS PCB. The connections of this programming header are as follows:
Programming header.


Soldering the lipo battery connector and excitation LED wires

  • You can also now solder a 2 pin Mill-Max 50mil pitch header and wires for the excitation LED PCB to the three pads near to top of the board in the above picture. First solder the Mill-Max header to Lipo+ and GND (this will be the connector for the lipo battery). Then solder the 2 LED wires to LED+ and the same middle GND pad that the Mill-Max header is soldered to. The CMOS PCB should now look something like this:
PCB sensor side.
PCB sd card side.


Let's also connectorize the Lipo battery

  • The lipo battery will come with 2 metal strips (initially protected with heat shrink) extending from the body of the battery which are its + and - voltage terminals. We want to solder a wire to each of these metal strips and then put a 2pin Mill-Max header on the other end of the wires so that the battery can connect to the Mill-Max header we soldered to the Lipo+ and GND pads of the CMOS PCB.
Lipo Battery.


  • Make sure to never short the 2 metal strips of the lipo battery. If you do, it could damage the battery permanently.
  • Use a multimeter to test which metal strip is the + and which is the - (GND).
  • When soldering wires to the lipo, try to minimize the amount of heat traveling to the lipo battery.

3) Programming the wire-free CMOS PCB

Connectorizing the Atmel ICE programmer

  • In order to program the microcontroller on the CMOS PCB, we first need to wire-up and connectorize a 4pin Mill-Max header to the 4 programming pins of the Atmel ICE programmer. These are GND, VTG, SWDIO, and SWDCLK. Below shows which pins/wires of the Atmel ICE have which function. The Atmel ICE has 2 different 5x2 pin ports. One is labeled AVR and one is labeled SAM. Either will work but depending on which one you are using it will change which column you refer to in the below chart.
Chart


  • Connect the Atmel ICE to the programming header of the CMOS PCB.
  • Power up the CMOS PCB through the lipo connector (2pin Mill-Max head with Lipo+ and GND). You can hook up a charged lipo battery but we suggest using a power supply between 3.5V and 4.2V here. This way you don't have to worry about a battery running out of charge during programming and testing. You can cap the maximum current output of the power source at 0.150A just to be safe. The power source should measure a current of about 0.03A when 3.8V is supplied to the PCB.
  • When the CMOS PCB gets powered on, you should see an orange light turn on on the Atmel ICE which shows that the Atmel ICE has detected voltage on the VTG (Voltage Target) pin. In the ATATMEL-ICE-ND, you should see a red light turn on showing that the Atmel box is powered, and a green light showing that the box is measuring a voltage from the PCB. Updating Atmel Studio and restarting the computer could all help with debugging.
  • Open Atmel Studio and click the "Device Programming" button
Atmel Studio device programming button.


  • In the Device Programming window that pops up select:
    • Tool: Atmel ICE
    • Device: ATSAM.... (should automatically be the correct name, ATSAME70N21)
    • Interface: SWD
    • Then click "Apply"
  • Now check to make sure that Atmel Studio can communicate with the microcontroller on the CMOS PCB. You do this by clicking the "Read" button under Device Signature. If everything is powered and connected correctly you should see some numbers and letter pop up in the box and no error window show up. Now we are ready to program the microcontroller.
device programming window.


  • Click "Memory" on the left menu panel of the Device Programming window we are currently in. If the memory tab is not showing up, make sure to select the tool, device, and interface and click apply again
  • Click "Browse" and locate the wire-free Miniscope firmware. This is a .hex file you can find in the "/wire-free-firmware" folder. Either the .hex or .elf file should work.
  • Click "Program". This will erase, program, and verify the microcontroller. It will tell you if everything was successful.
  • Exit the Device Programming window.
  • Now we have to do something a bit weird. I am not sure why this has to be done but it does. Open up the Atmel project found in the "/wire-free-firmware" folder. This load up the code that makes up the wire-free Miniscope firmware. Now click "Debug" from the top menu bar and then click "Start Debugging and Break". Wait about 15 seconds while the debugger does its thing in Atmel Studio and then the code should jump to the "main()" function and highlight it. Now click the play button (labelled "Start Debugging") in the top menu. Wait a few seconds then click the stop button (labelled "Stop Debugging").
Loading Atmel.
Debug buttons.


  • Go back to the "Device Programming" window by clicking the "Device Programming" button.
  • Repeat the steps to program the PCB with the .hex file.
  • Now the microcontroller on the wire-free Miniscope CMOS PCB knows how to be a wire-free Miniscope microcontroller.

4) Configure the micro SD card

The wire-free Miniscope and the Miniscope SD Card Reader software are able to read and write raw data directly into and out of the memory blocks of the SD card. In memory block 1023 of the SD card, we need to first write an a key that will, for all subsequnt writing to the SD card, be checked before any raw data writed to make sure we are not writing to the wrong drive. If we accidently write over a memory block on your computer's drive it can corrupt Windows so we need to be extra careful not to do that.

Add the Write Key to memory block 1023 of the SD Card

Here we will use the HxD software to directly write our Key into the SD Card.

  • Open the HxD software and run as Administrator
  • Select 'Tools' then select 'Open Disk' from the drop down menu
  • Uncheck the 'Open as Readonly' option in the bottom left of the window, select the SD card from the list of disks, and then click 'OK'. If the disk is not showing up, restarting the computer might help.
HxD.


  • We will now be writing directly to memory blocks of the drive. Make sure you have selected the SD Card and not another drive
  • Go to Sector 1023 and modify the first 16 bytes in this sector.We will be replacing the data in these 16 bytes with the write Key. The write Key is 0x0D7CBA17 repeated 4 times. After replacing these bytes it should look like this:
HxD write key.


  • Now click 'Save'.
  • Let's check to make sure everything was modified and saved correctly. Close HxD, pull out the SD card from the computer and then place it back in the computer. Now open up HxD, open the SD Card disk, go to sector 1023, and check to make sure the write Key is still there. If it is then we have correctly configured the SD Card for wire-free Miniscope recording.

5) Using the Miniscope SD Card Reader software

Our final step is to use the Miniscope SD Card Reader software to configure the LED power and Gain of the wire-free Miniscope. The way we do this is by writing the configuration into specific bytes of memory block 1023 of the SD card. The Miniscope SD Card Reader software handles all of this through a simple GUI.

  • Open the MiniscopeSDCardReader.exe and run as Administrator
Miniscope SD Card Reader.


  • You may need to change the 'Drive' name based on the naming your computer has given to the SD Card. In the image above it has defaulted to 'PhysicalDrive1' and this name should usually work. If a window pops up asking if you want to format the SD card, do not format it or it will undo what we programmed.
  • You can set the Gain, LED Power, and Recording Length. Once the correct numbers have been entered, click 'Set' to write those values to the SD card. The software makes sure the write Key is present in memory block 1023 before attempting to write this configuration. This is used to stop the software from writing to another disk but still be careful. A line should pop up in the bottom window saying “Write key match!”
  • After setting the configuration you can take out the SD card from the computer and mount it in the wire-free Miniscope. Once the Miniscope is powered on, it will wait 5 seconds and then begin recording. Always put in the SD card before plugging in the battery.
  • After recording with the Miniscope, take the SD card out of the Miniscope mount and place it in your computer. You can now use the MiniscopeSDCardReader software to view, save, and delete recordings.

6) Modifying the Lipo charger

In general any single cell lipo charger will work for charging the batteries used for the wire-free Miniscope but you have to make sure that the max current the charge can output is limited to around 20mA. The Sparkfun Lipo charger listed at the top of this tutorial is capped at 500mA by default so we will need to modify the charger to limit the current to ~20mA. The way we do this is by replacing the SMD resistor circled in blue below with a ~50kOhm 0603 resistor. If you don't have a ~50kohn resistor on hand you can order one from digikey. If the solder around the resistor is hard to remove, it might help to add a little bit of new solder.

Sparkfun modified charger.


You will also need to modify or swap out the lipo connector on the right of the board with connector that can mate to the connector you put on your lipo batteries.

How to record with the wire-free Miniscope system

After following the wire-free Miniscope tutorial above you should now be ready to record using the system. Imaging using the wire-free Miniscope has a few extra steps compared to the wired Miniscope but you set up a workflow for recording the system is often times easier to use than the wired one.

Steps for imaging in an untethered animal

  1. Use a wired Miniscope to get a ballpark idea of focal depth and excitation power needed for a specific animal.
  2. Set the focal height of the wire-free Miniscope as close as possible to the wired Miniscope you used in step 1.
  3. Using the MiniscopeSDCardReader software, set the Gain, LED Power, and recording length. We suggest using a ~5 second recording length when first figuring out these settings. This will allow you to quickly image and then check the recording.
Settings.


  1. Now that you have the focal depth set as well as the gain and LED power figured out, you are ready for your experiment. Mount the wire-free Miniscope on the baseplate on the animal's head.
  2. Place a microSD card in the SD card mount on the wire-free Miniscope PCB.
  3. Plug in a fully charged single cell lipo.
  4. The wire-free Miniscope will now power up and detect the SD card. You can also power up the Miniscope before mounting the SD card but we have found this to be slightly less stable than the other way around. The Miniscope will wait exactly 5 seconds before turning on its red status LED and beginning recording.
  5. The Miniscope will now record for the recording length you previously set through the MiniscopeSDCardReader software. Once the recording has finished the red status LED will turn off. Unplug the lipo battery then remove the SD card.
  6. Imaging data is stored in a raw format on the SD card. There are no files or folder structures on the SD card. The recording begins in memory block 1024 and will continue until the end of the recording is reached.

Steps for transferring a recording from an SD Card to a computer

Now that you have a wire-free Miniscope stored on an SD Card, we need to transfer it to a computer. As mentioned above, the wire-free Miniscope records raw pixel byte values directly to memory blocks in the SD Card. This means that when the card is mounted in a computer, the computer will think that the card needs to be reformatted. This is due to the SD Card not having a file system on it. Always ignore the recommendation of your computer to reformat the SD Card as well as if it says the SD Card is corrupted.

  1. Mount the SD Card in your computer. If you computer doesn't have a built in SD Card mount, you can use an external USB SD Card mount.
  2. Open the MiniscopeSDCardReader software in with Administrator privileges. You will need this since we will be directly reading/writing memory blocks.
    1. The "Drive" is the name of the SD Card. This defaults to "PhysicalDrive1" but you should double check you are using the correct name of the SD Card drive.
    2. The "Starting Sector" is the memory block where the beginning of the Miniscope recording is located. This should not need to ever be changed from "1024".
    3. Note: Whenever this software attempts to access data on the SD Card, it first checks to make sure the correct 128bit "WRITE KEY" is stored in memory block 1023. This WRITE KEY was placed there by you if you followed the tutorial above. The goal of this WRITE KEY is it makes it extremely unlikely that you end up accessing or modifying any other drive on your computer since the chances of another drive having the 128bit WRITE KEY located at memory block 1023 is highly unlikely. When you do try accessing data on the SD Card, the text box at the bottom of the GUI will tell you if it found the correct WRITE KEY or if it found the wrong one and stopped the requested action.
  3. Now you can use the "Read/Save Data" portion of the software to do exactly that... read and/or save the wire-free Miniscope data.
    1. First enter in the length of the recording you want to extract from the SD Card. This says "Number of Seconds" but I think it is actually "Number of Frames" (I will get around to fixing this sometime soon...). The wire-free Miniscope records at 20FPS so you should usually just set this number a bit longer than the expected recording to make sure you grab all the data.
    2. If you click "Read" the software will open up a window that will play the wire-free Miniscope recording. On some computers using some versions of OpenCV, this option for some reason doesn't actually update the window and it just shows black the whole time. We recommend to use "Save" in all cases if this happens to you.
    3. If you click "Save" the software will display the video as it extracts it from the SD Card and writes it to the computer's drive. It will save a copy of the wire-free recording in the "data" folder located where ever your MiniscopeSDCardReader software is located. We generally recommend you using the "Save" option over the "Read" option since the read option can be buggy on some computers.
  4. Check to make sure the data is now saved as an uncompressed .avi file on your computer.
  5. Once you have your data transferred to your computer we highly recommend clearing the SD Card before beginning a new recording:
    1. You can do this using the "Clear SD Card" section of the software. Here you can define the number of frames to clear from the SD card and then clear/delete them.
    2. Set the number of frames to clear first. We suggest entering a number that is larger than the expected length of recording currently on the SD Card.
    3. Click "Delete" and the software will set all bytes in these memory block in the SD Card to 0.
    4. Note: It will not delete the settings located in memory block 1023. This means you can now reuse this SD Card without reprogramming the gain, LED power, and recording length.
  6. Note: Each frame is timestamped and the timestamp is embedded within each frame. You can extract the timestamp by generating a 32bit integer from the last 8th, 7th, 6th, and 5th pixels in each frame. In MATLAB it would look something like this for a given frame:

footer = (frame(end,(end-7):end)); timestamp = footer(1) + bitshift(footer(2),8) + bitshift(footer(3),16) + bitshift(footer(4),24);

You're Done!