QMC5883L module advice

If doesn't fit into any other category ....
Post Reply
Zim
Posts: 289
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 265 times
Been thanked: 130 times

QMC5883L module advice

Post by Zim »

Hi cicciocb.
I have finally received the QMC5883l modules. I am getting it to read 0 - 360 as a compass from your example code, and found it to be very useable for my project. I only need the heading function as I am simply monitoring the rotated position of a bar magnet. Is there a way to disable the affects of tilt and incline? They drastically effect the heading readings. I also am not concerned with calibration, as I am not monitoring the earth's direction. Can you help to modify the code for heading only? (way above my pay grade)

Thanks
Zim

Code: [Local Link Removed for Guests]

'gauge sensor v1

TM1637.SETUP 15, 16, 100   'display setup

I2C.SETUP 21, 22           'QMC5883 compass
address = &H0D    ' Address of the device QMC5883
ioBuff.dim(0, 6)  ' To save the measurement result
i2c.writeRegByte address, &H0A, &B10000000  ' SOFT_RST
pause 100
i2c.writeRegByte address, &H0B, 1 ' start
pause 100
'i2c.writeRegByte address, &H09, &B00000001 ' 512 samples, 2 gauss, 10Hz, continuous
i2c.writeRegByte address, &H09, &B00010001 ' 512 samples, 8 gauss, 10Hz, continuous


while 1
  i2c.read_ioBuff(0), address, &H00, 6
  
  x = ioBuff.read(0, 0) OR (ioBuff.read(0, 1) << 8)
  if x > 32768 then x = x - 65536
  
  y = ioBuff.read(0, 2) OR (ioBuff.read(0, 3) << 8)
  if y > 32768 then y = y - 65536
  
  z = ioBuff.read(0, 4) OR (ioBuff.read(0, 5) << 8)
  if z > 32768 then z = z - 65536
   
  yaw = atan2(y, x) * 180 / PI
  if yaw < 0 then yaw = 360 + yaw 
 
  wlog cint(yaw);"°"', 
yw = cint(yaw)
  pause 500
TM1637.PRINT str$(yw), 4 'display
wend

end
Post Reply