Has anyone used the GY-26 Digital compass

westaust55

Moderator
A search of the forum found no evidence that anyone has posted about using one. There was a suggestion by hippy to use a GY-26.
A Google search for GY-26 and PICAXE found no sign of anyone using these two items together.

That said, you can consider being the first. There will be folks here to try and help you.
 

17b

New Member
I used a CMPS10 and got it work together with a 08M2 and a 18M2.
The CMPS10 is Tilt compensated, saves a lot of work.
 

hippy

Technical Support
Staff member
Not used it but the GY-26 seems easy enough to read over I2C.

The datasheet is not however very clear on how commands are sent over I2C to tell it to take a new angle reading or to configure it. From setting the declination ( 0x03 + DECL_HIGH, 0x04 + DECL_LOW ) I would take that to mean write DECL_HIGH to address 3, write DECL_LOW to address 4, which is where both would also be read from. I would guess the following -

HI2cOut 0, ( $31 ) - Take a reading
HI2cOut 0, ( $C0 ) - Start calibration
HI2cOut 0, ( $C1 ) - End calibration
HI2cOut 0, ( $A0, $AA, $A5, $C5 ) - Reset factory defaults
HI2cOut 0, ( $A0, $AA, $A5, $xx ) - Set I2C device address
HI2cOut 3, ( $xx ) - Set DECL_HIGH
HI2cOut 4, ( $xx ) - Set DECL_LOW

The Reset Factory Default and Set I2C Device Address, may however be four HI2COUT's to location 0, that is -

HI2cOut 0, ( $A0 )
HI2cOut 0, ( $AA )
HI2cOut 0, ( $A5 )
HI2cOut 0, ( $C5 )

Untested but this should read the angle as it changes ...

Code:
HI2cSetup I2cMASTER, $E0, I2C_SLOW, I2C_BYTE
Do
  HI2cOut 0, ( $31 )
  Pause 10
  HI2cIn 1, ( b1,b0 )
  SerTxd( "Angle=", #w0, CR, LF )
  Pause 1000
Loop
Probably time to start experimenting and see what results you get back. Once you have some results we can probably guess what might be right and wrong and suggest other options to try.
 
Last edited:

Bill.b

Senior Member
Had no luck with I2c. I finished up using serial to read data from the gy-26.

I used a seperate output to initiate the calibration.

the following code was used to test the gy-26, during the configuration time, the gy-26 has to be rotated at least twice.
the results are displayed on a serial 16 x 2 OLED.

Code:
symbol ConfigDelay	    = w2		'Set Compass configure time
symbol configout       = b.2		'Compass configure pulse output
ConfigDelay               = 50000

high configout	' Set Pulse out to High			
pause 6000
pulsout configOut,55000			'500ms pulse to start compass calibration
pause ConfigDelay
pulsout configOut,55000			'500ms pulse to end compass calibration

dspdir:
	serout C.1, t9600,($31)
             pause 10
	serin C.1, t9600, b14, b15, b50, b51, b52, b53, b54, b55  	'Read Compasa data from GY-26
	serout C.0,n2400,(254,128)
	 serout C.0,n2400,("     Heading    " )
	  serout C.0,n2400,(254,192)
	  if b50 = 30 then
	  	serout C.0,n2400,("     ", b51, b52, b53, b54, 210," ")
	  Else
	 	serout C.0,n2400,("    ",b50, b51, b52, b53, b54, 210," ")
	 endif
	 w10 = b50 - 48 * 10 + b51 - 48 * 10 + b52 - 48 
	
	 select case W10
	 	case 0 to 10 
	 		 serout C.0,n2400,("N    ")
	 	case 11 to 32 
	 		 serout C.0,n2400,("NNE  ")
	 	case 33 to 55 
	 		 serout C.0,n2400,("NE   ")
	 	case 56 to 80 
	 		 serout C.0,n2400,("ENE  ")
	 	case 81 to 101 
	 		 serout C.0,n2400,("E    ")
	 	case 102 to 122 
	 		 serout C.0,n2400,("ESE  ")
	 	case 123 to 149 
	 		 serout C.0,n2400,("SE   ")
	 	case 150 to 170 
	 		 serout C.0,n2400,("SSE  ")
	 	case 171 to 190 
	 		 serout C.0,n2400,("S    ")
	 	case 191 to 212  
	 		 serout C.0,n2400,("SSW  ")
	 	case 213 to 235 
	 		 serout C.0,n2400,("SW   ")
	 	case 236 to 258 
	 		 serout C.0,n2400,("WSW  ")
	 	case 259 to 280 
	 		 serout C.0,n2400,("W    ")
	 	case 281 to 302 
	 		 serout C.0,n2400,("WNW  ")
	 	case 303 to 325  
	 		 serout C.0,n2400,("NW   ")
	 	case 336 to 347 
	 		 serout C.0,n2400,("NNW  ")
	 	case 348 to 360 
	 		 serout C.0,n2400,("N    ")
	 	END SELECT
	 		 
	goto dspdir
I have installed the gy-26 in my latest robot car and it is working OK.

Bill
 

ZOR

Senior Member
Hello Bill, sorry to crash in on your thread. You say during configuration the gy-26 had to be rotated twice. I was wondering if it would be any good for my motorised satellite dish. However I cannot rotate twice and only interested in a small deviation between east and west, all satellites being in the south. Does it know where it's pointed to from word go? Thanks
 

westaust55

Moderator
Hello Bill, sorry to crash in on your thread. You say during configuration the gy-26 had to be rotated twice. I was wondering if it would be any good for my motorised satellite dish. However I cannot rotate twice and only interested in a small deviation between east and west, all satellites being in the south. Does it know where it's pointed to from word go? Thanks
Most compass modules and small handheld GPS I have used (eg CMPS03 and Garmin ETrex) require you to rotate to perform an initial calibration. Without calibration the basic modules would likely have no idea on where north is and I suspect the Garmin could be welll of. In fact the Garmin units suggest recalibrate when you change out the batteries.
 
Top