An advanced monitoring system for DRV425 magnetic field sensors (or similar) connected to Raspberry Pi via SPI ADC.
# Install Python dependencies sudo apt-get update sudo apt-get install python3-spidev python3-pandas python3-matplotlib # Or using pip pip3 install spidev pandas matplotlib # Enable SPI on Raspberry Pi sudo raspi-config # Navigate to: Interface Options -> SPI -> Enable
# Make executable chmod +x magnetic_field_monitor.py # Run monitoring (Ctrl+C to stop) python3 magnetic_field_monitor.py
Output example:
â•”â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•—
â•‘ REMARKABLE MAGNETIC FIELD MONITOR - DRV425 â•‘
╚â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
📊 Logging to: mag_log_20260202_143022.csv
🔠Calibrating baseline...
✓ Baseline established: 1.650V
Press Ctrl+C to stop monitoring
──────────────────────────────────────────────────────────────────
â±ï¸ 14:30:45 | Raw: 512 | V: 1.653V | ΔV: +0.003V | ████████████████████████████░░░░░░░░░░
# Static analysis (generates PNG and displays plots) python3 visualize_data.py mag_log_20260202_143022.csv # Live updating plot (while monitoring is running) python3 visualize_data.py mag_log_20260202_143022.csv live
Edit these variables in magnetic_field_monitor.py:
SAMPLE_RATE = 0.1 # Seconds between readings V_REF = 3.3 # Reference voltage (Pi Zero = 3.3V) ADC_MAX = 1023.0 # 10-bit ADC max value HISTORY_SIZE = 100 # Rolling window size ANOMALY_THRESHOLD = 2.5 # Std deviations for anomaly
MCP3008 -> Raspberry Pi
VDD -> 3.3V (Pin 1)
VREF -> 3.3V (Pin 1)
AGND -> GND (Pin 6)
DGND -> GND (Pin 6)
CLK -> SCLK (Pin 23 / GPIO 11)
DOUT -> MISO (Pin 21 / GPIO 9)
DIN -> MOSI (Pin 19 / GPIO 10)
CS/SHDN -> CE0 (Pin 24 / GPIO 8)
DRV425 -> MCP3008
VOUT -> CH0 (Pin 1)
GND -> AGND
Watch for sudden voltage spikes when metal passes near the sensor.
DRV425 can measure current flow by detecting the magnetic field around a wire.
Map Earth's magnetic field variations.
No readings / stuck at 0:
lsmod | grep spiNoisy readings:
SAMPLE_RATE for averagingPermission errors:
sudo usermod -a -G spi $USERtimestamp,raw_value,voltage,delta_v,anomaly 2026-02-02T14:30:22.123456,512,1.650000,0.000000,False 2026-02-02T14:30:22.223456,515,1.660000,0.010000,False 2026-02-02T14:30:22.323456,580,1.870000,0.220000,True
Modify the detect_anomaly() method to implement your own detection algorithm.
CSV files can be imported into Excel, MATLAB, or Python for further analysis.
Add network logging or webhook notifications when anomalies are detected.
You now have a professional-grade magnetic field monitoring system. Go detect some magnetic phenomena! 🧲✨