Skip to main content

Python class for serial communication with QuSpin Zero Field Magnetometer

Project description

QuSpin Zero Field Magnetometer DAQ

Read and control QuSpin magnetometer (unofficial)

Uses QZFM commands to send/receive signals via the pySerial module. See also this guide for more info on setup for the QuSpin.

This has been tested on the QuSpin Triaxial sensor.

README Contents


Installation

Install is accomplished with pip:

pip install QZFM

If you wish to install from source, clone this repository then do

cd path/QZFM
pip install -e .

Additional setup for LabJack DAQ

Assumed T7 DAQ device.

  1. Install the LJM software
  2. Install the LJM python package: pip install labjack-ljm

API documentation

Documentation generated with handsdown


Quick Start

from QZFM import QZFM

# connect to sensor
qu = QZFM('Z3T0')

# start
# this will show the laser and temperature lock status
# the command will also zero and calibrate the device
# further execution is blocked until complete
qu.auto_start()

# we are now ready to start taking data
# all front panel lights on the QuSpin electronics box should be green

# display live data from digital output
qu.monitor_data('z')

Note that if you disconnect from the QZFM electronics, the state of the sensor is maintained but the python script won't know the value of the zeroing fields or calibration numbers.


Calibration

From a forum discussion post with QuSpin, dated 2019:

When you press calibrate, a known magnetic field is momentarily applied with the internal coils to calibrate the magnetometer response. The calibration process yields a calibration number which is multiplied with the raw output in a way that scales the analog output to be 2.7 V/nT (in default mode) and the digital output to be represented in pT.

If the calibration number is small <1, then the magnetometer is relatively healthy, but if the displayed number is high (>1), then there is some problem, most likely residual field or the gradient field too high. The calibration number itself is arbitrary and it is capped at 15.9.

The limit for healthy performance is generally a calibration of about 1.5. If the sensor is in a low ambient magnetic field environment, the calibration factor will be lower than if the internal coils need to cancel out a large ambient field. This is usually the most significant source of large calibration values (over 1.5). Sensors can be at optimal performance with a calibration above 1.0 (lower values are generally better), but around 1.5+ the performance is almost certainly not optimal.


Noise Spikes

From a forum discussion post with QuSpin, dated 2019:

The digital and the analog output is derived from the same source, so the FFT from the analog output should look the same digital output. If you see excess spikes on the analog output, something is not right.

Here are some of the sources of spikes that we or other users have experienced in the past.

  1. 77 Hz spike (only seen on the analog output)

    The sinusoidal modulation field on which the QZFM relies for operation is at 923 Hz. After demodulation, we try and filter out residual 923 on the analog output as best as we can, but a tiny bit of 923 Hz modulation signal leaks out on the analog port. If you are sampling the analog output with ADC running at 1kHz (or 500 Hz), then the 1 kHz can alias with 923 Hz producing a 77 Hz spike in the FFT.

    To avoid this problem, we recommend sampling at a minimum of 2 kHz when possible. If sampling at 2 kHz is not an option, we suggest sampling at a frequency slightly higher than 1 kHz (something like 1.1 kHz for example) such that the spike is outside the 0-100 Hz band which is critical for MEG and related applications. 

  2. USB Grounding

    If the USB ground is different from the power supply ground, then ground loops can form which an introduce random and sometimes inconsistent spikes. This is a design oversight at our end and we will try to fix this problem in future electronics but for now, the best option is trying to plug the USB cable elsewhere and see if that helps. If you have found some nice tricks to solve the problem, please post here to benefit the rest of the community. To identify USB cable is a source of the noise spikes, do the following: Run field zeroing and calibration, and after that unplug the USB cable and measure the noise spectrum with analog output. If you see spikes that disappear, then USB ground loop is the source of the problem.


Digital vs Analog Output

From a forum discussion post with QuSpin, dated 2019:

If everything is working the way it should be, there will be no difference in the noise floor/SNR using the two data acquisition methods (in-built digital vs. 16-bit analog DAQ). Visually, it is possible for the two signals to look a little different because the digital data seen over USB has a built-in sixth-order low-pass filter at 100 Hz whereas the analog signal is sampled much faster and thus there is a possibility that a noise spike outside the 100 Hz is picked up the DAQ. One can always add a low pass filter to the analog signals and after that, I expect the signals to look more identical.

In addition, to be positively certain DAQ is working correctly, do the following:

  1. Send ascii command 51 to the sensor under test (after auto-start, field zeroing, and calibration steps). This will turn off internal modulation signals in the sensor and make it insensitive to external magnetic fields. In this mode, it is easier to distinguish external noise from magnetic noise by making the sensor insensitive to the magnetic field.
  2. Now take the FFT with QuSpin user interface. The FFT (power spectral density (psd)) will give you the true noise floor of the sensor in pT/rtHz.
  3. Take the FFT (PSD) of the analog output with 16-bit or higher resolution DAQ.

The FFT noise floor with the two methods should match near perfectly in the DC-100 Hz band. Note: FFT with QuSpin interface is in pT/rtHz units but analog FFT is in V/rtHz units. The analog voltage to field conversion in default mode is 2.7 V/nT. Thus, to match the analog FFT with QuSpin interface units, divide the FFT of the analog output by 2.7 (default analog gain mode) and then multiply the result by 1000 to obtain numbers in the same pT/rtHz units.

  1. Once your tests are completed, you can run field zeroing to make the sensor function normally again.

Debugging Issues

Known issues with connecting to QuSpin:

1. Lacking permissions to access USB device [LINUX]

If your user lacks permissions to read/write from the USB device follow the below:

# check which group can use the USB device
# in the below example, we need to make sure the user is a part of the group "dialout"
$ ls -l /dev | grep USB
crw-rw----   1 root      dialout 188,   0 May 30 18:18 ttyUSB0

# check which users are in the group dialout
$ getent group dialout
dialout:x:20:dfujimoto

# if your user is listed above, then you have a different problem. If not then add your user to the group
$ sudo usermod -a -G dialout yourusername

# then logout to have the changes take effect

2. Cannot find device

If one cannot find the device you can look at the list of available ports and devices using the following python script:

from serial.tools import list_ports

for port in list_ports.comports():
    print(port)

In bash you could also do

lsusb

On linux you should see something like ttyUSB0 listed next to a device which has the QuSpin ID (i.e. something like Z3T0). Update your connection string as needed.

In windows you're likely to see something like COM3 or COM5. Use the relevant COM device as the connection string.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

QZFM-0.4.1.tar.gz (22.1 kB view details)

Uploaded Source

File details

Details for the file QZFM-0.4.1.tar.gz.

File metadata

  • Download URL: QZFM-0.4.1.tar.gz
  • Upload date:
  • Size: 22.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for QZFM-0.4.1.tar.gz
Algorithm Hash digest
SHA256 a78ab808091bd2dc388c849f2582b09934c3c74428063ff82f57ad6809e23d3e
MD5 57fff4e031e262444e67b81b9ea62290
BLAKE2b-256 8ac9c62ebbb55a71ecbef29b9df60e23c2e2e0fa02b1760afeb1018690fd8948

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page