HMC5883L – 3-Osni Digitalni kompas

Proizvodjač: Honeywell
Napon napajanja: 2.16...3.6 V
Izlazni signal: I2C interface
Opseg merenja: X & Y & Z osa -8...+8 gauss
Rezolucija merenja: 2 milli-gauss
Tačnost merenja: ±1° za kompas
Period merenja: 6 ms


Software in Assembler for PIC16F876, rutina se poziva kod starta 
;---------------------------------------------------------------------
; Inicijalizacija HCM5883L
Init_HCM5883L
	i2c_start
	movlw	0x3C		;Module address WR (0x1E)
	call	i2c_send

	movlw	0x00		;address 0x00
	call	i2c_send
 
	movlw	0x70		;8-average, 15 Hz default, normal measurement
	call	i2c_send

	movlw	0xA0		;Gain=5 (440 LSb/Gauss)
	call	i2c_send

	movlw	0x00		;Continuous-measurement mode
	call	i2c_send

	i2c_stop
	return
;---------------------------------------------------------------------

Software in Assembler for PIC16F876, rutina se poziva svake sekunde
;---------------------------------------------------------------------
; Citaj podatke iz HCM5883L - Pravac vetra
HCM5883L
	i2c_restart
	movlw	0x3D		;Module address RD (0x1E)
	call	i2c_send

;- - - - - - - - - - - - - - - - - - - - - - - -
	i2c_receive
	i2c_send_ACK
	movf	SSPBUF,W	;uzmi podatak 1
	movwf	WX_H

	i2c_receive
	i2c_send_ACK
	movf	SSPBUF,W	;uzmi podatak 2
	movwf	WX_L

	i2c_receive
	i2c_send_ACK
	movf	SSPBUF,W	;uzmi podatak 3
	movwf	WZ_H

	i2c_receive
	i2c_send_ACK
	movf	SSPBUF,W	;uzmi podatak 4
	movwf	WZ_L

	i2c_receive
	i2c_send_ACK
	movf	SSPBUF,W	;uzmi podatak 5
	movwf	WY_H

	i2c_receive
	i2c_send_NACK
	movf	SSPBUF,W	;uzmi podatak 6
	movwf	WY_L

	i2c_stop

;- - - - - - - - - - - - - - - - - - - - - - - -
	i2c_restart
	movlw	0x3C		;Module address WR (0x1E)
	call	i2c_send

	movlw	0x03		;point to first data register 0x03
	call	i2c_send

	i2c_stop
	return
;---------------------------------------------------------------------

Download File:
  • hmc5883.py - Python software za testiranje HMC5883
  • Šema RPI WS
  • Šema PIC WS
  • Data Sheet - HMC5883L.pdf


  • Pravac vetra

    Senzor: HMC5883L
    Izlazni signal: I2C interface
    Tačnost merenja: ±1°
    Izradjen je od metala, moguće je dodati grejače za rad na niskim temperaturama.

    Software in C++ for Raspberry Pi
    //****************************************************************************
    // Calculate values – Wind Direction – Pravac vetra
    //****************************************************************************
    #define wdeg_offset 0 	// offset = -180...+180
    ...
    // ----- Smer vetra (deg)
    		wx = hex_val2(buf[52],buf[53],buf[54],buf[55]);
    		wy = hex_val2(buf[56],buf[57],buf[58],buf[59]);
    		printf("(X=%d Y=%d) ",wx,wy);
    		// Offset racun
    		if(wx > xmax) { xmax = wx; }
    		if(wx < xmin) { xmin = wx; }
    		if(wy > ymax) { ymax = wy; }
    		if(wy < ymin) { ymin = wy; }
    		xoff = (xmax + xmin)/2;
    		yoff = (ymax + ymin)/2;
    		xo = wx - xoff;
    		yo = wy - yoff;
    		// Gain racun
    		xd = (xmax - xmin);
    		yd = (ymax - ymin);
    		if(xd > yd) { xgain = 1000; ygain =  (xd * 1000) / yd ; }
    		else { xgain =  (yd *1000) / xd ; ygain =1000; }
    		xo = (xo * xgain) / 1000;
    		yo = (yo * ygain) / 1000;
    		wdeg = atan_fast(xo,yo);	// X osa pokazuje SEVER
    		// Deg offset racun
    		wdeg = wdeg + wdeg_offset;
    		if(wdeg >= 360) wdeg = wdeg -360;
    		if(wdeg < 0) wdeg = wdeg + 360;
    		printf("Wd=%3d' ",wdeg);
    ...
    //----------------------------------------------------------------------
    unsigned int atan_fast(signed int y, signed int x)
    {
    	unsigned char negflag, tempdegree, comp;
    	unsigned int degree, ux, uy;
    	negflag=0;
    	if (x<0)
    	{
    		negflag+=0x01;
    		x=(0-x);
    	}
    	ux=x;
    	if (y<0)
    	{
    		negflag+=0x02;
    		y=(0-y);
    	}
    	uy=y;
    	if (ux>uy)
    	{
    		degree=(uy*45)/ux;
    		negflag+=0x10;
    	}
    	else
    	{
    		degree=(ux*45)/uy;
    	}
    	comp=0;
    	tempdegree=degree;
    	if(tempdegree > 22)
    	{
    		if(tempdegree <= 44) comp++;
    		if(tempdegree <= 41) comp++;
    		if(tempdegree <= 37) comp++;
    		if(tempdegree <= 32) comp++;
    	}
    	else
    	{
    		if(tempdegree >= 2) comp++;
    		if(tempdegree >= 6) comp++;
    		if(tempdegree >= 10) comp++;
    		if(tempdegree >= 15) comp++;
    	}
    	degree += comp;
    
    	if(negflag & 0x10) degree = (90-degree);
    	if(negflag & 0x02)
    	{
    		if(negflag & 0x01)
    			degree = (180 + degree);
    		else
    			degree = (180 - degree);
    	}
    	else
    	{
    		if(negflag & 0x01)
    			degree = (360 - degree);
    	}
    	return (degree);
    }
    //----------------------------------------------------------------------
    

    Pravac vetra - low cost sensor

    Senzor: 8 x Reed relay
    Izlazni signal: Analogni
    Tacnost merenja: 360/16 = 22.5°
    Izradjen je od plastike.


    Link: www.philpot.me/weatherinsider.html

    Download File:
  • Šema RPi WS
  • Šema PIC WS