Code, hardware, and data for the paper "Low-Cost Transcranial Magnetic Stimulation" (PREPRINT, SUBJECT TO CHANGES), (2026).
This repository contains the design and validation materials for a low-cost monophasic transcranial magnetic stimulation (TMS) stimulator. As of July 2027, the bill of materials (BOM) runs at USD 657.34. The repository includes the electrical design, controller firmware, and terminal control interface, fabrication files, LTspice simulations, raw magnetic-field measurements, and analysis code to characterize the system.
Caution
This system contains a high-energy capacitor bank and generates high voltages and strong, rapidly changing magnetic fields. Contact with the system can cause severe injury or death, and stored energy can remain after charging is halted. Never rely on the computer interface or firmware as the primary safety mechanism. Work must be performed by trained personnel. Do not connect this research prototype to a person or animal.
If you use this code, hardware, or data in your research, please cite the following paper:
Low-Cost Monophasic Transcranial Magnetic Stimulator Maxence Lapatrie, Yuzuha Isetani, Jathav Puvirajan, Antonella Catanzaro, Siqi Lyu, Han C. Nguyen, William Mathieu, Milica Popovich. bioRxiv 2026.02.10.705127; doi: https://doi.org/10.64898/2026.02.10.705127
@article{lapatrie_monophasic_2026,
title = {Low-Cost Monophasic Transcranial Magnetic Stimulator},
author = {Lapatrie, Maxence and Isetani, Yuzuha and Puvirajan, Jathav and Catanzaro, Antonella and Lyu, Siqi and Nguyen, Han C. and Mathieu, William and Popovich, Milica},
year = {2026},
month = {aug},
journal = {bioRxiv},
publisher = {Cold Spring Harbor Laboratory},
doi = {10.64898/2026.02.10.705127},
url = {[https://doi.org/10.64898/2026.02.10.705127](https://doi.org/10.64898/2026.02.10.705127)}
}I welcome any feedback on the paper or repository. If you have questions or require help running the code, please do not hesitate to contact me.
Email me at maxence (dot) lapatrie (at) mail (dot) mcgill (dot) ca.
Or message me on LinkedIn maxence-lapatrie.
The design separates the build into three voltage domains: control domain, power domain, and high voltage domain. The domains are isolated from each other. The Arduino lives in the control domain and sends signals to the other two domains to control charging and discharging.
See the complete schematic for a more detailed understanding of the circuit.
| Path | Contents |
|---|---|
2d_models/ |
FreeCAD, SVG, PDF, and PNG fabrication drawings for the coil windings and busbars |
3d_models/ |
FreeCAD sources and printable STL files for the coil winder and pickup coil helpers |
controller_arduino/ |
Arduino UNO R4 Minima firmware and the Python terminal user interface |
data_processing/ |
Raw oscilloscope captures, acquisition scripts, data analysis notebooks, SimNIBS helpers, and generated figures |
figures/ |
Build, software-interface, and validation figures used in this README |
schematics/ |
KiCad project, hierarchical schematics, and a three-page PDF export |
simulations/ |
LTspice models for the charger, discharge path, gate driver, and IL300 linear optocoupler |
Safety_Checklists.pdf |
Project-specific inspection, pre-charge, and de-energization checklists |
TMS_field_grid.pdf |
Coordinate grids used for magnetic-field measurements |
requirements.txt |
Pinned Python analysis environment |
Editable source files are included wherever possible. The PDF, SVG, STL, and PNG files are provided for convenience.
Python 3.10 or newer is recommended.
git clone <REPOSITORY_URL>
cd <REPOSITORY_DIRECTORY>
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txtAdditional dependencies not included above:
- SimNIBS 4.6 is required by
data_processing/create_simple_figure_of_8_coil.pyanddata_processing/plot_simnibs.py. Run these scripts in the Python environment supplied with the SimNIBS installation. - KiCad, LTspice, and FreeCAD are recommended if one desires to edit the design files.
Compile and upload controller_arduino.ino to an Arduino UNO R4 Minima. Before compiling, review the pin assignments and calibrate the following firmware constants against the assembled measurement and gate-driver circuits:
MAX_ADC: capacitor-bank overvoltage threshold in ADC counts;FIRE_DELAY_US: delay used to obtain the required SCR gate-pulse width;COMP_STOP_ACTIVE: active level of the independent comparator trip.
MAX_ADC must be calculated from measured values:
MAX_ADC = round((V_trip / divider_ratio) / V_ref * ADC_FULL_SCALE)
The values committed in the firmware and terminal interface document the tested configuration; they are not universal safe defaults. The DEFAULT_MAX_ADC value in app.py must match the firmware MAX_ADC, and the divider ratio shown by the interface must match the physical divider tap in use.
cd controller_arduino
python app.py --divider <MEASURED_DIVIDER_RATIO> \
--vref <MEASURED_ADC_REFERENCE_V> \
--max-adc <FIRMWARE_MAX_ADC>Press p in the interface to select a port.
| Key | Command |
|---|---|
r |
Reset the controller state after all hardware trips are clear |
c |
Start or stop charging |
a |
Arm or unarm the discharge; arming also stops charging |
f |
Request one firing pulse while armed |
s |
Query controller status |
p |
Select a serial port |
d |
Disconnect |
q |
Quit |
The data used in our analyses is provided under data_processing/waveforms. The MagVenture* components correspond to the data collected from the MRI-B91 MagVenture coil with the MagVenture MagPro X100 TMS. The other components correspond to the homemade coil under 24V and 1480V capacitor charges.
collect_grid.py automates oscilloscope captures at each location of a pre-programmed field-measurement grid. Before use:
- Replace the VISA resource string with the identifier reported for the oscilloscope;
- Select the measured field component;
- Set
start_rowandstart_colif resuming an interrupted acquisition; and - Confirm the oscilloscope channel, vertical scale, offset, sample rate, and binary-waveform format.
Each capture is stored as a CSV file with Time (s) and Voltage (V) columns.
Use TMS_field_grid.pdf to help position your pickup coil.
- Loads capacitor and three-axis pickup-coil waveforms;
- Filters and maps the measured peak voltages;
- Converts the measurements to empirical dB/dt maps;
- Computes corresponding maps from a discretized figure-of-eight coil model; and
- Estimates coil dI/dt by a global least-squares fit.
Change user_local_dir at the beginning of the notebook before running it. Select homemade_coil and low_voltage to match the dataset being analyzed.
plot_gate_pulses.ipynbcompares the microcontroller and gate-resistor pulses and estimates the gate-current rise rate. It expects local files underwaveforms/gate_component/.create_fo8_coil.pycreates the line-segment TMS coil model used by SimNIBS.
The repository includes raw low-voltage, high-voltage, and commercial-coil reference measurements. The figure below compares the measured and wire-segment-model dB/dt maps and shows the global least-squares fits used to estimate coil dI/dt at low and high capacitor-bank voltages:
Read Safety_Checklists.pdf before inspecting or operating the physical system. These checklists document the procedures used for this prototype, but they are not a substitute for a complete, site-specific risk assessment or formal training.
The controller source files, data analysis code, and data collection code are licensed under the MIT SPDX license. The SimNIBS-derived coil-generation example retains its GPLv3 notice. All hardware files are licensed under the CERN-OHL-P-2.0 license. Project-authored data, figures, and documentation are licensed under the CC-BY-4.0 license. Read LICENSE for more information.