Hi George
This is the exact one I am using ... The ebay link has Pics and Circuit... I am running it at 5v.. As the LCD needs 5v
http://www.ebay.co.uk/itm/1112141408...%3AMEBIDX%3AIT
BR
Andy
Hi George
This is the exact one I am using ... The ebay link has Pics and Circuit... I am running it at 5v.. As the LCD needs 5v
http://www.ebay.co.uk/itm/1112141408...%3AMEBIDX%3AIT
BR
Andy
So you are connecting the clock and data from the PIC directly to the break-out board pins? Do you have pull-ups? if so to 5 or 3.3?
george
Hi George
I wondered about this
I have measured 2K2 to the 5v rail on the breakout board.
The Ic2 link seems to run OK so happy with that.
My issue remains to be the conversion from radians to degrees.
I bought one to play with
after looking at the raw data I came up with this , works ok if device is held level , tilt compensation is elusive at this stage
Code:'**************************************************************** '* Name : hmc5883l.BAS * '* Author : [select VIEW...EDITOR OPTIONS] * '* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] * '* : All Rights Reserved * '* Date : 29/04/2011 * '* Version : * '* Notes : * '* : 12f1822 '* : ' '**************************************************************** #CONFIG cfg1 = _FOSC_INTOSC cfg1&= _WDTE_ON cfg1&= _PWRTE_OFF cfg1&= _MCLRE_ON cfg1&= _CP_OFF cfg1&= _CPD_OFF cfg1&= _BOREN_ON cfg1&= _CLKOUTEN_OFF cfg1&= _IESO_ON cfg1&= _FCMEN_ON __CONFIG _CONFIG1, cfg1 cfg2 = _WRT_OFF cfg2&= _PLLEN_OFF cfg2&= _STVREN_ON cfg2&= _BORV_19 cfg2&= _LVP_OFF __CONFIG _CONFIG2, cfg2 #ENDCONFIG osccon=$6A '4 mhz anselA=0 'dig i/o trisA=1110 pause 2000 serout2 porta.0,84, ["ready",13,10] lata.0=1 SDA var porta.2 'transceives to/from SDA SCL var porta.4 'sends clock pulses WRITE_DATA CON $3C 'Used to perform a Write operation READ_DATA CON $3D 'Used to perform a Read operation MODE CON $02 'Read/Write Register, Selects the operating mode. Default = Single measurement 'Send $3C $02 $00 on power up to change to continuous measurement mode. X_MSB CON $03 'Read Register, Output of X MSB 8-bit value. X_LSB CON $04 'Read Register, Output of X LSB 8-bit value. Z_MSB CON $05 'Read Register, Output of Z MSB 8-bit value. Z_LSB CON $06 'Read Register, Output of Z LSB 8-bit value. Y_MSB CON $07 'Read Register, Output of Y MSB 8-bit value. Y_LSB CON $08 'Read Register, Output of Y LSB 8-bit value. Cont_Mode CON $0 X VAR byte 'x sensor measured value Y VAR byte 'y sensor measured value Z VAR byte 'z sensor measured value READX VAR WORD READY VAR WORD READZ VAR WORD brads VAR Word 'angle in brads degr VAR Word 'angle in degrees Radians VAR Word 'value calculated using X ATN -Y ' -----[ Main Routine ]------------------------------------------------------- PAUSE 50 ' Give sensor needed power up time I2CWRITE SDA,SCL,WRITE_DATA,MODE,[0,1,Cont_Mode] ' Send continuous output command PAUSE 10 DO GOSUB GetRawReading ' Get RAW Compass reading serout2 porta.0,84, ["x ",SDEC x," y ",SDEC y ," z ",SDEC z,13,10] brads = -x ATN -y ; degr = brads */360 'convert to degrees ;serout2 porta.0,84, ["xy ",SDEC Radians ,","] serout2 porta.0,84, ["xy ",DEC degr ,13,10] brads = -x ATN -z ; degr = brads */360 'convert to degrees ; serout2 porta.0,84, ["xz ",SDEC Radians ,","] serout2 porta.0,84, ["xz ",DEC degr ,13,10] brads = -y ATN -z degr = brads */360 'convert to degrees ;serout2 porta.0,84, ["yz ",SDEC Radians ,","] serout2 porta.0,84, ["yz ",DEC degr ,13,10] PAUSE 2000 LOOP ' -----[ Subroutines ]-------------------------------------------------------- GetRawReading: 'Compass module subroutine 'Wait for new data to become available I2CREAD SDA,SCL,READ_DATA, X_MSB,[READX,READZ,READY] 'Read the data starting at x_msb 3 x = readx >>2 Y = readY >>2 Z = readZ >>2 RETURN
Hi Richard
Had put this on the back burner for a whilst....
Will revisit it later... I see you have done a few things differently!
Thank you for Ideas. Andy
Last edited by andybarrett1; - 22nd January 2015 at 11:17. Reason: typo
Hi Richard,
you need to add a 3-axis accelerometer to do tilt compensation, something like LSM303DLM.
George
turns out that the premise of using this chip alone as a compass is basically flawed. it can't do its own tilt compensation because the earths magnetic field is not necessarily parallel to the earth .
as George says an accelerometer needs to be added to compensate for tilt. (read, complicated math probably needs floats for any decent accuracy)
no wonder they are so cheap , not a total loss it makes a pretty sensitive 3 axis hall effect sensor , nice colour
Richard,
Not if your application will not be required to tilt or has some mechanical (gimbals) way to negate the problem.
George
Hi both
Yeah.... I put your code in Richard ... Does pretty much same as before... So I think I need find a better chip
Or use a real needle
Thank you again for ideas .... Appreciated !
So according to your code , we get x , y , z raw readings as byte datas .... and xy xz yz calculations obtained using some trigonometry .. But what do those datas mean ? I think these xy xz yz readings are referring a direction but which one is what ? Does xy give me the magnetic north ? or is it xz or maybe yz ...
I'd be so happy if any of you guys could help me with that ...
Thanks ..
maybe this will help
http://www.starlino.com/imu_guide.html
I still can't understand which vector shows me the magnetic north in this picture ... But as far as I read the datasheet of this IC , it mentions about a term called Hnorth which is the resultant force of X and Y vectors ... so which one is it then ? Is it XY calculation that shows me the north ?
if the device is held so that the xy plane is perfectly!!!! level then the xy angle is magnetic north (sort of). if the device is tilted then the xy angle needs to compensated for that tilt . the device alone cannot really be used as a compass . the device output is a 3d vector as drawn by the black line in my previous post, as you can see the result is relative to the devices orientation , if that is unknown (and it is without an external reference ) then its virtually impossible to ascertain a direction from its output. even a small tilt creates substantial error.
furthermore magnetic field lines are not parallel with the earths surface they tilt into the earth or up to the sky depending on location. not to mention magnetic inclination/deviation etc
basically the concept of using this chip as a compass is unworkable see post 47
Last edited by richard; - 3rd February 2015 at 11:57. Reason: typo
I must add , the vector does not point north . it indicates the [ direction and magnitude ] of the magnet field relative to the device orientation.
the link I posted is for accelerometers but the math is the same . the big difference is that gravity always points to the centre of the planet so orientation can be established
Last edited by richard; - 3rd February 2015 at 12:13.
That was a nice a explanation Richard ... As you've previously said , we can at least use this IC to observe the pitch then ... For example I'm intending to read XZ or YZ to see the pitch angle for the control of an inverted pendulum ... I personally thought it's a low cost way of doing it compared to an encoder ... Bye the way .. For my module , should I keep it horizontally flat just like in the picture or upside down , does it matter ?
Here is my module
not sure how effective that will be , it would probably need to be calibrated every time you relocate it (or maybe even rotate it) . don't forget its own orientation is its only reference point . an accelerometer might be more appropriateFor example I'm intending to read XZ or YZ to see the pitch angle for the control of an inverted pendulum ... I personally thought it's a low cost way of doing it compared to an encoder
Well , Yeah actually I'm planning to calibrate it right before every operation with a quick push button click ... So that It can assume the present values as exact zero .. It's all about math I guess .... I'm also aware of that It won't be that accurate ... But I still wanna use it ... Thanks for your all prompt answers Richard ...
Surely what you need is an accelerometer, you know that the period is always the same, it just moves faster when first set in motion (I'm not totally sure that's correct, my knowledge of basic physics is pretty ragged). If that's correct, there will be a relationship between angle and acceleration. With calibration you should end up with a look up table of acceleration/angle. Of course you'll only need to generate the table once.For example I'm intending to read XZ or YZ to see the pitch angle for the control of an inverted pendulum ... I personally thought it's a low cost way of doing it compared to an encoder
Also I cant imagine how you would orient the magnetometer to even hint at the angle.
BTW anyway, you couldn't use an encoder if you want the pendulum to be "true", pivot must be frictionless.
Sounds like an interesting project, have fun.
George
Bookmarks