The title sounds ever so techno-geek but in essence it is a single board device which can detect the Earth’s Magnetic Fields and outputs data over I2C ports.
I have found some scratch code for an Arduino project, but frankly that stuff turns me off big style.
Has anyone had any experience with this device or more some GCB (PROPER) scratch code with which I can get cracking with? Any help would be appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
void setup(){
//Initialize Serial and I2C communications
Serial.begin(9600);
Wire.begin();
//Put the HMC5883 IC into the correct operating mode
Wire.beginTransmission(address); //open communication with HMC5883
Wire.send(0x02); //select mode register
Wire.send(0x00); //continuous measurement mode
Wire.endTransmission();
}
void loop(){
int x,y,z; //triple axis data
//Tell the HMC5883 where to begin reading data
Wire.beginTransmission(address);
Wire.send(0x03); //select register 3, X MSB register
Wire.endTransmission();
//Read data from each axis, 2 registers per axis
Wire.requestFrom(address, 6);
if(6<=Wire.available()){
x = Wire.receive()<<8; //X msb
x |= Wire.receive(); //X lsb
z = Wire.receive()<<8; //Z msb
z |= Wire.receive(); //Z lsb
y = Wire.receive()<<8; //Y msb
y |= Wire.receive(); //Y lsb
}
//Print out values of each axis
Serial.print("x: ");
Serial.print(x);
Serial.print(" y: ");
Serial.print(y);
Serial.print(" z: ");
Serial.println(z);
delay(250);
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here goes. A new hardware file for you. Be patient - it may take one or two posting to sort.
You have to new functions.
Init_HMC5883L and Read_HMC5883L ( device_x, device_y, device_z ). Init initialises the device and the other reads the device.
I have attached a ZIP with the files you need. You will need to edit chip, ports etc. Edit the GCB file, set up a terminal to show you the results.
How to use these files: 1) replace your existing I2C.H with the zip file version in INCLUDE\LOWLEVEL, 2) add then put the two .h files in INCLUDE, 3) then put the GCB where ever your wish. Edit the GCB to reflect your file structure - YOU NEED to edit the INCLUDE statements.
rather I would like to know how to convert the values read and convert to degrees(the readings are in radians).
the formula should be:
Degrees=arctan(Y,X)*(180/3.1416)
exists in a gcbasic arctan?
Last edit: alejandro1957 2014-03-18
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The ATAN function in Gambas says that is the inverse of TAN.
TAN that uses only one value (X or Y).
hand at work, let's see what comes out with Google and mathematical functions.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
appears on the monitor:
X=N;Y=O
X=0 121
Y=255 248
Z=255 80
X=O;Y=S
X=0 58
Y=255 137
Z=255 80
X=S;Y=E
X=255 200
Y=255 210
Z=255 80
X=E;Y=N
X=0 9
Y=0 67
Z=255 82
Anobium,in each case the values are always positive, no negative sign.
thing that is not good.
the minus sign on one of these values indicates the Cartesian position.
the programe works and the pic with the HMC5883L converse well.
even with a program that self-test (datasheet shows how) it works and I have seen that the optimal value for the module is 0xC0 (0x01 0xC0 0x3C -> ± 5.6Ga).
what's wrong????
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
(1)This value is negative.
if the 15th bit of the word is equal to 1(0=positive,1=negative),are negative.
all values than 0x7FFF(mean value between Vmax=0xF800 and Vmin=0x7FF)have the 15th bit to 0 (0111111111111111),then positive.
otherwise,greater than 0x8000(0x7FFF+1) is 1(1000000000000000),then negative.
I forgot, if I send the measured values without creating a 16-bit word, the values are these:
X_Tmp(0)=000
X_Tmp(1)=111
Z_Tmp(0)=255
Z_Tmp(1)=74
Y_Tmp(0)=000
Y_Tmp(1)=84
only the value of Z (0) moved to the left of 8 places is equal to 0xFF00(1111111100000000-16th bit to 1, so it is a negative value).
then,65354-65280(0xFF00) is equal to 74.that is -74(a negative value).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anobium sorry,but maybe you did not see the attached code?
when I saw you posted with the tag like this:
EjeZ=(Z_Tmp(0)256)
but it was already in the code like this:
EjeZ=(Z_Tmp(0)*256)
has the same value to move 8 places left.
Last edit: alejandro1957 2014-04-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Advice. Write code long hand. Do not try to have arrays handled and multiplied on the same line. We are trying to figure out a bug that may be related to this.
is a bit rudimentary, but it will.
The decline is 0.3333(Naples, Italy)allows me to correct the drift with the geographic pole +- well.
error 0° to 360° i will try to correct it using values instead of Long to Float (which is an integer and maybe harm the calculation radians to Ang (X, Y)).
Last edit: alejandro1957 2014-05-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
it works fine.
it was enough to change the configuration for the module in this way and reads the position at the time a grade from 0° to 359°:
0x3C 0x00 0x70 (8 samples, 15Hz, reading normal mode)
0x3C 0x01 0x40 (+-1.9Ga)
do
0x3C 0x02 0x01 (single read, no read more)
WAIT 5 ms (not less than)
Read function
WAIT 25 ms (not less than)
Code of administration involving the user prefers
WAIT 67 ms (not less than)
loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The title sounds ever so techno-geek but in essence it is a single board device which can detect the Earth’s Magnetic Fields and outputs data over I2C ports.
I have found some scratch code for an Arduino project, but frankly that stuff turns me off big style.
Has anyone had any experience with this device or more some GCB (PROPER) scratch code with which I can get cracking with? Any help would be appreciated.
I do not have the code, but, post the code you have and we can convert.
:-)
Here is the "HardDoneTo" (Arduino) Code I have dug up off the web. As I said before this stuff turns me clay cold....
#include <Wire.h> //I2C Arduino Library
#define address 0x1E //0011110b, I2C 7bit address of HMC5883
void setup(){
//Initialize Serial and I2C communications
Serial.begin(9600);
Wire.begin();
//Put the HMC5883 IC into the correct operating mode
Wire.beginTransmission(address); //open communication with HMC5883
Wire.send(0x02); //select mode register
Wire.send(0x00); //continuous measurement mode
Wire.endTransmission();
}
void loop(){
int x,y,z; //triple axis data
//Tell the HMC5883 where to begin reading data
Wire.beginTransmission(address);
Wire.send(0x03); //select register 3, X MSB register
Wire.endTransmission();
//Read data from each axis, 2 registers per axis
Wire.requestFrom(address, 6);
if(6<=Wire.available()){
x = Wire.receive()<<8; //X msb
x |= Wire.receive(); //X lsb
z = Wire.receive()<<8; //Z msb
z |= Wire.receive(); //Z lsb
y = Wire.receive()<<8; //Y msb
y |= Wire.receive(); //Y lsb
}
//Print out values of each axis
Serial.print("x: ");
Serial.print(x);
Serial.print(" y: ");
Serial.print(y);
Serial.print(" z: ");
Serial.println(z);
delay(250);
}
Here goes. A new hardware file for you. Be patient - it may take one or two posting to sort.
You have to new functions.
Init_HMC5883L and Read_HMC5883L ( device_x, device_y, device_z ). Init initialises the device and the other reads the device.
I have attached a ZIP with the files you need. You will need to edit chip, ports etc. Edit the GCB file, set up a terminal to show you the results.
How to use these files: 1) replace your existing I2C.H with the zip file version in INCLUDE\LOWLEVEL, 2) add then put the two .h files in INCLUDE, 3) then put the GCB where ever your wish. Edit the GCB to reflect your file structure - YOU NEED to edit the INCLUDE statements.
We are here for you.
Last edit: Anobium 2014-01-19
instead I'm working with this FW and it works well.
Beware though, in some cases (see Constructed by board manufacturer) notification SDA/SCL must be converted to 5V(bus_master)-->3.3V(bus_slave)-->5V(bus_master) via a BS170/BS108/BSS138(SMD on each I2C line.
CHIP 16F877A,4
CONFIG OSC=XT,WDT_OFF,PWRTE_ON,CP_OFF,DEBUG_OFF,WRT_OFF,CPD_OFF,LVP_OFF,BODEN_ON
INCLUDE <I2C_Master.h>
INCLUDE <UART.h>
DEFINE HMC5883L_Address_Wr 0x3C
DEFINE HMC5883L_Address_Rd 0x3D
DEFINE HMC5883_CONFIG_REG_A 0x00
DEFINE HMC5883_CONFIG_REG_B 0x01
DEFINE HMC5883_MODE_REG 0x02
DEFINE HMC5883_DATA_OUT_X_MSB_REG 0x03
DEFINE HMC5883_DATA_OUT_X_LSB_REG 0x04
DEFINE HMC5883_DATA_OUT_Z_MSB_REG 0x05
DEFINE HMC5883_DATA_OUT_Z_LSB_REG 0x06
DEFINE HMC5883_DATA_OUT_Y_MSB_REG 0x07
DEFINE HMC5883_DATA_OUT_Y_LSB_REG 0x08
'DEFINE HMC5883_STATUS_REG 0x09
'DEFINE HMC5883_IDENT_REG_A 0x0A
'DEFINE HMC5883_IDENT_REG_B 0x0B
'DEFINE HMC5883_IDENT_REG_C 0x0C
DIM HMC5883LX,HMC5883LY,HMC5883LZ AS WORD
DIM Contador,Valor AS BYTE
SUB HMC5883L_Init()
START()
Tx_I2C(HMC5883L_Address_Wr)
Tx_I2C(HMC5843_CONFIG_REG_A)
Tx_I2C(0x74)
STOP()
WAIT 5 ms
START()
Tx_I2C(HMC5883L_Address_Wr)
Tx_I2C(HMC5843_CONFIG_REG_B)
Tx_I2C(0xA0)
STOP()
WAIT 5 ms
START()
Tx_I2C(HMC5883L_Address_Wr)
Tx_I2C(HMC5843_MODE_REG)
Tx_I2C(0x00)
STOP()
END SUB
SUB HMC5883L_Rd()
START()
Tx_I2C(HMC5883L_Address_Wr)
Tx_I2C(HMC5883_DATA_OUT_X_MSB_REG)
RESTART()
Tx_I2C(HMC5883L_Address_Rd)
HMC5883LX_H=Rx_I2C()
ACK_I2C()
HMC5883LX_L=Rx_I2C()
ACK_I2C()
HMC5883LY_H=Rx_I2C()
ACK_I2C()
HMC5883LY_L=Rx_I2C()
ACK_I2C()
HMC5883LZ_H=Rx_I2C()
ACK_I2C()
HMC5883LZ_L=Rx_I2C()
No_ACK_I2C()
STOP()
WAIT 5 ms
END SUB
Ciclo:
TRISA=b'000000'
TRISB=b'00000000'
TRISC=b'00011000'
TRISD=b'00000000'
TRISE=b'00000000'
PORTA=b'000000'
PORTB=b'00000000'
PORTC=b'00000000'
PORTD=b'00000000'
PORTE=b'00000000'
INTCON=b'00000000'
OPTION_REG=b'00000000'
CVRCON=b'00000000'
CCP1CON=b'00000000'
CCP2CON=b'00000000'
ADCON0=b'00000000'
ADCON1=b'10000110'
UART_Init(4000,1200,0)
I2C_Init(4000,100)
HMC5883L_Init()
WAIT 500 ms
DO
WAIT 100 ms
HMC5883L_Rd()
WAIT 100 ms
UART_TX_Print("X:")
UART_TX(HMC5883LX/256)
UART_TX(HMC5883LX%256)
UART_TX_Print("Y:")
UART_TX(HMC5883LY/256)
UART_TX(HMC5883LY%256)
UART_TX_Print("Z:")
UART_TX(HMC5883LZ/256)
UART_TX(HMC5883LZ%256)
UART_TX(13)
WAIT 100 ms
LOOP
rather I would like to know how to convert the values read and convert to degrees(the readings are in radians).
the formula should be:
Degrees=arctan(Y,X)*(180/3.1416)
exists in a gcbasic arctan?
Last edit: alejandro1957 2014-03-18
I am not aware of ATAN. There is code on the web for estimating ATAN, TAN etc.
Would be great if you can create some functions for us all.
BS170/BS108/BSS138(SMD)
Resistor recommended 2K2-->10K(datasheet)
The ATAN function in Gambas says that is the inverse of TAN.
TAN that uses only one value (X or Y).
hand at work, let's see what comes out with Google and mathematical functions.
Here some research on SIN. I was going to add SIN and TAN this summer.
http://www.societyofrobots.com/programming_trigtable.shtml
Last edit: Anobium 2014-03-18
And, http://www.societyofrobots.com/robotforum/index.php?topic=1308.0
Thank you for the link to Anobium, mainly this:
http://www.mathsisfun.com/polar-cartesian-coordinates.html
ok,I pulled out two lines of code very rough.
DIM Kangulo 0.018634466
FUNCTION Calculo_Angular(Eje_Y,Eje_X)
Tangente_Inversa=(Eje_Y/Eje_X)/Kangulo
Calculo_Angular=Tangente_Inversa
END FUNCTION
I know the stuff of cavemen.
but let me know if it works.
are currently in bed with a fever of 40° and my wife will not let me get up for any reason.
Anobium then, the code running in single mode reading is this:
CHIP 16F877A,4
CONFIG OSC=XT,WDT_OFF,PWRTE_ON,CP_OFF,DEBUG_OFF,WRT_OFF,CPD_OFF,LVP_OFF,BODEN_ON
INCLUDE <I2C_Master.h>
INCLUDE <UART.h>
DEFINE Baud_UART 51 '(Fosc(Hz)/64/Baudrate)-1
DIM EjeX,EjeY,EjeZ AS INTEGER
SUB HMC5883L_Init()
START()
Tx_I2C(0x3C)
Tx_I2C(0x00)
Tx_I2C(0x74)
STOP()
WAIT 5 ms
START()
Tx_I2C(0x3C)
Tx_I2C(0x01)
Tx_I2C(0xC0)
STOP()
END SUB
FUNCTION HMC5883L_Test() AS INTEGER
DIM Test AS INTEGER
START()
Tx_I2C(0x3C)
Tx_I2C(0x02)
RESTART()
Tx_I2C(0x3D)
Test=Rx_I2C()
STOP()
HMC5883L_Test=Test
WAIT 10 ms
END FUNCTION
SUB HMC5883L_Lectura()
DIM X_Tmp(2),Z_Tmp(2),Y_Tmp(2) AS INTEGER
START()
Tx_I2C(0x3C)
Tx_I2C(0x03)
RESTART()
Tx_I2C(0x3D)
X_Tmp(0)=Rx_I2C()
ACK_I2C()
X_Tmp(1)=Rx_I2C()
ACK_I2C()
Z_Tmp(0)=Rx_I2C()
ACK_I2C()
Z_Tmp(1)=Rx_I2C()
ACK_I2C()
Y_Tmp(0)=Rx_I2C()
ACK_I2C()
Y_Tmp(1)=Rx_I2C()
No_ACK_I2C()
STOP()
EjeX=(ROTATE X_Tmp(0) LEFT 8)|X_Tmp(1)
EjeY=(ROTATE Y_Tmp(0) LEFT 8)|Y_Tmp(1)
EjeZ=(ROTATE Z_Tmp(0) LEFT 8)|Z_Tmp(1)
END SUB
Ciclo:
TRISA=b'000000'
TRISB=b'00000000'
TRISC=b'00011000'
TRISD=b'00000000'
TRISE=b'00000000'
PORTA=b'000000'
PORTB=b'00000000'
PORTC=b'00000000'
PORTD=b'00000000'
PORTE=b'00000000'
INTCON=b'00000000'
OPTION_REG=b'00000000'
CVRCON=b'00000000'
CCP1CON=b'00000000'
CCP2CON=b'00000000'
ADCON1=b'00000110'
UART_Init()
I2C_Init(4000,100)
WAIT 1 s
IF HMC5883L_Test=3 THEN PULSEOUT PORTD.3,1 s
HMC5883L_Init()
WAIT 5 ms
DO
SET PORTD.0 ON
START()
Tx_I2C(0x3C)
Tx_I2C(0x02)
Tx_I2C(0x01)
STOP()
WAIT 5 ms
HMC5883L_Lectura()
WAIT 25 ms
UART_TX_Print("X:")
UART_TX(EjeX)
UART_TX(13)
WAIT 25 ms
UART_TX_Print("Y:")
UART_TX(EjeY)
UART_TX(13)
WAIT 25 ms
UART_TX_Print("Z:")
UART_TX(EjeZ)
UART_TX(13)
SET PORTD.0 OFF
WAIT 100 ms
LOOP
appears on the monitor:
X=N;Y=O
X=254
Y=252
Z=238
X=O;Y=S
X=191
Y=174
Z=254
X=S;Y=E
X=238
Y=239
Z=252
X=E;Y=N
X=174
Y=238
Z=253
.
.
DIM EjeX(2),EjeY(2),EjeZ(2) AS INTEGER
.
.
SUB HMC5883L_Lectura()
START()
Tx_I2C(0x3C)
Tx_I2C(0x03)
RESTART()
Tx_I2C(0x3D)
EjeX(0)=Rx_I2C()
ACK_I2C()
EjeX(1)=Rx_I2C()
ACK_I2C()
EjeZ(0)=Rx_I2C()
ACK_I2C()
EjeZ(1)=Rx_I2C()
ACK_I2C()
EjeY(0)=Rx_I2C()
ACK_I2C()
EjeY(1)=Rx_I2C()
No_ACK_I2C()
STOP()
END SUB
.
.
.
.
DO
SET PORTD.0 ON
START()
Tx_I2C(0x3C)
Tx_I2C(0x02)
Tx_I2C(0x01)
STOP()
WAIT 5 ms
HMC5883L_Lectura()
WAIT 25 ms
UART_TX_Print("X:")
UART_TX(EjeX(0))
UART_TX(EjeX(1))
UART_TX(13)
WAIT 25 ms
UART_TX_Print("Y:")
UART_TX(EjeY(0))
UART_TX(EjeY(1))
UART_TX(13)
WAIT 25 ms
UART_TX_Print("Z:")
UART_TX(EjeZ(0))
UART_TX(EjeZ(1))
UART_TX(13)
SET PORTD.0 OFF
WAIT 100 ms
LOOP
appears on the monitor:
X=N;Y=O
X=0 121
Y=255 248
Z=255 80
X=O;Y=S
X=0 58
Y=255 137
Z=255 80
X=S;Y=E
X=255 200
Y=255 210
Z=255 80
X=E;Y=N
X=0 9
Y=0 67
Z=255 82
Anobium,in each case the values are always positive, no negative sign.
thing that is not good.
the minus sign on one of these values indicates the Cartesian position.
the programe works and the pic with the HMC5883L converse well.
even with a program that self-test (datasheet shows how) it works and I have seen that the optimal value for the module is 0xC0 (0x01 0xC0 0x3C -> ± 5.6Ga).
what's wrong????
I do not know. But, willing to help.
I just reviewed the datasheet. How are the negative value returned in the bytes returned from the device?
Thanks Anobium.
I would like to know if someone in the forum has already worked with these gizmos.
Then,if this use to convert two 8-bit values in an word by 16-bit:
.........................................
DIM EjeX,EjeZ,EjeY AS WORD
DIM X_Tmp(2),Y_Tmp(2),Z_Tmp(2) AS INTEGER
.........................................
EjeX=(X_Tmp(0)256)+X_Tmp(1)
EjeZ=(Z_Tmp(0)256)+Z_Tmp(1)
EjeY=(Y_Tmp(0)*256)+Y_Tmp(1)
X:5211
Z:4928(1)
Y:5221
.........................................
EjeX=(WORD)+X_Tmp(1)
EjeZ=(WORD)+Z_Tmp(1)
EjeY=(WORD)+Y_Tmp(1)
X:5211
Z:4928(1)
Y:5221
.........................................
EjeX=(WORD)|X_Tmp(1)
EjeZ=(WORD)|Z_Tmp(1)
EjeY=(WORD)|Y_Tmp(1)
X:91
Z:64(1)
Y:101
.........................................
FUNCTION SHIFT(Numero AS INTEGER,Direccion AS STRING,Carry AS INTEGER) AS WORD
DIM Index AS INTEGER
FOR Index=1 TO Carry
ROTATE Numero Direccion SIMPLE
NEXT
SHIFT=Numero
END FUNCTION
EjeX=SHIFT(X_Tmp(0),"LEFT",8)|X_Tmp(1)
EjeZ=SHIFT(Z_Tmp(0),"LEFT",8)|Z_Tmp(1)
EjeY=SHIFT(Y_Tmp(0),"LEFT",8)|Y_Tmp(1)
X:91
Z:64(1)
Y:101
.........................................
EjeX=(X_Tmp(0)256)
EjeX+=X_Tmp(1)
EjeZ=(Z_Tmp(0)256)
EjeZ+=Z_Tmp(1)
EjeY=(Y_Tmp(0)*256)
EjeY+=Y_Tmp(1)
X:111
Z:65354(1)
Y:84
(1)This value is negative.
if the 15th bit of the word is equal to 1(0=positive,1=negative),are negative.
all values than 0x7FFF(mean value between Vmax=0xF800 and Vmin=0x7FF)have the 15th bit to 0 (0111111111111111),then positive.
otherwise,greater than 0x8000(0x7FFF+1) is 1(1000000000000000),then negative.
you could create a function that checks the 15 °, type:
FUNCTION Control_bit(Bit AS INTEGER) AS INTEGER
DIM Valor AS WORD
IF Bit.15=1 THEN
Valor=-Bit ''assign a negative value,as you can do?
Else
Valor=Bit
End If
Control_bit=Valor
END FUNCTION
the code does not look good
Last edit: alejandro1957 2014-04-24
I forgot, if I send the measured values without creating a 16-bit word, the values are these:
X_Tmp(0)=000
X_Tmp(1)=111
Z_Tmp(0)=255
Z_Tmp(1)=74
Y_Tmp(0)=000
Y_Tmp(1)=84
only the value of Z (0) moved to the left of 8 places is equal to 0xFF00(1111111100000000-16th bit to 1, so it is a negative value).
then,65354-65280(0xFF00) is equal to 74.that is -74(a negative value).
There are a few errors in the code.
EjeZ=(Z_Tmp(0)256) should be EjeZ=( Z_Tmp(0) * 256)
Is this cause of the issue?
Anobium sorry,but maybe you did not see the attached code?
when I saw you posted with the tag like this:
EjeZ=(Z_Tmp(0)256)
but it was already in the code like this:
EjeZ=(Z_Tmp(0)*256)
has the same value to move 8 places left.
Last edit: alejandro1957 2014-04-25
OK. Ooops.
Advice. Write code long hand. Do not try to have arrays handled and multiplied on the same line. We are trying to figure out a bug that may be related to this.
I this is a pain but try this method.
you have:
EjeX=SHIFT(X_Tmp(0),"LEFT",8)|X_Tmp(1)
change to:
tempvar1 = X_Tmp(0)
tempvar2 = X_Tmp(1)
tempvar1 = tempvar1 * 256
EjeX = tempvar1 | tempvar2
Then, we can use some debug to sort out the issue.
I hope I am helping with the right problem. its hard to understand the core issue.
Last edit: Anobium 2014-04-25
I understand, try the static variables in recursion.
I'll try and let you know.
ok,is starting to work:
EjeX=(X_Tmp(0)256)
EjeX+=X_Tmp(1)
EjeY=(Y_Tmp(0)256)
EjeY+=Y_Tmp(1)
EjeZ=(Z_Tmp(0)*256)
EjeZ+=Z_Tmp(1)
SUR
X 55
Y 65394
Z 65328
Grados=314°
ESTE
X 65457
Y 65499
Z 65332
Grados=250°
NORD
X 31
Y 95
Z 65334
Grados=91°
OESTE
X 141
Y 0
Z 65330
Grados=19°
as seen,the minimum is relieved angle 19°(instead of 0°)and the maximum is 317(instead of 360°).
with this code in Gambas2,i can read the data in rotation(starting from west)clockwise.
ranges from 19 ° to 317 ° degree at a time:
PUBLIC SUB RS232_Read()
DIM strInput AS String
TRY READ #RS232, strInput, 1
IF ERROR THEN
txaVentana.Text &= "--> Error de recepciòn" & "\n"
ELSE
IF Asc(strInput) <> 13 THEN
Frase &= strInput
ELSE
Analisar(Frase)
Frase = ""
ENDIF
ENDIF
END
PUBLIC SUB Analisar(Linea AS String)
DIM Angulo, Declinacion AS Float
DIM Puntador_X, Puntador_Y, Puntador_Z AS Integer
DIM NumeroX, NumeroY, NumeroZ AS Long
Declinacion = 0.3333
Puntador_X = InStr(Linea, "X")
Puntador_Y = InStr(Linea, "Y")
Puntador_Z = InStr(Linea, "Z")
NumeroX = CLong(Trim(Mid(Linea, Puntador_X + 1, (Puntador_Y - Puntador_X) - 1)))
NumeroY = CLong(Trim(Mid(Linea, Puntador_Y + 1, (Puntador_Z - Puntador_Y) - 1)))
NumeroZ = CLong(Trim(Mid(Linea, Puntador_Z + 1, Len(Linea) - Puntador_Z)))
txbX.Text = Signo(NumeroX)
txbY.Text = Signo(NumeroY)
txbZ.Text = Signo(NumeroZ)
Angulo = Ang(Signo(NumeroX), Signo(NumeroY))
Angulo = Angulo + Declinacion
IF Angulo < 0 THEN Angulo += (2 * Pi)
IF Angulo > (2 * Pi) THEN Angulo -= (2 * Pi)
Angulo *= 180 / Pi
txbGrados.Text = CInt(Angulo)
END
FUNCTION Signo(Word AS Long) AS Integer
DIM Valor AS Integer
IF Word <= 2047 THEN
Valor = Word
ELSE
Valor = - (Word - 65280)
ENDIF
RETURN Valor
END
is a bit rudimentary, but it will.
The decline is 0.3333(Naples, Italy)allows me to correct the drift with the geographic pole +- well.
error 0° to 360° i will try to correct it using values instead of Long to Float (which is an integer and maybe harm the calculation radians to Ang (X, Y)).
Last edit: alejandro1957 2014-05-23
it works fine.
it was enough to change the configuration for the module in this way and reads the position at the time a grade from 0° to 359°:
0x3C 0x00 0x70 (8 samples, 15Hz, reading normal mode)
0x3C 0x01 0x40 (+-1.9Ga)
do
0x3C 0x02 0x01 (single read, no read more)
WAIT 5 ms (not less than)
Read function
WAIT 25 ms (not less than)
Code of administration involving the user prefers
WAIT 67 ms (not less than)
loop
I'm trying to create a library for Atan and Atan2.
I will let you know.