(Using a Raspberry Pi 3 Model B+ and python)
I'm a newbie especially for data processing. The information provided in the datasheet is a problem to me. I've spent last 7 days trying to understand it with nothing solid to work with. The sample code from the product page works very well and gives intended output. So far I've been just able to change just GAIN_SEL property because it's already in the sample code and has a variable for it to be changed and done a lot of trial and errors with non-sensible output. I know Bitwise conversions and I've worked with them before but I can't understand how exactly the host specifies the address register and the values for it in reference to the memory map. I've gone through all of the tutorials on Sparkfun and Adafruit and some other websites to understand I2C again. I know how I2C works about sending bytes and waiting for the responses and then reading data blocks but I simply don't know how to configure the sensor. (For example, how am I supposed to set DIG_FILT (digital property)?, How do I start it in burst mode?)
It really seems like a stupid question to me as well but I just don't know what I'm doing wrong.
If you guys can help me understand it or point me to link which will be useful that'll be great!
Here is the sample code for your reference :
# Distributed with a free-will license. # Use it any way you want, profit or free, provided it fits in the licenses of its associated works. # MLX90393 # This code is designed to work with the MLX90393_I2CS I2C Mini Module available from ControlEverything.com. # https://www.controleverything.com/products import smbus import time # Get I2C bus bus = smbus.SMBus(1) while True: # MLX90393 address, 0x0C(12) # Select write register command, 0x60(96) # AH = 0x00, AL = 0x5C, GAIN_SEL = 5, Address register (0x00 << 2) config = [0x00, 0x5C, 0x07] bus.write_i2c_block_data(0x0C, 0x60, config) # Read data back, 1 byte # Status byte data = bus.read_byte(0x0C) # MLX90393 address, 0x0C(12) # Select write register command, 0x60(96) # AH = 0x02, AL = 0xB4, RES for magnetic measurement = 0, Address register (0x02 << 2) config = [0x02, 0xB4, 0x08] bus.write_i2c_block_data(0x0C, 0x60, config) # Read data back, 1 byte # Status byte data = bus.read_byte(0x0C) #FROM HERE # MLX90393 address, 0x0C(12) # Start single meaurement mode, X, Y, Z-Axis enabled bus.write_byte(0x0C, 0x3E) # Read data back, 1 byte # Status byte data = bus.read_byte(0x0C) time.sleep(0.096) # MLX90393 address, 0x0C(12) # Read data back from 0x4E(78), 7 bytes # Status, xMag msb, xMag lsb, yMag msb, yMag lsb, zMag msb, zMag lsb data = bus.read_i2c_block_data(0x0C, 0x4E, 7) # Convert the data xMag = data * 256 + data # if xMag > 32767 : # xMag -= 65536 yMag = data * 256 + data # if yMag > 32767 : # yMag -= 65536 zMag = data * 256 + data # if zMag > 32767 : # zMag -= 65536 # Output data to screen print "Magnetic Field in X-Axis : %d" %xMag print "Magnetic Field in Y-Axis : %d" %yMag print "Magnetic Field in Z-Axis : %d" %zMag