- 1 Overview
- 2 Tutorial on setting up a new wire-free Miniscope
- 2.1 1) First we need to make sure we have all the components and software to get things up and running.
- 2.2 2) Now we need to get the wire-free CMOS PCB ready to be programmed with the wire-free Miniscope firmware.
- 2.3 3) Programming the wire-free CMOS PCB
- 2.4 4) Configure the micro SD card
- 2.5 5) Using the Miniscope SD Card Reader software
- 2.6 6) Modifying the Lipo charger
- 3 How to record 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.
General information, notes, and troubleshooting
- 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 <firstname.lastname@example.org> or elsewhere. The design file and dimensions are in the "wire-free focus slider" folder in our github repository.
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.
- Wire-free Miniscope CMOS PCB: You will also need the wire-free CMOS PCB. You can order this PCB already programmed and tested along with all the supporting equipment (batteries, connectors, chargers, SD Cards) from Filipe Carvalho <email@example.com>. 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.
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 <firstname.lastname@example.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:
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:
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.
- 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.
- 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
- 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.
- 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").
- 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.
- 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:
- 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
- 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.
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.
- 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:
footer = (frame(end,(end-7):end)); timestamp = footer(1) + bitshift(footer(2),8) + bitshift(footer(3),16) + bitshift(footer(4),24);